How can I plot differential equations in Maple?
You can use the 'type=numeric' option with the 'dsolve' routine to generate a numerical approximation to the solution of a system of ordinary differential equations. This is often described in Maple literature as `dsolve/numeric`, which is the name of the actual Maple routine that implements the numerical option.
How to plot the results of 'dsolve/numeric' is not immediately obvious. When you use 'dsolve' in this way, what it returns is a procedure that you can later use to numerically estimate the solution at arbitrary points. The results returned by this procedure are not in a format that is immediately recognized by the 'plot' routine. There are three solutions to this problem:
- Use the 'odeplot' routine, for example:
> with(plots): > p:= dsolve({D(y)(x) = y(x), y(0)=1}, y(x),type=numeric): > odeplot(p,[x,y(x)],-1..1 );
- Convert the output of the numerical procedure into something that 'plot' can accept. This is handy if you want to use some of the plotting options that are not currently available in 'odeplot'. Continuing with the example from above, if you try evaluating p at the location x=1, here is what you get:
> p(1); [ x=1, y(x)=2.718281800377609 ]
We need to isolate the right-hand side of the second item in that list and give it to 'plot':
> plot( x -> op(2,op(2,p(x))), -1..1 );
For Maple programmers looking for a really bullet-proof way for handling lexical scoping of the name 'p', here is how you do it:
> eval(subs('P'=p,'plot'( x -> op(2,op(2,P(x))), -1..1 )));
- The 'DEtools' package contains several functions including 'DEplot' which you can try wityh the system above:
> with(DEtools): > DEplot(D(y)(x)=y(x),y(x),x=-1..1,{[y(0)=1]});
For more information, see online help on the topics: dsolve, solve[numeric], odeplot, plot, plot[options], DEtools, DEplot