plot solutions to a system of DEs - Maple Help

Home : Support : Online Help : Graphics : Packages : DEtools : DEtools/DEplot

DEtools[DEplot] - plot solutions to a system of DEs

 Calling Sequence DEplot(deqns, vars, trange, options) DEplot(deqns, vars, trange, inits, options) DEplot(deqns, vars, trange, xrange, yrange, options) DEplot(deqns, vars, trange, inits, xrange, yrange, options) DEplot(dproc, vars, trange, number, xrange, yrange, options)

Parameters

 deqns - list or set of first order ordinary differential equations, or a single differential equation of any order dproc - a Maple procedure representation for first order ordinary differential equations, or a single differential equation of any order vars - dependent variable, or list or set of dependent variables trange - range of the independent variable number - equation of the form 'number'=integer indicating the number of differential equations when deqns is given as a function (dproc) instead of expressions inits - set or list of lists; initial conditions for solution curves xrange - range of the first dependent variable yrange - range of the second dependent variable options - (optional) equations of the form keyword=value

Description

 • Given a set or list of initial conditions (see below), and a system of first order differential equations or a single higher order differential equation, DEplot plots solution curves, by numerical methods.
 Note: This means that the initial conditions of the problem must be given in standard form, that is, the function values and all derivatives up to one less than the differential order of the differential equation at the same point.
 • A system of two first order differential equations produces a direction field plot, provided the system is determined to be autonomous. In addition, a single first order differential equation produces a direction field (as it can always be mapped to a system of two first order autonomous differential equations). A system is determined to be autonomous when all terms and factors, other than the differential, are free of the independent variable. For more information, see DEtools[autonomous]. For systems not meeting these criteria, no direction field is produced (only solution curves are possible in such instances). There can be only one independent variable.
 • The default method of integration is method=rkf45. Other methods can be specified in the optional equations. Note that because numerical methods are used to generate plots, the output is subject to the characteristics of the numerical method in use. In particular, unusual output may occur when dealing with asymptotes.
 • The direction field presented consists of either a grid of arrows or a set of randomly generated arrows. In either case, the arrows are tangential to solution curves. For each grid point, the arrow centered at $\left(x,y\right)$ has slope $\frac{\mathrm{dy}}{\mathrm{dx}}$. This slope is computed using $\left(\frac{\mathrm{dy}}{\mathrm{dt}}\right)$/$\left(\frac{\mathrm{dx}}{\mathrm{dt}}\right)$, where these two derivatives are specified in the first argument to DEplot. The curved arrow types (curves and comet) require additional data for the curvature of the direction field, which is computed by moving an epsilon in the direction of the slope $\frac{\mathrm{dy}}{\mathrm{dx}}$, and computing $\frac{\mathrm{dy}}{\mathrm{dx}}$, then moving an epsilon in the direction opposite the slope, and computing $\frac{\mathrm{dy}}{\mathrm{dx}}$. This data is then sufficient to draw a small portion of the direction field lines local to the point, which is then used to draw the curved arrows.
 • By default, the two dependent variables are plotted, unless otherwise specified in the scene option.
 • The deqns parameter can be given as a procedure, but must conform to the specification as given in dsolve/numeric, and the number option must be included before the initial conditions. In this instance, deqns must be of the form:

 proc( N, ivar, Y, YP ) ... YP[1] := f1(ivar,Y); YP[2] := f2(ivar,Y); ... end proc

 where N represents the number of first order equations, ivar is the independent variable, Y is a vector of length N, and YP is a vector of derivatives which is updated by the procedure (for the equivalent first order system), also of length N. For information on determining first order systems, see DEtools[convertsys]. N is given in this case by the fourth parameter number.
 • The inits parameter must be specified as:

$\left[\left[x\left({t}_{0}\right)={x}_{0},y\left({t}_{0}\right)={y}_{0}\right],\left[x\left({t}_{1}\right)={x}_{1},y\left({t}_{1}\right)={y}_{1}\right],\mathrm{...}\right]$

$\left[\left[y\left({t}_{0}\right)={y}_{0}\right],\left[y\left({t}_{1}\right)={y}_{1}\right],\mathrm{...}\right]$

$\left[y\left({t}_{0}\right)={y}_{0},y\left({t}_{1}\right)={y}_{1},\mathrm{...}\right]$

 where, in the above, sets can be used in place of lists, or

$\left[\left[{t}_{0},{x}_{0},{y}_{0}\right],\left[{t}_{1},{x}_{1},{y}_{1}\right],\mathrm{...}\right]$

$\left\{\left[{t}_{0},{x}_{0},{y}_{0}\right],\left[{t}_{1},{x}_{1},{y}_{1}\right],\mathrm{...}\right\}$

$\left[\left[{t}_{0},{x}_{0}\right],\left[{t}_{1},{x}_{1}\right],\mathrm{...}\right]$

 where the above is a list or set of lists, each sublist specifying one group of initial conditions.
 • The xrange and yrange parameters must be specified as follows.

 $x\left(t\right)={x}_{1}..{x}_{2}$, $y\left(t\right)={y}_{1}..{y}_{2}$ or $x={x}_{1}..{x}_{2}$,    $y={y}_{1}..{y}_{2}$

 By default, integration along a solution curve stops one mesh point after the specified range is exceeded. This may be overridden by the obsrange option.
 • More examples can be found in the deplot example worksheet.
 • DEplot can also be accessed through the interactive DEplot assistant. For more information, see DEplot[interactive].

Examples

This first example is for a first order equation. It is for Newton's law of cooling.  The differential equation is

 > $\mathrm{with}\left(\mathrm{DEtools}\right):$
 > $\mathrm{NLC}:=\frac{ⅆ}{ⅆt}y\left(t\right)=k\left(\mathrm{Am}-y\left(t\right)\right);$$\mathrm{Am}:=20;$$k:=0.1$

where $y$ is the temperature at time $t$ and we have set the Ambient temperature $\mathrm{Am}$ to 20 degrees and the cooling rate constant $k$ to 0.1. We plot the solution for initial temperatures 10, 30, and 50 degrees. In the second plot we change the ranges for time $t$ and temperature $y$.

 > $\mathrm{ivs}:=\left[y\left(0\right)=10,y\left(0\right)=30,y\left(0\right)=50\right]$
 > $\mathrm{DEplot}\left(\mathrm{NLC},y\left(t\right),t=0..20,\mathrm{ivs}\right)$
 > $\mathrm{DEplot}\left(\mathrm{NLC},y\left(t\right),t=0..40,y=0..60,\mathrm{ivs},\mathrm{arrows}=\mathrm{medium},\mathrm{linecolor}=\mathrm{black}\right)$

The second example is a first order system in $x\left(t\right)$ and $y\left(t\right)$. It is the SIR virus model where $x$ is the susceptible population and $y$ is the infected population.  The differential equations are:

 > $\mathrm{deS}:=\frac{ⅆ}{ⅆt}x\left(t\right)=-0.5x\left(t\right)y\left(t\right)$
 > $\mathrm{deI}:=\frac{ⅆ}{ⅆt}y\left(t\right)=0.5x\left(t\right)y\left(t\right)-0.15y\left(t\right)$

The first plot shows one initial value $x\left(0\right)=0.98$ and $y\left(0\right)=0.01$ meaning 1% of the population is infected at time $t=0$.

 > $\mathrm{DEplot}\left(\left[\mathrm{deS},\mathrm{deI}\right],\left[x\left(t\right),y\left(t\right)\right],t=0..40,x=0..1,y=0..0.6,\left[\left[x\left(0\right)=0.99,y\left(0\right)=0.01\right]\right],\mathrm{arrows}=\mathrm{medium}\right)$

This second plot animates the solution curve in time. To run the animation, click on the plot then press the play button.

 > $\mathrm{DEplot}\left(\left[\mathrm{deS},\mathrm{deI}\right],\left[x\left(t\right),y\left(t\right)\right],t=0..40,x=0..1,y=0..0.6,\left[\left[x\left(0\right)=0.99,y\left(0\right)=0.01\right]\right],\mathrm{arrows}=\mathrm{medium},\mathrm{animatecurves}=\mathrm{true}\right)$

This third example is a second order differential equation. It is a damped harmonic oscillator $mx\text{'}\text{'}=-cx\text{'}-kx$ where $x$ is the position of the object at time $t$, $m=2$ is its mass, $k=2$ is the spring constant and $c=1$ is the damping constant.

 > $\mathrm{de}:=\frac{{ⅆ}^{2}}{ⅆ{t}^{2}}x\left(t\right)=-x\left(t\right)-\frac{1\left(\frac{ⅆ}{ⅆt}x\left(t\right)\right)}{2}$
 > $\mathrm{DEplot}\left(\mathrm{de},x\left(t\right),t=0..15,x=-1..1,\left[\left[x\left(0\right)=1,\mathrm{D}\left(x\right)\left(0\right)=0\right]\right]\right)$

The fourth example shows the same damped Harmonic oscillator above but input as a system of two first order equations.  Here $y\left(t\right)=x\text{'}\left(t\right)$ is the velocity.  By default the plot is a plot of $y$ verses $x$. In the second plot, we use the scene option to obtain a plot of $x$ verses $t$. In the third plot, we show some options for improving the quality of the solution curve.

 > $\mathrm{sys}:=\left\{\frac{ⅆ}{ⅆt}x\left(t\right)=y\left(t\right),\frac{ⅆ}{ⅆt}y\left(t\right)=-x\left(t\right)-\frac{1y\left(t\right)}{2}\right\}$
 > $\mathrm{DEplot}\left(\mathrm{sys},\left[x\left(t\right),y\left(t\right)\right],t=0..15,\left[\left[x\left(0\right)=1,y\left(0\right)=0\right]\right]\right)$
 > $\mathrm{DEplot}\left(\mathrm{sys},\left[x\left(t\right),y\left(t\right)\right],t=0..15,\left[\left[x\left(0\right)=1,y\left(0\right)=0\right]\right],\mathrm{scene}=\left[t,x\left(t\right)\right]\right)$
 > $\mathrm{DEplot}\left(\mathrm{sys},\left[x\left(t\right),y\left(t\right)\right],t=0..15,\left[\left[x\left(0\right)=1,y\left(0\right)=0\right]\right],x=-1..1,y=-1..1,\mathrm{numpoints}=200,\mathrm{linecolor}=\mathrm{black},\mathrm{axes}=\mathrm{boxed}\right)$

Here is the same plot as above, but using the procedure input form.

 > F1 := proc(N,x,Y,YP)                  # First order system     YP[1] := Y[2];     YP[2] := -Y[1]-1/2*Y[2]; end proc;
 > $\mathrm{DEplot}\left(\mathrm{F1},\left[x\left(t\right),y\left(t\right)\right],t=0..15,\mathrm{number}=2,\left[\left[y\left(0\right)=1,y\left(0\right)=0\right]\right],x=-1..1,y=-1..1,\mathrm{numpoints}=200,\mathrm{linecolor}=\mathrm{black},\mathrm{axes}=\mathrm{boxed}\right)$

The fifth set of examples are plots of the Lotka-Volterra predator-prey system. Here $x$ is the prey population and $y$ is the predator population. The first plot shows a plot of the direction field where color is used to indicate the velocity. The second plot shows the direction field with 300 randomly placed "comets." In the third plot we animate the direction field and in the fourth plot we animate the solution curves. Note, the second animation may take a minute or two to compute.

 > $\mathrm{LVS}:=\left[\frac{ⅆ}{ⅆt}x\left(t\right)=x\left(t\right)\left(1-y\left(t\right)\right),\frac{ⅆ}{ⅆt}y\left(t\right)=0.3y\left(t\right)\left(x\left(t\right)-1\right)\right]$
 > $\mathrm{DEplot}\left(\mathrm{LVS},\left[x\left(t\right),y\left(t\right)\right],t=0..10,x=-1..2,y=-1..2,\mathrm{arrows}=\mathrm{large},\mathrm{title}=\mathrm{Lotka-Volterra model},\mathrm{color}=\mathrm{magnitude}\right)$
 > $\mathrm{DEplot}\left(\mathrm{LVS},\left[x\left(t\right),y\left(t\right)\right],t=0..10,x=0..3,y=0..2,\mathrm{arrows}=\mathrm{comet},\left[\left[x\left(0\right)=1,y\left(0\right)=0.5\right]\right],\mathrm{title}=\mathrm{Lotka-Volterra model},\mathrm{dirfield}=500\right)$
 > $\mathrm{DEplot}\left(\mathrm{LVS},\left[x\left(t\right),y\left(t\right)\right],t=0..12,x=0..3,y=0..2,\mathrm{arrows}=\mathrm{comet},\left[\left[x\left(0\right)=1,y\left(0\right)=0.5\right]\right],\mathrm{animatecurves}=\mathrm{true},\mathrm{dirfield}=300\right)$
 > $\mathrm{DEplot}\left(\mathrm{LVS},\left[x\left(t\right),y\left(t\right)\right],t=0..12,x=0..3,y=0..2,\mathrm{arrows}=\mathrm{comet},\mathrm{animatefield}=\mathrm{true},\mathrm{numframes}=50,\mathrm{dirfield}=300\right)$

The sixth example is a system of three DEs in $x\text{'}\left(t\right),y\text{'}\left(t\right),z\text{'}\left(t\right)$ showing how to plot a solution for $z\left(t\right)$ versus $y\left(t\right)$. To see a plot of $x\left(t\right)$ verses $y\left(t\right)$ verses $z\left(t\right)$ in 3 dimensions, use DEtools[DEplot3d].

 > $\mathrm{sys}:=\mathrm{D}\left(x\right)\left(t\right)=y\left(t\right)-z\left(t\right),\mathrm{D}\left(y\right)\left(t\right)=z\left(t\right)-x\left(t\right),\mathrm{D}\left(z\right)\left(t\right)=x\left(t\right)-y\left(t\right)\cdot 2$
 > $\mathrm{DEplot}\left(\left[\mathrm{sys}\right],\left[x\left(t\right),y\left(t\right),z\left(t\right)\right],t=-2..2,\left[\left[x\left(0\right)=1,y\left(0\right)=0,z\left(0\right)=2\right]\right],\mathrm{scene}=\left[z\left(t\right),x\left(t\right)\right],\mathrm{method}={\mathrm{classical}}_{\mathrm{foreuler}},\mathrm{stepsize}=0.05\right)$

The seventh example, a 3rd order equation, illustrates how to input higher order derivatives and initial values.

 > $\mathrm{de}:=\mathrm{cos}\left(x\right)\left(\frac{{ⅆ}^{3}}{ⅆ{x}^{3}}y\left(x\right)\right)-\left(\frac{{ⅆ}^{2}}{ⅆ{x}^{2}}y\left(x\right)\right)+\mathrm{π}\left(\frac{ⅆ}{ⅆx}y\left(x\right)\right)=y\left(x\right)-x$
 > $\mathrm{DEplot}\left(\mathrm{de},y\left(x\right),x=-2.5..1.4,\left[\left[y\left(0\right)=1,\mathrm{D}\left(y\right)\left(0\right)=2,{\mathrm{D}}^{\left(2\right)}\left(y\right)\left(0\right)=1\right]\right],y=-4..5\right)$

The next examples illustrate other arrow and color options and also an alternative way for inputting a system from which one can directly solve for the fixed points of the system. This system is a modified Lotka-Volterra system, and these are the commands to create the plot from the Plotting Guide.

 > $f:=\left(x,y\right)→x\left(1-y-0.1x\right):$$g:=\left(x,y\right)→0.3y\left(x-1\right):$
 > $\mathrm{MLV}:=\left[\frac{ⅆ}{ⅆt}x\left(t\right)=f\left(x\left(t\right),y\left(t\right)\right),\frac{ⅆ}{ⅆt}y\left(t\right)=g\left(x\left(t\right),y\left(t\right)\right)\right]$
 > $\mathrm{solve}\left(\left\{f\left(x,y\right)=0,g\left(x,y\right)=0\right\},\left\{x,y\right\}\right)$
 > $\mathrm{ivs}:=\left[\left[x\left(0\right)=1,y\left(0\right)=0.5\right],\left[x\left(0\right)=1,y\left(0\right)=1.5\right]\right]$
 > $\mathrm{DEplot}\left(\mathrm{MLV},\left[x\left(t\right),y\left(t\right)\right],t=0..10,\mathrm{ivs},\mathrm{arrows}=\mathrm{smalltwo},\mathrm{dirfield}=\left[12,12\right],\mathrm{color}={\mathrm{magnitude}}_{\mathrm{green},\mathrm{red}}\right)$
 > $\mathrm{DEplot}\left(\mathrm{MLV},\left[x\left(t\right),y\left(t\right)\right],t=-8..8,\mathrm{ivs},\mathrm{arrows}=\mathrm{mediumfill},\mathrm{color}=\left[f\left(x\left(t\right),y\left(t\right)\right),g\left(x\left(t\right),y\left(t\right)\right),0.5\right],\mathrm{linecolor}=\frac{t}{2}\right)$
 > $\mathrm{DEplot}\left(\mathrm{MLV},\left[x\left(t\right),y\left(t\right)\right],t=0..10,\mathrm{ivs},\mathrm{arrows}=\mathrm{comet},\mathrm{dirfield}=200,\mathrm{color}=\mathrm{magnitude},\mathrm{linecolor}=\mathrm{black}\right)$
 > $\mathrm{DEplot}\left(\mathrm{MLV},\left[x\left(t\right),y\left(t\right)\right],t=0..10,\mathrm{ivs},\mathrm{arrows}=\mathrm{comet},\mathrm{dirfield}=200,\mathrm{size}=\mathrm{magnitude},\mathrm{linecolor}=\left[\mathrm{cyan},\mathrm{yellow}\right],\mathrm{thickness}=5\right)$

The next example shows that arrows are plotted only in regions where the direction field is real valued.

 > $\mathrm{DEplot}\left(\frac{ⅆ}{ⅆx}y\left(x\right)=\frac{1\left(-x-{\left({x}^{2}+4y\left(x\right)\right)}^{\frac{1}{2}}\right)}{2},y\left(x\right),x=-3..3,y=-3..2,\mathrm{title}=\mathrm{Restricted domain},\mathrm{color}=\frac{1\left(-x-\left({x}^{2}+4y\right)\right)}{2}\right)$

The final examples illustrate other aspects of differential equations using animation.  To play the animations, you must click on the plot then click on the play button.

 > $\mathrm{vdP}:=\left[\frac{ⅆ}{ⅆt}x\left(t\right)=10\left(y\left(t\right)-\frac{{x\left(t\right)}^{3}}{3}+x\left(t\right)\right),\frac{ⅆ}{ⅆt}y\left(t\right)=-\frac{1x\left(t\right)}{10}\right]$
 > $\mathrm{DEplot}\left(\mathrm{vdP},\left[x\left(t\right),y\left(t\right)\right],t=0..20,x=-3..3,y=-2..2,\left[\left[x\left(0\right)=0.2,y\left(0\right)=0.2\right]\right],\mathrm{title}=\mathrm{van der Pol oscillator},\mathrm{dirfield}=400,\mathrm{arrows}=\mathrm{comet},\mathrm{size}=\mathrm{magnitude},\mathrm{numpoints}=505,\mathrm{linecolor}=\mathrm{blue},\mathrm{animatecurves}=\mathrm{true}\right)$
 > $\mathrm{DEplot}\left(\mathrm{vdP},\left[x\left(t\right),y\left(t\right)\right],t=0..20,x=-2..2,y=-1..1,\mathrm{title}=\mathrm{van der Pol oscillator},\mathrm{dirfield}=\left[\left[0.2,0.2\right],\left[-0.2,-0.2\right]\right],\mathrm{arrows}=\mathrm{comet},\mathrm{color}=\mathrm{blue},\mathrm{animatefield}=\mathrm{true},\mathrm{numframes}=100\right)$
 > $\mathrm{DEplot}\left(\left[\frac{ⅆ}{ⅆt}x\left(t\right)=y\left(t\right),\frac{ⅆ}{ⅆt}y\left(t\right)=-\mathrm{sin}\left(x\left(t\right)\right)\right],\left[x\left(t\right),y\left(t\right)\right],t=0..10,\left[\left[x\left(0\right)=0,y\left(0\right)=0.5\right],\left[x\left(0\right)=0,y\left(0\right)=1\right],\left[x\left(0\right)=0,y\left(0\right)=1.8\right],\left[x\left(0\right)=-2\mathrm{π},y\left(0\right)=1\right],\left[x\left(0\right)=2\mathrm{π},y\left(0\right)=0.5\right],\left[x\left(0\right)=-2\mathrm{π},y\left(0\right)=2.1\right],\left[x\left(0\right)=2\mathrm{π},y\left(0\right)=-2.1\right]\right],\mathrm{title}=\mathrm{Pendulum Vibrations},\mathrm{dirfield}=300,\mathrm{arrows}=\mathrm{comet},\mathrm{color}=\mathrm{magnitude},\mathrm{linecolor}=\mathrm{blue},\mathrm{animate}=\mathrm{true}\right)$
 > $r:=0.7\sqrt{{x\left(t\right)}^{2}+{y\left(t\right)}^{2}}:$
 > $\mathrm{des}:=\left[\frac{ⅆ}{ⅆt}x\left(t\right)=\mathrm{sin}\left(r\right)x\left(t\right)-y\left(t\right),\frac{ⅆ}{ⅆt}y\left(t\right)=\mathrm{sin}\left(r\right)y\left(t\right)+x\left(t\right)\right]$
 > $\mathrm{DEplot}\left(\mathrm{des},\left[x\left(t\right),y\left(t\right)\right],t=0..2,x=-15..15,y=-15..15,\mathrm{color}=\mathrm{magnitude},\mathrm{title}=\mathrm{Stable Limit Cycles},\mathrm{arrows}=\mathrm{curve},\mathrm{dirfield}=800,\mathrm{axes}=\mathrm{none}\right)$
 > $\mathrm{DEplot}\left(\mathrm{des},\left[x\left(t\right),y\left(t\right)\right],t=0..2,x=-15..15,y=-15..15,\mathrm{title}=\mathrm{Stable Limit Cycles},\mathrm{arrows}=\mathrm{comet},\mathrm{dirfield}=300,\mathrm{animate}=\mathrm{true}\right)$