awass

301 Reputation

10 Badges

19 years, 114 days

MaplePrimes Activity


These are questions asked by awass

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?

Can anyone explain this?
> if  3 = 0 mod 3 then print(good) else print(bad) end if;
                        bad

> if  0 = 3 mod 3 then print(good) else print(bad) end if;
                       good
 

I have a procedure, se, that takes 2 real numbers as arguments and returns a list of 3 real numbers,
so, for example,
se(1.2,2.7)=[-5.85,3.24,3.9].
(The exact nature of that procedure should not be important for plotting purposes.) 

The command   >plot3d(se(x,y),x=0..2,y=-2..3);  returns a surface plot as hoped.   
(I had some doubt because the help page suggests one needs 3 functions or procedures [f,g,h] to get a 3 d plot rather than one procedure that generates a list of 3 values but Maple 2017.3 came through). 
I have another procedure , td,that takes 2 real numbers as arguments and returns a list of 3 real numbers,  ;
so, for example,
td(2.7, 3.4)=[3.4, .594943507924521, -.111391393034295].

(Again, the exact nature of that procedure should not be important for plotting purposes.) 
The command   > plot3d(td(x,t),x=0..2,t=0..3);  returns the error message: 

Error, (in dsolve/numeric/process_parameters) parameter values must evaluate to numeric, got a = x

For some reason, plot3d is going back to the body of the procedure, td, rather than just accepting the values it provides.

Knowing that quotes can sometimes solve this sort of problem I then tried:
plot3d('td(x, t)', x = 0 .. 2, t = 0 .. 3);
only to get

Warning, unable to evaluate the function to numeric values in the region; see the plotting command's help page to ensure the calling sequence is correct

I am not sure what plot3d is complaining about. The procedure I believe has all the information it needs in the form it needs it.
I then tried another workaround.

I set td1(x,t) :=td(x,t)[1], td2(x,t) :=td(x,t)[2], td3(x,t) :=td(x,t)[3] and tried :
plot3d([td1(x, t), td2(x, t), td3(x, t)], x = 0 .. 3, t = 0 .. 2);
to get
Error, (in dsolve/numeric/process_parameters) parameter values must evaluate to numeric, got a = x
Again, for some reason, plot3d is going back to the body of the procedure td.

Finally, I tried:
plot3d('[td1(x, t), td2(x, t), td3(x, t)]', x = 0 .. 3, t = 0 .. 2);
 
and I got the plot I wanted.

I am very happy to have a working file but I do not understand what worked and why. The nest time I have such a problem I will have to resort to the mysterious syntax manipulations again and hope that I hit on a combination that works.

For completeness I include the procedure bodies for  se and td below but I think that is irrelevant information.

se := proc (x, y) [x^2-y^2, x*y, x+y] end proc;


td := proc (x, tt)
local des, ff, fpfp; global ans;
ans(parameters = [a = x]);
des := ans(tt); ff := rhs(des[2]); fpfp := rhs(des[3]); [tt, ff, fpfp]
end proc;
 and
ans:=dsolve(ic,numeric,parameters=[a]):  where ic is an ode (I used several with the same result) with initial condition involving a.;

Can anybody explain what is happening?

 

I searched the questions for an answer before posting and found that I had asked the question 10 years ago! I still do not understand although it appears every other Maple user does. Embarrassing!
 

I have done some time consuming computations in my worksheet and would like to save the results for further investigation. Let's say, for example, that I have a long list L of numbers, strings etc, and a very large Matrix A . I am working on a Mac running 10.12.6.
From reading the documentation many times I gather that I can create a file with the values of L and A. I might then be able to open another worksheet and read the values of L and A into that worksheet but I cannot figure out how to do that.

Here are some of the (unhelpful) error messages I get using toy examples:

after creating a text file by hand

> read "testZ";
Error, unable to read `testZ` 

or

read testn. txt;
Error, read must have a file name

ro

read "Users/awass/Desktop/testn";
Error, unable to read `Users/awass/Desktop/testn`
 

So, how do I write my info to a file? Must I somehow create the file before I save?
Where should that file be placed? Desktop? Folder?
How do I read from the file after I have saved.
Can I save both L and A to the same file? Do I need 2 commands?

I would appreciate some explicit toy examples. Many thanks.
 

 

 

 



 

2 3 4 5 6 7 8 Page 4 of 10