Simple Commands in MapleV for DEs
> | restart: |
Functions
> | f:=x->4*x*(1-x); |
2D Plots
> | plot(f(x),x=0..1); |
> | plot({f(f(x)),x},x=0..1); |
Adding Text
Click on Insert, Paragraph, Above or Below
The Default number of digits used is 10, which can be reset.
> | Digits:=15: |
Iteration
In this case, you can use a simple loop structure. (1) Specify initial value. (2) Iterate using Loop:
for n from start to finish
do
statement 1:
statement 2: etc.
od:
> | x[0]:=0.1: for n from 1 to 100 do x[n]:=f(x[n-1]): od: |
Displaying Results
> | for n from 1 to 10 do print(x[n]): od: |
Some plotting routines need the plots library added. Use with(plots):
> | with(plots): pointplot([seq([n,x[n]],n=0..100)]); |
Warning, the name changecoords has been redefined
Finding Roots
Seeking fixed point of f(f(x))
Define f(x)
> | f:=x->2.1*x*(1-x): |
Fixed point equation
> | g:=x->f(f(x))-x: |
Compute roots of function g(x)
> | fsolve(g(x)); |
Clear internal memory
> | restart: |
Computing Derivatives
> | diff(sin(x),x); |
Second derivative.
> | diff(sin(x),x$2); |
Derivative of general function.
> | diff(y(x,y),x,y$2); |
Differential Equations
Store differential equation in a variable.
> | eq:=diff(y(x),x$2)+y(x)=0; |
Obtain general solution.
> | dsolve(eq); |
Solve initial value problem.
> | dsolve({eq, y(0)=3, D(y)(0)=0}, y(x)); |
Convert a result to a function
> | f:=unapply(rhs(dsolve({eq, y(0)=3, D(y)(0)=0}, y(x))),x); |
> | plot(f(x),x=0..10); |
Plotting Solutions to ODEs
A more direct way to plot solutions is to use dsolve with type=numeric combined with odeplot.
> | with(plots): |
Warning, the name changecoords has been redefined
> | p:= dsolve({D(y)(x) = y(x), y(0)=1}, y(x),type=numeric): |
> | odeplot(p,[x,y(x)],-1..1); |
Solving a systems of DEs
> | sys:={diff(x(t),t)=y(t),diff(y(t),t)=-9*x(t)}; |
> | dsolve(sys,{x(t),y(t)}); |
Plotting Direction Fields, Solutions and Phase Portraits
Load the DEtools package. For the most part you can use DEplot
> | with(DEtools): |
Plot of direction field for first order ODE
> | DEplot(diff(y(x),x)=x+y(x),y(x),x=-10..10,y=-10..10); |
Add a solution passing through a given initial condition.
> | DEplot(diff(y(x),x)=x+y(x),y(x),x=-10..10,y=-10..10,[[y(0)=0]],linecolor=black); |
Plot the phase portrait for a system of two first order ODEs with two orbits passing through the given intial conditions. Note the addition of a title and changing of colors.
> | DEplot(sys,[x(t),y(t)],t=0..2,x=-1..1,y=-2..2,[[x(1)=0,y(1)=2],[x(0)=0,y(0)=1]],color=black,linecolor=blue,title=`Phase Portrait`); |
Plotting only orbits.
> | DEplot(sys,[x(t),y(t)],t=0..2,x=-1..1,y=-2..2,[[x(1)=0,y(1)=2],[x(0)=0,y(0)=1]],title=`Phase Portrait with no arrows`, arrows=none); |
There are functions for doing only the direction field or only the solution: dfieldplot, phaseportrait.
> | dfieldplot([diff(x(t),t)=x(t)*(1-y(t)),diff(y(t),t)=.3*y(t)*(x(t)-1)], [x(t),y(t)],t=-2..2,x=-1..2,y=-1..2,arrows=thin,title=`Lotka-Volterra model`); |
> | phaseportrait(cos(x)*diff(y(x),x$3)-diff(y(x),x$2)+Pi*diff(y(x),x)=y(x)-x, y(x),x=-2.5..1.4,[[y(0)=1,D(y)(0)=2,(D@@2)(y)(0)=1]],y=-4..5); |
> | phaseportrait(sys,[x(t),y(t)],t=0..2,[[x(1)=0,y(1)=2],[x(0)=0,y(0)=1]],linecolor=black,thickness=0); |
> |
Maple
TM is a registered trademark of Waterloo Maple Inc.
Math rendered by
WebEQ