awass

221 Reputation

4 Badges

13 years, 273 days

MaplePrimes Activity


These are questions asked by awass

I have a procedure that changes the value of an input variable quite unexpectdly. Can anyone explain why? I have a very simplified example of this below.

restart;
with(LinearAlgebra):
switch := proc (V::Vector)
description "This procedure is supposed to take a Vector V and switch entries 1 and 2";
local W,a,b;
W:= V;
a:= W[1];
b:= W[2];
W[1 ] := b;  
W[2] :=a;
W
end proc;

V1:=Vector([1,3,5]);
V2:=switch(V1);
I have omitted the output for brevity's sake but all works well as expected.
However,
V1;

returns V2 not V1. Why is the procedure changing V1?
 

The problem occurs with matrices but not with lists.

 

Thanks.

 

Here is a simple procedure that works fine if entered using 1D Maple input
> Q:=proc(x)
sin(x)
end proc;
but if you use 2D math input
> q:=proc(x)
sin(x);

  end proc;

Error, unterminated procedure
    Typesetting:-mambiguous(qAssignTypesetting:-mambiguous(

      procApplyFunction(x) sinApplyFunction(x),

      Typesetting:-merror("unterminated procedure")))
Error, unable to parse
    Typesetting:-mambiguous(  Typesetting:-mambiguous(end,

      Typesetting:-merror("unable to parse")) procsemi)

Ouch! But to confuse things further the following procedures may be entered using 2D math and work fine:
>H := proc (x) x^2*sin(x) end proc;
>K := proc (x) sin(x^2) end proc;
Doesn't make any sense to me. Perhaps 2D math is not ready for prime time?

 

From the help pages for the Gram Schmidt command:

The number of Vectors returned is the dimension of the vector space spanned by V.  In particular, if the Vectors in V are not linearly independent, fewer Vectors than the number in V are returned.


That is not what happens when floating point numbers are involved, for example:

>restart;
>with(LinearAlgebra);
>a := Vector([1, 2, 3]); b := Vector([1, -2, 3]); c := Vector([3, 2, 1]); d := Vector([5, 1, -3]); e := Vector([0, 1.01, -3]);
>GramSchmidt([a, b, c, d, e]);

This returns 3 vectors as it should BUT
>GramSchmidt([b, c, d, e, a]) returns 5 vectors (one of which is essentially 0).  That is definitely a bug.
 

Here is a simple little procedure that does not work

et :=proc(x) 

description   "this is a variant of evalf that gets rid of almost 0 nos.(rounding error) and shortens the display to 2 `digits"`;  

if  abs(x) < 10^((-14))  then 0 else  evalf(x,2) end if     end proc;


Error, unable to delimit strings/identifiers


and here is the same procedure that works because I added the # before the description.

et :=proc(x)

# description   "this is a variant of evalf that gets rid of almost 0 nos.(rounding error) and shortens the display to 2 `digits"`;  

if  abs(x) < 10^((-14))  then 0 else  evalf(x,2) end if     end proc;

 

In the help pages they do not say that the description must be hidden by the # sign (nor do they mention that quotes should be used although they are used in the examples.

 

What am I missing?

 

 

 

I was pleased to observe that in Maple 2018 one can use dsolve to get solutions of matrix ODEs, e.g., X'(t)=A(t) X(t). The command is the obvious dsolve({diff(X(t),t)=A(t).X(t), X(0)=Xo}).

I was then surprised that Maple balked at the commands dsolve({diff(X(t),t)=A(t).X(t), X(0)=Xo},numeric) and dsolve({diff(X(t),t)=A(t).X(t), X(0)=Xo},numeric,{x(t),y(t)}).  Is there some error on my part?

1 2 3 4 5 6 7 Page 1 of 7