Joe Riel

9665 Reputation

23 Badges

20 years, 35 days

MaplePrimes Activity


These are answers submitted by Joe Riel

So how'd you do it? Here's one approach. See Cartesian Product of Lists for a comparison of ways to compute the cartesian product of lists. The following CartProdSeq was taken from there.
CartProdSeq := proc(L::seq(list))
local Seq,i,j;
option `Copyright (C) 2007, Joseph Riel. All rights reserved.`;
    eval([subs(Seq=seq, foldl(Seq
                              , [cat(i,1..nargs)]
                              , seq(cat(i,j)=L[j],j=nargs..1,-1)
                             ))]);
end proc:
P := combinat[permute]([0,0,1,1]):
map(Matrix,CartProdSeq(P,P));
 [0    0    1    1]  [0    0    1    1]        [1    1    0    0] 
[[                ], [                ], ...,  [                ]]
 [0    0    1    1]  [0    1    0    1]        [1    1    0    0] 
Use combinat[permute] to generate a list of the permuations. To convert these to Vectors you could use map:
combinat[permute]([0,0,1,1]);
      [[0, 0, 1, 1], [0, 1, 0, 1], [0, 1, 1, 0], [1, 0, 0, 1], [1, 0, 1, 0], [1, 1, 0, 0]]
map(Vector, %);
                         [0]  [0]  [0]  [1]  [1]  [1]
                         [ ]  [ ]  [ ]  [ ]  [ ]  [ ]
                         [0]  [1]  [1]  [0]  [0]  [1]
                        [[ ], [ ], [ ], [ ], [ ], [ ]]
                         [1]  [0]  [1]  [0]  [1]  [0]
                         [ ]  [ ]  [ ]  [ ]  [ ]  [ ]
                         [1]  [1]  [0]  [1]  [0]  [0]
That add is faster is to be expected; sum usually calls add to do a discrete summation, certainly it will in this case because it won't find a symbolic expression. The following demonstrates this;
tprime := proc (s) if isprime(s) then s else 0 end if end proc:
debug(add):
sum('tprime'(k),k=1..1000);
execute add, args = eval(tprime(k),j = k), k = a .. b
                                     76127
You typed rctlnn as rcltnn in the procedure. Another way to refer to a procedure is to use 'procname'. Here is a rewrite of your code:
rctlnn := proc(n::nonnegint)
local j;
option remember;
uses combinat;
    if n = 0 then
        0
    else
        bell(n) + add(stirling2(n,j)*procname(j), j=2..n-1)
    end if;
end proc:

rctlnn(4);
                       95
It's frequently better to use add for this application. Because add has special evaluation rules, it doesn't evaluate its first argument before substituting the value of the dummy variable, so quotes are not needed:
add(tprime(n), n=1..12); 
                                     28
Possibly you want to do the following:
uv2xy := {u=2*x-3*y, v=-x+y}:
eqs_xy := [x=0, x=-3, y=x, y=x+1];
# solve for transformation equations
xy2uv := solve(uv2xy, {x,y}):
# transform equations
eqs_uv := eval(eqs_xy, xy2uv);
# collect u and v
map(eq -> collect((lhs-rhs)(eq), [u,v])=0, eqs_uv);
              [-u - 3 v = 0, -u - 3 v + 3 = 0, v = 0, v - 1 = 0]
The problem is that T cannot handle symbolic arguments. There are a few ways to work around this. One is to modify the assignment of T so that it does not generate an error if one or more of its arguments are symbolic. For example:
T := proc(w,r)
   if not (w::numeric and r::numeric) then return 'T'(w,r) end if;
   (w, r) -> rhs(Maximize(Profit(T, L, w, r), assume = nonnegative)[2][1]);
end proc:
This returns an unevaluated call to T if T is called with nonnumeric arguments. A simpler approach, which avoids modifying T, is to create a one parameter function and pass it to plot:
plot( r -> T(0.5,r), 0.3 .. 0.4);
Note that the second argument to plot is a "naked" range, there is no dummy parameter (i.e., r = 0.3..0.5). This can also be achieved by using the curry procedure:
plot(curry(T,0.5), 0.3 .. 0.4)
See its help page for details. One final method is to prevent premature evaluation of the expression T(0.5,r). That can be done by surrounding it with forward quotes:
plot('T(0.5,r)', r=0.3..0.5)
Note that there is not a unique solution. For example, -diff(f(x-y,z-y),x) - diff(f(x-y,z-y),z) is also a solution.
The error is in your assignment to Δy, it should be
Δy = n -> s*(sin(t[n])-y[n])*Δt/Λ(t[n],x[n],y[n])
You used x[n]
Here are a few suggestions. First, assign N directly and then use it to compute dt. Second, use the evalf to force Maple to convert 2*Pi/N to a floating point. Change vector to Vector. The function assignment should be
Lambda := (t,x,y) -> sqrt((cos(t)-x)^2+(sin(t)-y)^2);
With those changes everything seemed to work.
One way is to use the save and read commands:
y := x^2:
save y, "somefile.mpl":
restart;
read "somefile.mpl":
y;
              x^2
Use fsolve. For example,
deq := diff(y(t),t)=-y(t):
dsol1 := dsolve({deq, y(0)=1}, numeric, output=listprocedure):
dsol2 := dsolve({deq, y(0)=2}, numeric, output=listprocedure):
delta := eval(y(t), dsol2) - eval(y(t), dsol1): # I swapped order so delta is positive
fsolve(delta=0.5);
                  0.6931469270
delta(%); # check result
                   0.5000000000
Note that you can pass an interval to fsolve to restrict its search to a specified real interval. See ?fsolve,details.
Here's one approach:
deq := diff(y(t),t)=-y(t):
dsol1 := dsolve({deq, y(0)=1}, numeric, output=listprocedure):
dsol2 := dsolve({deq, y(0)=2}, numeric, output=listprocedure):
delta := eval(y(t), dsol1) - eval(y(t), dsol2):
plot(delta, 0..10);
First, traperror is obsolete, the proper way to catch errors is with try/catch. A simple way to "trap" warnings is to replace the WARNINGS procedure. Here is code I use to capture all warnings when evaluating a particular expression. The try statement is necessary to handle errors that occur in the evaluation (this is used during testing).
GetWarning := proc(expr::uneval)
global WARNING;
local warnings,oldWARNING,cnt,i;
description "Capture arguments passed to calls to WARNING."
    ,"Return a list of lists, each sublist corresponds to the arguments "
    "to one call to WARNING.";
    unprotect(WARNING);
    oldWARNING := eval(WARNING);
    cnt := 0;
    warnings := table();
    try
        WARNING := proc()
            cnt := cnt+1;
            warnings[cnt] := [args];
            NULL;
        end proc;
        eval(expr);
    finally
        WARNING := eval(oldWARNING);
        protect('WARNING');
    end try;
    [seq(warnings[i], i=1..cnt)];
end proc:

f := proc()
    WARNING("danger!");
    WARNING("alert!");
end proc:

GetWarning(f());
               [["danger!"], ["alert!"]]
What does the parenthetical phrase, "(xmaple -classic)," mean? Do you launch it from a shell prompt with that command? On my debian box, that launches the standard interface, not the classic (the -classic option does nothing). To start the classic interface I do
maple -cw
First 103 104 105 106 107 108 109 Last Page 105 of 114