Visualizing differential equations with the VisualDSolve package

Antonín Slavík, Charles University in Prague, Czech Republic

Stan Wagon, Macalester College, St. Paul, Minnesota

What is VisualDSolve?

A package for visualizing solutions to ordinary differential equations (1st and 2nd order scalar equations, 1st and 2nd order systems, 1st and 2nd order vector equations)

An electronic book with package documentation (5 chapters) and many examples (differential equations modeling, 13 chapters)

VisualDSolve is built on top of NDSolve – the equations are passed to NDSolve and the results are displayed in a suitable form.

VisualDSolve history

First version of VisualDSolve by Stan Wagon and Dan Schwalbe (1994)

Dan Schwalbe and Stan Wagon, VisualDSolve: Visualizing Differential Equations With Mathematica. Springer, 1997 (book + floppy disk)

Package updates and documentation in electronic form available from Wolfram Research, Inc.

Antonín Slavík and Stan Wagon, 2009: Update for Mathematica 7, expanded documentation including new applications, improved help

Visual DSolve

Get["VisualDSolve`"]

A simple example (scalar 1st order equation):

VisualDSolve[x'[t]==((x[t])^2)+(t^2)-1,{t,-2.5,2.5},{x,-2.5,2.5},InitialValues->{0,0},ShowInitialValues->True,PlotStyle->Thickness[0.008],AspectRatio->Automatic]

Direction field:

VisualDSolve[x'[t]==((x[t])^2)+(t^2)-1,{t,-2.5,2.5},{x,-2.5,2.5},InitialValues->{0,0},ShowInitialValues->True,PlotStyle->Thickness[0.008],AspectRatio->Automatic,DirectionField->True,FieldMeshSize->20]

Multiple initial values:

VisualDSolve[x'[t]==((x[t])^2)+(t^2)-1,{t,-2.5,2.5},{x,-2.5,2.5},InitialValues->Table[1.5 {Cos[t],Sin[t]},{t,0,2 π,(π/10)}],ShowInitialValues->True,PlotStyle->Thickness[0.008],AspectRatio->Automatic,Rainbow->True,WindowShade->Gray]

Nullcline:

VisualDSolve[x'[t]==((x[t])^2)+(t^2)-1,{t,-2.5,2.5},{x,-2.5,2.5},InitialValues->Table[1.5 {Cos[t],Sin[t]},{t,0,2 π,(π/10)}],ShowInitialValues->True,PlotStyle->Thickness[0.008],AspectRatio->Automatic,Rainbow->True,WindowShade->Gray,Isoclines->True, IsoclineStyle->{White,Thick}]

Isocline shading:

VisualDSolve[x'[t]==((x[t])^2)+(t^2)-1,{t,-2.5,2.5},{x,-2.5,2.5},InitialValues->Table[1.5 {Cos[t],Sin[t]},{t,0,2 π,(π/10)}],PlotStyle->Thickness[0.008],AspectRatio->Automatic,Rainbow->True,IsoclineShading->True,Contours->15,ShowInitialValues->True]

SystemSolutionPlot

An example from chemistry (autocatalator reaction):

system={
(Subscript[x, 1]^′)[t]==-0.002 (Subscript[x, 1])[t],
(Subscript[x, 2]^′)[t]==0.4 (Subscript[x, 1])[t]-0.08 (Subscript[x, 2])[t]-(Subscript[x, 2])[t] (((Subscript[x, 3])[t])^2),
(Subscript[x, 3]^′)[t]==-(Subscript[x, 3])[t]+0.08 (Subscript[x, 2])[t]+(Subscript[x, 2])[t] (((Subscript[x, 3])[t])^2),
(Subscript[x, 4]^′)[t]==0.005 (Subscript[x, 3])[t]};

SystemSolutionPlot[system,
{(Subscript[x, 1])[t],(Subscript[x, 2])[t],(Subscript[x, 3])[t],(Subscript[x, 4])[t]},{t,0,700},InitialValues->{2.5,0,0,0},
PlotRange->{-0.132,3.432},PlotStyle->{{Green,Thick},{Yellow,Thick},{Red,Thick},{Blue,Thick}},Prolog->{Gray,Rectangle[{0,0},{701,3.3}]}]

Obtaining individual solution components:

SystemSolutionPlot[system,
{(Subscript[x, 1])[t],(Subscript[x, 2])[t],(Subscript[x, 3])[t],(Subscript[x, 4])[t]},{t,0,700},InitialValues->{2.5,0,0,0},PlotVariables->{{(Subscript[x, 2])},{(Subscript[x, 3])}}]//GraphicsRow

PhasePlot

A helium-filled balloon:

sys={v'[t]==((9800-20 v[t]-0.1 ((v[t])^2)-98 y[t])/(3+0.1y[t])),
v[t]==y'[t]};

PhasePlot[sys,{v[t],y[t]},{t,0,10},{v,-275,275},{y,0,175},InitialValues->{0,0},AspectRatio->1,PlotStyle->{Black,Thickness[0.015]}]

Nullclines and shaded phase plane:

PhasePlot[sys,{v[t],y[t]},{t,0,10},{v,-275,275},{y,0,175},InitialValues->{0,0},AspectRatio->1,PlotStyle->{Black,Thickness[0.015]},Nullclines->True,NullclineShading->True]

Direction field:

PhasePlot[sys,{v[t],y[t]},{t,0,10},{v,-275,275},{y,0,175},InitialValues->{0,0},AspectRatio->1,PlotStyle->{Black,Thickness[0.015]},Nullclines->True,NullclineShading->True,VectorField->True,FieldLogScale->4,FieldThickness->Thickness[0.006],FieldColor->RandomGrayLevel]

Flow field:

PhasePlot[sys,{v[t],y[t]},{t,0,10},{v,-275,275},{y,0,175},InitialValues->{0,0},AspectRatio->1,PlotStyle->{Black,Thickness[0.015]},Nullclines->True,NullclineShading->True,FlowField->True,FieldLogScale->Automatic,FieldColor->GrayLevel]

Rössler's system:

rossler={
x'[t]==-y[t]-z[t],
y'[t]==x[t]+0.2y[t],
z'[t]==0.2+(-5.3+x[t]) z[t]};

PhasePlot[rossler,{x[t],y[t],z[t]},{t,0,50},{x,-10,10},{y,-10,10},{z,0,20},InitialValues->{0,2,0},PlotStyle->{Orange,Specularity[Yellow,10],Tube[0.3]}, BoxRatios->Automatic,Boxed->True]

Projection to the x-y plane:

PhasePlot[rossler,{x[t],y[t],z[t]},{t,0,50},{x,-10,10},{y,-10,10},InitialValues->{0,2,0},PlotStyle->{Orange,Thick}]

SecondOrderPlot

A planet orbiting around the Sun:

e=0.7;
SecondOrderPlot[
X''[t]==((-X[t])/((Norm[X[t]])^3)),X[t],{t,0,2 π},{X[1],-2,1},{X[2],-1.4,1.4},InitialValues->{1-e,0,0,(Sqrt[((1+e)/(1-e))])},PlotStyle->Thickness[0.015],Epilog->{PointSize[0.03],Point[{0,0}]}]

An illustration of Kepler's law:

SecondOrderPlot[
X''[t]==((-X[t])/((Norm[X[t]])^3)),X[t],{t,0,2 π},{X[1],-2,1},{X[2],-1.4,1.4},InitialValues->{1-e,0,0,(Sqrt[((1+e)/(1-e))])},ParametricPlotFunction->ColorParametricPlot,PlotStyle->Thickness[0.015],Speed->True,WindowShade->Gray,Epilog->{Yellow,PointSize[0.03],Point[{0,0}]}]

Damped pendulum:

SecondOrderPlot[10 Sin[x[t]]+x'[t]+x''[t]==0,x[t],{t,0,15},{x,-16,16},{x',-16,16},Nullclines->True,NullclinePlotPoints->30,
NullclineShading->True,FastPlotting->True,InitialValues->Join[Table[{x,15},{x,-14,-7,0.8}],Table[{x,-15},{x,7.6,14,0.8}]],PlotStyle->Black,AspectRatio->1/GoldenRatio]

PoincareSection

The Duffing equation:

duffing=x''[t]-x[t]+((x[t])^3)+0.15 x'[t]==0.3 Cos[t];

PoincareSection[duffing,{t,0,1000},{x,-1.6,1.6},{x',-0.85,1.3},{-1,1},TimeInterval->2 π,Axes->False,Frame->True,FrameTicks->{{Range[-1,1,1],{}},{Range[-1.5,1.5,.5],{}}},PointStyle->{Yellow,PointSize[0.015]},
WindowShade->Gray,MaxSteps->∞]

A strange attractor of the Duffing equation:

PoincareSection[duffing,{t,0,20000},{x,-1.6,1.6},{x',-0.85,1.3},{-1,1},TimeInterval->2 π,Axes->False,Frame->True,FrameTicks->{{Range[-1,1,1],{}},{Range[-1.5,1.5,.5],{}}},PointStyle->{Yellow,PointSize[0.01]},
WindowShade->Gray,MaxSteps->∞]

Documentation

Help messages + help browser:

?SystemSolutionPlot

The VisualDSolve Manual
(5 chapters, access via Documentation Center or palette)

VisualDSolve and Differential Equations Modeling

Differential Equations and Mathematica

Some Parachute Experiments

Linear Systems

Logistic Models of Population Growth

Hamiltonian Systems

A Devilish Equation

Lead Flow in the Human Body

Making a Discus Fly

A Double Pendulum

The Duffing Equation

The Tetrapods of Wada

I Tossed a Book into the Air...

Miscellany