Joe Riel

9530 Reputation

23 Badges

20 years, 28 days

MaplePrimes Activity


These are answers submitted by Joe Riel

You probably don't want to assign directly to elements of a list; that is limited to lists with less than 100 elements.  You could, instead, use subsops.  For example:

b := [[2, 3], 1, 2, 3, 4, 5]:

replace := proc(b)
local c;
    c := b[2..-1];
    c := ListTools:-MakeUnique(subsop(b[1,1]=b[1,2],c));
    subsop(b[1,1]=1+max(subsop(b[1,1]=b[1,2],c)), c);
end proc:

replace(b);
                                 [1, 6, 4, 5]

Do elements 2..-1 of the original list have any structure that you can take advantage of? For example, are they sorted?  Unique?

I only looked at your original post.  There are some syntax errors, specifically, using square brackets for the int. Also the call to Split only works on a pure integral, so you want to remove the 2/Pi factors (and use Int, the inert form of the integral). 

I see Robert Israel already mentioned those problems. 

You might use a Matrix. For example
 

y := x^2: 
f := unapply(y,x):
M := Matrix([seq([x,f(x)], x = 0..0.75, 0.01)]):

The description of the first problem is not specific.  Here are a few examples you might consider:

L0 := [];
L1 := [a];  # return a, or raise an error?
L2 := [1,a]: # does that return 1? Or raise an error?
L3 := [1,Pi]: # does that raise an error? Return Pi? Or return a numerical approximation of Pi (3.14159)?

You might want to pass these lists to Maple's max command to see what it does.

Note that one would normally not want to return 'ERROR'.  Rather, the more usual operation is to raise an error by calling the Maple error command, which generates an error message and halts the evaluation.

The 'clever' student might cheat and do the following

MY_MAX := proc(L)
local mx;
    mx := max(op(L)); # op isn't necessary for Maple 12+
    if not mx::'realcons' then
         error "could not compute maximum";
    end if;
    return mx;
end proc:

Try

koords := readdata("data_koordinate.txt", 3);

What sort of content are you attempting to import?  Could you give a small example?

Note that x=1..6 does not uniquely specify a portion of the curve. With that in mind, you could do

with(Student[VectorCalculus]):
curve := <y^2+y, y>:
sol1 := solve(curve[1]=1, y);
sol6 := solve(curve[1]=6, y);

plot([curve[1],curve[2], y=sol1[2]..sol6[1]]);

ArcLength( curve, y=sol1[2]..sol6[1] );

Here's one approach to finding a fixed point in psi

fixeq := 1/2*Int(x*y/(y+1)*f(y),y=0..1) + x^3/2 = f(x);
deq := diff(fixeq,x,x);
dsol := dsolve(deq);
F := unapply(rhs(dsol),x);
eq := value(eval(fixeq, f=F));
cfs := coeffs((lhs-rhs)(eq),x);
csol := solve({cfs},{_C1,_C2});
eval(F(x), csol);

 

You are better off using Maple's autocompile option, which generates compiled code.  To use it most effectively, pass in an Array and compute, in a loop, all values from 1 to 300.  Then select the range you are interested in.  For example:

computeS := proc(a::float, n::posint, S::Array(datatype=float[8]))
option autocompile;
local i;
    S[1] := 0.3;
    for i to n-1 do
        S[i+1] := a*S[i]*(1-S[i]);
    end do;
end proc:

t := time():
N := 300:
for i from 800 to 1280 do
    S := Array(1..N, 'datatype=float[8]');
    computeS(evalf(i/320), N, S);
    L[i] := S[200..300];
end do:
time()-t;
                               0.328

You never assigned the Determinant. Currently your code depends on a previous incantanation of with(LinearAlgebra).  Better to do this with a uses statement inside the procedure assignment.  For example

AffineMatEncode := proc(...)
uses LA = LinearAlgebra;
 ...
   Inv := LA:-MatrixInverse(A);
   D := modp(LA:-Determinant(A),p);
...
end proc:

Also, you should not be using evalm, that is for the old linalg package.  You are better off not allowing A and B to be matrix or vectors, but restrict them to Matrix and Vector. This procedure can be improved; look at the LinearAlgebra[Modular] subpackage.

 

 

 

It always a good idea to indent the code, then it would be immediately clear that you are doing a double loop.  Clearly the total time should generally be at least 100=10x10 times greater than a single execution of Powell().  There isn't much else to say without knowing what Powell does...

Should that be S2 := S2+0.2?  The first four conditionals are missing a conjunction (and).

Hmm. Try this http://www.mapleprimes.com/viewfile/3329  If that doesn't work, send me your email address and I'll email it to you directly.

I've uploaded a corrected version, however, I had some trouble pasting a link to it. Look in the recent files section in the right column, it's called 10494_MethodsFixed.mw

You can use simplify with side relations; the output is an expression not an equation:

simplify(b/m, [eq], [b,m]);
                                       g
                                      ---
                                      v_t

See ?simplify,siderels for details
First 83 84 85 86 87 88 89 Last Page 85 of 114