Plotting Two-Dimensional Differential Equations
The DEplot routine from the DEtools package is used to generate plots that are defined by differential equations. This worksheet details some of the options that are available, in sections on Interface and Options.
In order to access the routines in the DEtools package by their short names, the with command has been used.
restart
with⁡DEtools:
Interface
The interface accepts forms of input similar to those allowed by the dsolve/numeric routine. For example,
DE1:=ⅆ3ⅆx3⁢y⁡x⁢cos⁡x−ⅆⅆx⁢y⁡x=y⁡x
DEplot⁡DE1,y⁡x,x=0..1.57,y⁡0=1,D⁡y⁡0=2,D2⁡y⁡0=2
DE1≔ⅆ3ⅆx3y⁡x⁢cos⁡x−ⅆⅆxy⁡x=y⁡x
Here is another example which uses strictly the D operator.
DE2:=D3⁡y⁡x⁢cos⁡x−D⁡y⁡x=y⁡x
DEplot⁡DE2,y⁡x,x=0..1.57,y⁡0=1,D⁡y⁡0=2,D2⁡y⁡0=2
DE2≔D3⁡y⁡x⁢cos⁡x−D⁡y⁡x=y⁡x
Autonomous systems are automatically determined for plotting phase portraits. For instance,
DE3:=ⅆⅆx⁢y⁡x=y⁡x−z⁡x,ⅆⅆx⁢z⁡x=z⁡x−2⁢y⁡x
DEplot⁡DE3,y⁡x,z⁡x,x=0..3,y=0..2,z=−4..4,arrows=large
DE3≔ⅆⅆxy⁡x=y⁡x−z⁡x,ⅆⅆxz⁡x=z⁡x−2⁢y⁡x
An example of a non-autonomous system is
DE4:=ⅆⅆx⁢y⁡x=y⁡x−z⁡x⁢x,ⅆⅆx⁢z⁡x=z⁡x−2⁢y⁡x
DEplot⁡DE4,y⁡x,z⁡x,x=0..3,y=0..2,z=−4..4,y⁡0=1,z⁡0=1,arrows=large
DE4≔ⅆⅆxy⁡x=y⁡x−z⁡x⁢x,ⅆⅆxz⁡x=z⁡x−2⁢y⁡x
To view examples that make use of the autonomous command, consult the autonomous help page.
Inputs may be specified as lists or sets. If lists are used, the order of the variables in a list control the ordering of plot axes (along the lines of the scene optional equation).
Options
Some of the options available to DEplot are summarized in the subsections that follow.
color
Color handling is allowed for the plotting of arrows in various ways. Details are found in the DEplot help page.
plot/color Name
DE5:=ⅆⅆx⁢y⁡x=1⁢−x−x2+4⁢y⁡x122
DEplot⁡DE5,y⁡x,x=−3..3,y=−3..2,title=Restricted domain-C1,arrows=medium,color=turquoise
DE5≔ⅆⅆxy⁡x=−x2−x2+4⁢y⁡x2
DEplot respects plots:-setcolors
When plots:-setcolors is used to set the default colors for plots, DEplot now respects that setting.
plots:-setcolorsBright:
DEplot⁡DE5,yx,x=−3..3,y=−3..2,arrows=medium
plots:-setcolorsNiagara:
HUE Value
DE6:=ⅆⅆt⁢y⁡t=sin⁡t−y⁡t
DEplot⁡DE6,y⁡t,t=−π..π,y=−π..π,arrows=large,title=C2,color=COLOR⁡HUE,0.345
DE6≔ⅆⅆty⁡t=sin⁡t−y⁡t
RGB Value
DE7:=ⅆⅆx⁢y⁡x=1⁢−x−x2+4⁢y⁡x122
DEplot⁡DE7,y⁡x,x=−3..3,y=−3..2,title=Restricted domain-C 3,arrows=medium,color=COLOR⁡RGB,0.845,0.765,0.689
DE7≔ⅆⅆxy⁡x=−x2−x2+4⁢y⁡x2
Procedure Applied to HUE
DE8:=ⅆⅆt⁢y⁡t=sin⁡t−y⁡t
c_func1:=procs,tifsin⁡s<Float⁡5,−1thencos⁡telsesin⁡tend ifend proc:
DEplot⁡DE8,y⁡t,t=−π..π,y=−π..π,arrows=large,title=C4,color=c_func1
DE8≔ⅆⅆty⁡t=sin⁡t−y⁡t
Procedure Applied to RGB
DE9:=ⅆⅆx⁢y⁡x=1⁢−x−x2+4⁢y⁡x122
c_func1:=s,t→sin⁡s⁢t:c_func2:=s,t→coss−t:
DEplot⁡DE9,y⁡x,x=−3..3,y=−3..2,title=Restricted domain - C5,arrows=medium,color=0.5,c_func1,c_func2
DE9≔ⅆⅆxy⁡x=−x2−x2+4⁢y⁡x2
Expression Applied as HUE
DE10:=ⅆⅆt⁢y⁡t=sin⁡t−y⁡t
DEplot⁡DE10,y⁡t,t=−π..π,y=−π..π,arrows=large,title=C6,color=y⁡t−sin⁡t2
DE10≔ⅆⅆty⁡t=sin⁡t−y⁡t
Expression List Applied as HUE
DE11:=ⅆⅆx⁢y⁡x=1⁢−x−x2+4⁢y⁡x122
DEplot⁡DE11,y⁡x,x=−3..3,y=−3..2,title=Restricted domain - C7,arrows=medium,color=y⁡t2,0.3,y⁡t3
DE11≔ⅆⅆxy⁡x=−x2−x2+4⁢y⁡x2
Color signifying magnitude of field
DE12:=ⅆⅆx⁢y⁡x=1⁢−x−x2+4⁢y⁡x122
DE12≔ⅆⅆxy⁡x=−x2−x2+4⁢y⁡x2
Default is [blue,red], blue for small magnitude, and red for large
DEplot⁡DE12,y⁡x,x=−3..3,y=−3..2,arrows=large,color=magnitude
Can specify colors for small and large magnitude instead
DEplot⁡DE12,yx,x=−3..3,y=−3..2,arrows=large,color=magnitudeblue,white
numpoints (and iterations and stepsize)
The numpoints option allows specification of the number of points used to plot solution curves in the DEplot.
DE13:=ⅆ2ⅆx2⁢y⁡x=y⁡x
DE13≔ⅆ2ⅆx2y⁡x=y⁡x
DEplot⁡DE13,y⁡x,x=−2..2,y⁡0=1,D⁡y⁡0=2,y=−6..6,numpoints=11
DEplot⁡DE13,y⁡x,x=−2..2,y⁡0=1,D⁡y⁡0=2,y=−6..6,numpoints=101
The stepsize option can also be used to specify the number of points used in the plot, but only when the number of points it requests exceeds the default of 49, and one must take great care, as stepsize is also passed as an option to numerical dsolve when any of the classical methods are in use (not the default).
withplots:
P1≔DEplotDE13,y⁡x,x=−2..2,y⁡0=1,D⁡y⁡0=2,y=−6..6,stepsize=0.02:displayP1;nops⁡op⁡1,1,P1
201
P2≔DEplotDE13,y⁡x,x=−2..2,y⁡0=1,D⁡y⁡0=2,y=−6..6,stepsize=0.01:displayP2;nops⁡op⁡1,1,P2
401
When using a classical method (see the method option below), the option iterations allows the user to ask that the specified number of steps be taken for each stepsize in the plot. This gives a greater accuracy in the output points, while retaining the actual number of output points present in the plot. Again, unless the number of points dictated by the step size is greater than 49, 49 points will be used.
In this example, the stepsize sent to dsolve is actually 0.02/2=0.01
DEplot⁡DE13,y⁡x,x=−2..2,y⁡0=1,D⁡y⁡0=2,y=−6..6,method=classicalrk4,stepsize=0.02,iterations=2
In this example, the stepsize sent to dsolve is actually 0.02/4=0.005
DEplot⁡DE13,y⁡x,x=−2..2,y⁡0=1,D⁡y⁡0=2,y=−6..6,method=classicalrk4,stepsize=0.02,iterations=4
linecolor
The linecolor option works in a fashion similar to that of color, but it is applied to the solution curves.
DE14:=D⁡x⁡t=y⁡t−z⁡t,D⁡y⁡t=z⁡t−x⁡t,D⁡z⁡t=x⁡t−y⁡t⋅2
DEplot⁡DE14,x⁡t,y⁡t,z⁡t,t=−2..2,x⁡0=1,y⁡0=0,z⁡0=2,stepsize=0.05,scene=z⁡t,x⁡t,title=LC 1,linecolor=plum
DE14≔D⁡x⁡t=y⁡t−z⁡t,D⁡y⁡t=z⁡t−x⁡t,D⁡z⁡t=x⁡t−2⁢y⁡t
HUE Name
DE15:=cos⁡x⁢ⅆ3ⅆx3⁢y⁡x−ⅆ2ⅆx2⁢y⁡x+π⁢ⅆⅆx⁢y⁡x=y⁡x−x
DEplot⁡DE15,y⁡x,x=−2.5..1.4,y⁡0=1,D⁡y⁡0=2,D2⁡y⁡0=1,y=−4..5,numpoints=30,title=LC 2,linecolor=COLOR⁡HUE,0.254
DE15≔ⅆ3ⅆx3y⁡x⁢cos⁡x−ⅆ2ⅆx2y⁡x+π⁢ⅆⅆxy⁡x=y⁡x−x
DE16:=D⁡x⁡t=y⁡t,D⁡y⁡t=−sin⁡x⁡t−y⁡t10
f1:=x,y→sin⁡x−cos⁡y:
DEplot⁡DE16,y⁡t,x⁡t,t=−15..5,x⁡0=1,y⁡0=1,color=f1,arrows=large,numpoints=81,title=LC 3,linecolor=COLOR⁡RGB,0.5,0.5,0.6
DE16≔D⁡x⁡t=y⁡t,D⁡y⁡t=−sin⁡x⁡t−y⁡t10
DE17:=ⅆⅆt⁢x⁡t=x⁡t⁢1−y⁡t,ⅆⅆt⁢y⁡t=0.3⁢y⁡t⁢x⁡t−1
DEplot⁡DE17,x⁡t,y⁡t,t=−7..7,x⁡0=1.2,y⁡0=1.2,x⁡0=1,y⁡0=0.7,numsteps=76,title=Lotka-Volterra model - LC 4,color=0.3⁢y⁡t⁢x⁡t−1,x⁡t⁢1−y⁡t,0.1,linecolor=t2,arrows=medium
DE17≔ⅆⅆtx⁡t=x⁡t⁢1−y⁡t,ⅆⅆty⁡t=0.3⁢y⁡t⁢x⁡t−1
Procedure Applied as HUE
lc_proc:=proctif0<sin⁡t − cos⁡tthent/2elset/4end ifend proc:
DE18:=D⁡x⁡t=−2⁢y⁡t,D⁡y⁡t=x⁡t−2⁢y⁡t
vars:=x⁡t,y⁡t:
inits:=x⁡0=0,y⁡0=2,x⁡0=0,y⁡0=4,x⁡0=−6,y⁡0=0,x⁡0=−4,y⁡0=0,x⁡0=0,y⁡0=−2,x⁡0=0,y⁡0=−4,x⁡0=6,y⁡0=0,x⁡0=4,y⁡0=0:
DEplot⁡DE18,vars,t=−10..10,stepsize=0.2,scene=x,y,x=−10..10,y=−10..10,inits,title=Spiral Sink - LC 5,linecolor=lc_proc
DE18≔D⁡x⁡t=−2⁢y⁡t,D⁡y⁡t=x⁡t−2⁢y⁡t
method
The method option allows the user to make full use of the variety of numerical integration schemes available in dsolve/numeric. The default used is rkf45. Consider the following two-dimensional differential equation plot that uses the classical[foreuler] method.
DE19:=D⁡x⁡t=y⁡t−z⁡t,D⁡y⁡t=z⁡t−x⁡t,D⁡z⁡t=x⁡t−y⁡t⋅2
DEplot⁡DE19,x⁡t,y⁡t,z⁡t,t=−2..2,x⁡0=1,y⁡0=0,z⁡0=2,numpoints=81,scene=z⁡t,x⁡t,linecolor=sint⁢π2,method=classicalforeuler
DE19≔D⁡x⁡t=y⁡t−z⁡t,D⁡y⁡t=z⁡t−x⁡t,D⁡z⁡t=x⁡t−2⁢y⁡t
Now we use the dverk78 method for another plot.
DE20:=D⁡x⁡t=y⁡t−z⁡t,D⁡y⁡t=z⁡t−x⁡t,D⁡z⁡t=x⁡t−y⁡t⋅2
DEplot⁡DE20,x⁡t,y⁡t,z⁡t,t=−2..2,x⁡0=1,y⁡0=0,z⁡0=2,numpoints=81,scene=z⁡t,x⁡t,linecolor=sin⁡t⁢π2,method=dverk78
DE20≔D⁡x⁡t=y⁡t−z⁡t,D⁡y⁡t=z⁡t−x⁡t,D⁡z⁡t=x⁡t−2⁢y⁡t
obsrange
The obsrange option indicates whether the internal integration should stop once one of the user-specified ranges is exceeded. The default is to continue integration along a solution curve, even after the user boundaries have been exceeded. To illustrate this, let us graph two DE plots.
DE21:=D⁡y⁡x=y⁡x2⁢sin⁡x
DEplot⁡DE21,yx,x=−5..5,y=−2..5,y⁡1=0.45,y⁡1=0.6,y⁡1=−1,arrows=small,dirfield=30,30,numpoints=101,obsrange=true
DE21≔D⁡y⁡x=y⁡x2⁢sin⁡x
DE21;DEplot⁡DE21,yx,x=−5..5,y=−2..5,y⁡1=0.45,y⁡1=0.6,y⁡1=−1,arrows=small,dirfield=30,30,numpoints=101,obsrange=false
D⁡y⁡x=y⁡x2⁢sin⁡x
arrow styles and size
There are 8 types of arrows available for use in DEplot.
DE22:=ⅆⅆt⁢y⁡t=sin⁡t−y⁡t
DE22≔ⅆⅆty⁡t=sin⁡t−y⁡t
The 4 original arrow types are 'small', 'medium', 'large' and 'line':
DEplot⁡DE22,y⁡t,t=−π..π,y=−π..π,arrows=small
DEplot⁡DE22,y⁡t,t=−π..π,y=−π..π,arrows=medium
DEplot⁡DE22,y⁡t,t=−π..π,y=−π..π,arrows=large
DEplot⁡DE22,y⁡t,t=−π..π,y=−π..π,arrows=line
Two of the new standard arrow types are 'smalltwo' and 'mediumfill':
DEplot⁡DE22,y⁡t,t=−π..π,y=−π..π,arrows=smalltwo
DEplot⁡DE22,y⁡t,t=−π..π,y=−π..π,arrows=mediumfill
The other two newer arrow types are curved arrows. These types of arrows, 'comet' and 'curve', are not straight arrows, but have a curvature that is computed from the field:
DEplot⁡DE22,y⁡t,t=−π..π,y=−π..π,arrows=comet
DEplot⁡DE22,y⁡t,t=−π..π,y=−π..π,arrows=curve
It is also possible to increase or decrease the size of the arrows with the 'arrowsize' option. Values larger than 1 increase the arrow size while values smaller than 1 decrease the arrow size.
DEplot⁡DE22,yt,t=−π..π,y=−π..π,arrows=curve,arrowsize=12
DEplot⁡DE22,yt,t=−π..π,y=−π..π,arrows=curve,arrowsize=2
Finally, it is possible to specify that the size of the arrows increase with the strength of the field:
DE23:=D⁡y⁡x=y⁡x2⁢sin⁡x
DEplot⁡DE23,yx,x=0..5,y=0..5,arrowsize=magnitude
DE23≔D⁡y⁡x=y⁡x2⁢sin⁡x
arrow placement
DE24:=ⅆⅆt⁢y⁡t=sin⁡t−y⁡t
DE24≔ⅆⅆty⁡t=sin⁡t−y⁡t
In addition to the standard placement of arrows in a grid:
DEplot⁡DE24,y⁡t,t=−π..π,y=−π..π,arrows=curve,dirfield=20,20
Random placement of arrows is also possible by simply specifying an arrow count as the argument to 'dirfield':
DEplot⁡DE24,y⁡t,t=−π..π,y=−π..π,arrows=curve,dirfield=400
animation
Two types of animation are possible with DEplot:
1) Curve animation: The solution curve is traced out with each frame of the animation
2) Field animation: The field arrows move in the direction of the field during the animation
These can be used together by the 'animate' option, or separately by the 'animatecurves' and 'animatefield' options, with 'numframes' used to specify the number of animation frames (default is 25)
DE25:=ⅆⅆt⁢x⁡t=x⁡t⁢1−y⁡t,ⅆⅆt⁢y⁡t=0.3⁢y⁡t⁢x⁡t−1
DEplot⁡DE25,x⁡t,y⁡t,t=0..10,x=0..3,y=0..2,arrows=comet,x⁡0=1,y⁡0=0.5,dirfield=100,animatecurves=true
DE25≔ⅆⅆtx⁡t=x⁡t⁢1−y⁡t,ⅆⅆty⁡t=0.3⁢y⁡t⁢x⁡t−1
To play the animation, click the plot and the from the Animation Toolbar, select Play ( ).
DEplot⁡DE25,x⁡t,y⁡t,t=0..10,x=0..3,y=0..2,arrows=comet,x⁡0=1,y⁡0=0.5,dirfield=100,animatefield=true
DEplot⁡DE25,x⁡t,y⁡t,t=0..10,x=0..3,y=0..2,arrows=comet,x⁡0=1,y⁡0=0.5,dirfield=100,animate=true
plot and dsolve/numeric
A variety of standard plot and dsolve/numeric options are allowed as options to DEplot.
DEplotDxt=yt+zt,Dyt=−xt−yt+wt, Dzt=xt+yt−zt,Dwt=xt−wtzt, xt,yt,zt,wt, t=0..10, x0=1,y0=0,z0=2,w0=3,x0=0,z0=0.25,y0=0.5,w0=0.165, scene=zt,wt,numsteps=101,axes=BOXED,linestyle=dashdot,method=rkf45, startinit=true,maxfun=5000,xtickmarks=10
For more information, consult the DEplot help page. Also, see the worksheet Plotting Three-Dimensional Equations . You can also refer to the following help pages: dsolve/numeric, D operator, classical method, and dverk78 method.
Return to Index for Example Worksheets
Download Help Document