awass

296 Reputation

10 Badges

18 years, 161 days

MaplePrimes Activity


These are questions asked by awass

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.
 

 

 

 



 

I am trying to understand the use of "events" in solving ode's, specifically the possible actions.
From the help pages:

Events are specified by the events=[event1,event2,...] option in the call to dsolve[numeric], where each event is a list of [trigger,action] pairs, where the trigger describes the trigger of the event, and the action describes the action to perform when the event is triggered.

It then goes on to list possible actions, for example,

u(t) = -u(t): execute statement when triggered
– [u(t) = -u(t), y(t) = -y(t)]: execute statements when triggered
[If(y(t) < 0, y(t) = -y(t), halt)]: execute statements conditionally when triggered

I tried to use the first one unsuccessfully several ways:
This works:dsolve({eq, y(0) = 1, (D(y))(0) = -1}, numeric, events = [[x+y(x) = 15, halt]])

but dsolve({eq, y(0) = 1, (D(y))(0) = -1}, numeric, events = [[y(x) = 0,[ 'print("Yes'")', halt]]]) does not

nor does any variant of that using print.

Also, I cannot get at the result of any assingment, e.g.,

dsolve({eq, y(0) = 1, (D(y))(0) = -1}, numeric, events = [[y(x) = 0, [z = diff(y(x), x), halt]]]) does not work either; z does not have a value. What commands can be executed as actions after an event is triggered?

 

 

 

 

2 3 4 5 6 7 8 Page 4 of 9