Intro to Ordinary Differential Equations Using Maple

Copy and paste the following (red) maple commands into maple, execute them, and then do the exercise.

Many routines for working with ODEs (and PDEs) are contained in the Maple package, DEtools. This should  be first loaded into memory using the with command.

> with(DEtools);

[DEnormal, DEplot, DEplot3d, DEplot_polygon, DFactor, DFactorLCLM, DFactorsols, Dchangevar, GCRD, LCLM, MeijerGsols, PDEchangecoords, RiemannPsols, Xchange, Xcommutator, Xgauge, abelsol, adjoint, auto...[DEnormal, DEplot, DEplot3d, DEplot_polygon, DFactor, DFactorLCLM, DFactorsols, Dchangevar, GCRD, LCLM, MeijerGsols, PDEchangecoords, RiemannPsols, Xchange, Xcommutator, Xgauge, abelsol, adjoint, auto...[DEnormal, DEplot, DEplot3d, DEplot_polygon, DFactor, DFactorLCLM, DFactorsols, Dchangevar, GCRD, LCLM, MeijerGsols, PDEchangecoords, RiemannPsols, Xchange, Xcommutator, Xgauge, abelsol, adjoint, auto...[DEnormal, DEplot, DEplot3d, DEplot_polygon, DFactor, DFactorLCLM, DFactorsols, Dchangevar, GCRD, LCLM, MeijerGsols, PDEchangecoords, RiemannPsols, Xchange, Xcommutator, Xgauge, abelsol, adjoint, auto...[DEnormal, DEplot, DEplot3d, DEplot_polygon, DFactor, DFactorLCLM, DFactorsols, Dchangevar, GCRD, LCLM, MeijerGsols, PDEchangecoords, RiemannPsols, Xchange, Xcommutator, Xgauge, abelsol, adjoint, auto...[DEnormal, DEplot, DEplot3d, DEplot_polygon, DFactor, DFactorLCLM, DFactorsols, Dchangevar, GCRD, LCLM, MeijerGsols, PDEchangecoords, RiemannPsols, Xchange, Xcommutator, Xgauge, abelsol, adjoint, auto...[DEnormal, DEplot, DEplot3d, DEplot_polygon, DFactor, DFactorLCLM, DFactorsols, Dchangevar, GCRD, LCLM, MeijerGsols, PDEchangecoords, RiemannPsols, Xchange, Xcommutator, Xgauge, abelsol, adjoint, auto...[DEnormal, DEplot, DEplot3d, DEplot_polygon, DFactor, DFactorLCLM, DFactorsols, Dchangevar, GCRD, LCLM, MeijerGsols, PDEchangecoords, RiemannPsols, Xchange, Xcommutator, Xgauge, abelsol, adjoint, auto...[DEnormal, DEplot, DEplot3d, DEplot_polygon, DFactor, DFactorLCLM, DFactorsols, Dchangevar, GCRD, LCLM, MeijerGsols, PDEchangecoords, RiemannPsols, Xchange, Xcommutator, Xgauge, abelsol, adjoint, auto...[DEnormal, DEplot, DEplot3d, DEplot_polygon, DFactor, DFactorLCLM, DFactorsols, Dchangevar, GCRD, LCLM, MeijerGsols, PDEchangecoords, RiemannPsols, Xchange, Xcommutator, Xgauge, abelsol, adjoint, auto...

Entering ODEs in Maplle is the first thing to learn:

> diff(y(t),t)+y(t)=exp(-t);

> diff(y(t),t)-y(t)=sin(t);

> m*diff(x(t),t$2)+b*diff(x(t),t)+k*x(t)=0;

> diff(y(t),t$4)-10*diff(y(t),t$3)+35*diff(y(t),t$2)-50*y(t)+24=5*exp(t);

> des := diff(y(t),t) = z(t) - y(t),diff(z(t),t) = y(t);

Exercise: Enter the ODE,  y'' + y = 2cos(x) + 1.

Maple can sometimes tell if a ODE is separable (resp., linear, homogeneous) or not (NONE means either "no" or "unknown"):

>

> de:=diff(y(t),t)=y(t);
odeadvisor(de,[homogeneous]);

odeadvisor(de,[separable]);

odeadvisor(de,[linear]);

de := diff(y(t), t) = y(t)

[[_homogeneous, class D]]

[_separable]

[_linear]

> de:=diff(y(t),t)+y(t)=exp(-t);
odeadvisor(de,[homogeneous]);

odeadvisor(de,[linear]);

odeadvisor(de,[separable]);

de := diff(y(t), t)+y(t) = exp(-t)

[NONE]

[[_linear, class A]]

[NONE]

> de:=diff(y(t),t)+y(t)=1;
odeadvisor(de,[homogeneous]);

odeadvisor(de,[linear]);

odeadvisor(de,[separable]);

de := diff(y(t), t)+y(t) = 1

[NONE]

[[_linear, class A]]

[_separable]

> de:=diff(y(t),t)+y(t)^2=0;
odeadvisor(de,[homogeneous]);

odeadvisor(de,[linear]);

odeadvisor(de,[separable]);

de := diff(y(t), t)+y(t)^2 = 0

[[_homogeneous, class G]]

[NONE]

[_separable]

> de:=diff(y(t),t)+y(t)^2=1;
odeadvisor(de,[homogeneous]);

odeadvisor(de,[linear]);

odeadvisor(de,[separable]);

de := diff(y(t), t)+y(t)^2 = 1

[NONE]

[NONE]

[_separable]

> de:=diff(y(t),t$2)+y(t)=1;
odeadvisor(de,[homogeneous]);

odeadvisor(de,[linear]);

odeadvisor(de,[separable]);

de := diff(y(t), `$`(t, 2))+y(t) = 1

[NONE]

[[_2nd_order, _linear, _nonhomogeneous]]

[NONE]

> de:=diff(y(t),t$2)^2+y(t)=1;
odeadvisor(de,[homogeneous]);

odeadvisor(de,[linear]);

odeadvisor(de,[separable]);

de := diff(y(t), `$`(t, 2))^2+y(t) = 1

[NONE]

[NONE]

[NONE]

Exercise: COnsider the ODE, y' + cos(y) = x - 1. Type this into Maple and see if it thinks it is homogeneous, linear, or separable.

Solving ODEs can be done using the dsolve command.

> de:=diff(y(t),t)+y(t)=exp(-t);
dsolve(de,y(t));

de := diff(y(t), t) = y(t)

y(t) = _C1*exp(t)

> de:=diff(y(t),t)+y(t)=exp(-t);
ic:=y(0)=3;

dsolve({de,ic},y(t));

de := diff(y(t), t)+y(t) = exp(-t)

ic := y(0) = 3

y(t) = (t+3)*exp(-t)

>

> de:=(m,b,k)->m*diff(x(t),t$2)+b*diff(x(t),t)+k*x(t)=0:
de(m,b,k);

de(1,0,1);

dsolve(de(1,0,1),x(t));

m*diff(x(t), `$`(t, 2))+b*diff(x(t), t)+k*x(t) = 0

diff(x(t), `$`(t, 2))+x(t) = 0

x(t) = _C1*sin(t)+_C2*cos(t)

> ics:=x(0)=1,D(x)(0)=1;
dsolve({de(1,0,1),ics},x(t));

ics := x(0) = 1, D(x)(0) = 1

x(t) = sin(t)+cos(t)

>

> des := diff(y(t),t) = -z(t) ,diff(z(t),t) = y(t);
ics:=y(0)=0, z(0)=1;

dsolve({des,ics}, {y(t), z(t)});

des := diff(y(t), t) = -z(t), diff(z(t), t) = y(t)

ics := y(0) = 0, z(0) = 1

{z(t) = cos(t), y(t) = -sin(t)}

> des := diff(y(t),t) = 4*z(t) ,diff(z(t),t) = y(t);
ics:=y(0)=0, z(0)=1;

dsolve({des,ics}, {y(t), z(t)});

des := diff(y(t), t) = 4*z(t), diff(z(t), t) = y(t)

ics := y(0) = 0, z(0) = 1

{z(t) = 1/2*exp(-2*t)+1/2*exp(2*t), y(t) = -exp(-2*t)+exp(2*t)}

Exercise: Solve y' - y = x,  y(0) = 1, using dsolve.

Plotting solutions to ODEs can be done using the DEplot command.

> de:=(m,b,k)->m*diff(x(t),t$2)+b*diff(x(t),t)+k*x(t)=0:
DEplot(de(1,0,1), {x(t)}, 0..10, [[x(0)=3, D(x)(0)=-2]],title=`Damped Oscillator`);

[Plot]

> de:=(m,b,k)->m*diff(x(t),t$2)+b*diff(x(t),t)+k*x(t)=0:
DEplot(de(1,0.1,1), {x(t)}, 0..10, [[x(0)=3, D(x)(0)=-2]],title=`Damped Oscillator`);

[Plot]

> de:=(m,b,k)->m*diff(x(t),t$2)+b*diff(x(t),t)+k*x(t)=0:
DEplot(de(1,0,1), {x(t)}, 0..10, [[x(0)=3, D(x)(0)=-4]],title=`Damped Oscillator`);

[Plot]

Note the subtle difference between the 1st and last graph.

Exercise: Plot the solution to y' + y = 1, y(0) = -1, for  0 < x < 3.

Systems of Equations - Dynamical System Model

> des := diff(x(t),t) = -4*y(t),diff(y(t),t) = -x(t);
DEplot({des}, [x(t),y(t)], 0..(0.5), [[x(0)=100,y(0)=100]], title=`plot of (x(t),y(t)), t=0..2`);

des := diff(x(t), t) = -4*y(t), diff(y(t), t) = -x(t)

[Plot]

> des := diff(x(t),t) = 2.9*x(t)-4*y(t),diff(y(t),t) = -x(t);
DEplot({des}, [x(t),y(t)], 0..(0.9), [[x(0)=100,y(0)=100]], title=`plot of (x(t),y(t)), t=0..2`);

des := diff(x(t), t) = 2.9*x(t)-4*y(t), diff(y(t), t) = -x(t)

[Plot]

>

Phase portraits:

> de := diff(y(x),x)+y(x)=cos(x);
phaseportrait(de, y(x), x=-1..15, [[y(0)=0],[y(0)=1],[y(0)=-1]], title=`Asymptotic Solution`,

    color=magenta, linecolor=[red,blue,green]);

de := diff(y(x), x)+y(x) = cos(x)

[Plot]

Exercise: Plot the phase portrait to y' + y = 1, y(0) = -1, = 0, = 1, for  -2 < x < 2.

>

For more examples, see

 http://www.mapleapps.com/powertools/des/des.shtml      

 http://www.mapleapps.com/categories/maple_tools/functionality/html/odes1.html

 http://www.mapleapps.com/List.asp?CategoryID=7&Category=Differential%20Equations  

>

Created by wdj, 7-30-2003