Search code examples
elementsequencemaple

Maple - Sequence element affectation


I am encountering a problem when manipulating sequence element in Maple. First of all, here is the code.

b[0] := t -> (1-t)^3;
b[1] := t -> 3*t*(1-t)^2;
b[2] := t -> 3*t^2*(1-t);
b[3] := t -> t^3;
P := seq([seq([j*(i+1), j*(i-1)], i = 1 .. 4)], j = 1 .. 3);
EvalGamma := proc (b, P, i, t)
  local CP, res;
  option trace;
  CP := P[i];
  res := CP[1]*b[0](t)+CP[2]*b[1](t)+CP[3]*b[2](t)+CP[4]*b[3](t);
  RETURN res;
end proc;

The variable P is a sequence of sequence : P[i] is a sequence of four 2D points. But the affectation CP := P[i]; doesn't do what I want : I don't know why but the result is not P[i] in the procedure.

And the weird thing is that, outside the procedure, the following lines work :

CP := P[1];
CP[1];

I would appreciate any suggestions. Thanks.


Solution

  • I'm assuming you call the procedure as

    EvalGamma(b,P,i,t)
    

    The problem you are having is that when P is inserted into the sequence of arguments, the nested sequence of arguments is "flattened" to produce the final argument list. An easy way to fix this is to place the sequence for P inside a list structure. So use

    P := [seq([seq([j*(i+1), j*(i-1)], i = 1 .. 4)], j = 1 .. 3)];
    

    Once you do that, I think everything will work as expected.