Joe Riel

9530 Reputation

23 Badges

20 years, 28 days

MaplePrimes Activity


These are answers submitted by Joe Riel

This means that the discrete equations in the model have a cyclic dependency (x->y->z->x) that prevents them from being properly ordered. One way to break such a loop is with a "pre" block (in the Signal/Discrete palette).  You might post the model or contact Maple support for further assistance.

It's wrong because the correct answer, for k an integer, is piecewise(k=0, 2*Pi, 0).

You could use ?gfun[rectoproc] to convert the recursion to a procedure, then apply that to a sequence.  For example,

(**) with(gfun):               
(**) L := [1,4,9,16,25]:                    
(**) rec := listtorec(L, f(n));             
   rec := [{(-n - 3) f(n + 3) + 4 f(n + 2) + (n + 3) f(n + 1), f(0) = 1, f(1) = 4, f(2) = 9}, ogf]

(**) F := rectoproc(rec[1],f(n),'remember');
         F := proc(n) option remember; -(-n*procname(-2 + n) - 4*procname(-1 + n))/n end proc

(**) seq(F(i), i=1..10);                    
                                4, 9, 16, 25, 36, 49, 64, 81, 100, 121

Faster is

subs([seq(t=NULL, t in t)],X);
c := [1,2]:
c := [c[], 3]:

Now add x in position i

c := [op(..i-1, c), x, op(i.., c)];

Alternatively, you could do

c := subsop(i = (x,c[i]), c);

What do you want to do with, say,

A := [2,2,2]:
B := [2]:

Do you want the empty list, or one with two 2's?  Or is this not a concern?

It would help if you indicated how you call the procedure, that is, what arguments you used.

When ?assuming is used, the "assumee" (the operand to the left of the keyword assuming) is not evaluated until all assumptions have been applied. That is achieved by using the parameter modifier uneval (see ?parameter_modifiers).  To see that, do

 > print(`assuming`);
                                                        proc(x::uneval, a)  ...  end proc

The x parameter, which has the uneval modifier, is the "assumee".  When the assumption n :: negative (or n :: negint) is used, Maple correctly picks the proper branch of the piecewise and so GAMMA is never evaluated with x=-1.

The usual way to delay evaluation of a Maple expression is to surround it in single forward quotes (see ?').

Do not use ?with inside a procedure.  It doesn't work.  Instead uses ?uses.  That is,

stableMatching := proc(...)
local ... ;
uses ArrayTools;
    ...
end proc:

 

The error occurs with the call test(-1,n).  Because n is symbolic, the piecewise cannot be evaluated, so it computes piecewise(0<n, 1/GAMMA(-1), n<=0, sin(-Pi)).  The evaluation of GAMMA(-1) raises the divide-by-zero error.  One way to avoid this is to prevent the evaluation of the piecewise unless n is numeric.  That can be achieved with

test := proc(x,n) 
    if n :: numeric then
         piecewise(...);
    else
         'procname'(args);
    end if;
end proc:

This isn't ideal; if n is numeric then there is little point in using a piecewise.  That is, you might as well use a conditional.  A somewhat crude way to workaround that is to use a try/catch.

test := proc(x,n)
    try
        piecewise(...);
    catch:
        'procname'(args);
   end try;
end proc:

Not really.  The usual way to do this is with the `if` function: `if`(something, 1, 0).  If the condition is evaluable in evalhf, you can use it:

evalhf(3 < Pi);
                          1.

Note that the output is a float and not an integer.

Use ?add instead of ?sum.  The procedure sum is intended for symbolic summations, that is, when the limits are undefined.  The reason that sum fails is that the summand is evaluated before the summing begins.  That means the inner sum is evaluated before j is assigned a value.  That doesn't happen with add, which uses special evaluation rules.

The problem with assigning is that that effectively removes the symbolic variable from further use.  I generally prefer to assign the entire output of fsolve to a variable, and then use ?eval to get the value of a portion of it.  For example,

fsol := fsolve(...):
a5 := eval(a[5], fsol);

The difficulty is keeping R1/r0 together.  The simplest way may be to substitute for it; here I use the empty function, ``(), to group the product.

(**) y := R1^2/r0^2-2*R1/r0+1;
                                     2
                                   R1    2 R1
                              y := --- - ---- + 1
                                     2    r0
                                   r0

(**) subs(R1=``(R1/r0)*r0, y);
                              R1  2        R1
                            (----)  - 2  (----) + 1
                              r0           r0

(**) factor(%);
                                /   R1      \2
                                | (----) - 1|
                                \   r0      /

The command expand will expand the empty function (``(...)), which returns the original:

(**) expand(%);
                                  2
                                R1    2 R1
                                --- - ---- + 1
                                  2    r0
                                r0

Your latest error, "illegal use of a formal parameter" is usually caused (and is here) by attempting to assign to a formal parameter of a procedure. In this case, the statement p := g(p) is a attempting to assign to p, which is a formal parameter of fixe.  That is not allowed here.  One way to avoid it is to first assign the argument p (i.e., the value of the formal parameter) to a local variable, and then use that local variable inside the procedure.  That is, do

fixe := proc(p, g)
local pp;
pp := p;
...
pp := g(pp);
...
end proc
First 60 61 62 63 64 65 66 Last Page 62 of 114