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
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
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
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
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.
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:=ⅆⅆx⁢y⁡x=−12⁢x−12⁢x2+4⁢y⁡x
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
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:=ⅆⅆx⁢y⁡x=−12⁢x−12⁢x2+4⁢y⁡x
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
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:=ⅆⅆx⁢y⁡x=−12⁢x−12⁢x2+4⁢y⁡x
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
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:=ⅆⅆx⁢y⁡x=−12⁢x−12⁢x2+4⁢y⁡x
Color signifying magnitude of field
DE12:=ⅆⅆx⁢y⁡x=1⁢−x−x2+4⁢y⁡x122
DE12:=ⅆⅆx⁢y⁡x=−12⁢x−12⁢x2+4⁢y⁡x
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
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ⅆx3⁢y⁡x⁢cos⁡x−ⅆ2ⅆx2⁢y⁡x+π⁢ⅆⅆx⁢y⁡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−110⁢y⁡t
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
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