newuser,topic07

(7) Differential Equations

Before examining this topic, please make sure that you have read: (1) Working Through the New User's Tour.

In Maple , you can solve many ordinary differential equations (ODEs) and partial differential equations (PDEs). These include initial value problems (IVPs) and boundary value problems (BVPs).

Use the restart command to clear Maple's internal memory and get started with this page of the tour.

> restart;

Maple has two packages, DEtools and PDEtools, that help with manipulating differential equations. Before using this worksheet, execute the following commands to access the functions in these packages by their short names.

> with(DEtools);

[DEnormal, DEplot, DEplot3d, DEplot_polygon, DFacto...
[DEnormal, DEplot, DEplot3d, DEplot_polygon, DFacto...
[DEnormal, DEplot, DEplot3d, DEplot_polygon, DFacto...
[DEnormal, DEplot, DEplot3d, DEplot_polygon, DFacto...
[DEnormal, DEplot, DEplot3d, DEplot_polygon, DFacto...
[DEnormal, DEplot, DEplot3d, DEplot_polygon, DFacto...
[DEnormal, DEplot, DEplot3d, DEplot_polygon, DFacto...
[DEnormal, DEplot, DEplot3d, DEplot_polygon, DFacto...
[DEnormal, DEplot, DEplot3d, DEplot_polygon, DFacto...
[DEnormal, DEplot, DEplot3d, DEplot_polygon, DFacto...
[DEnormal, DEplot, DEplot3d, DEplot_polygon, DFacto...
[DEnormal, DEplot, DEplot3d, DEplot_polygon, DFacto...
[DEnormal, DEplot, DEplot3d, DEplot_polygon, DFacto...
[DEnormal, DEplot, DEplot3d, DEplot_polygon, DFacto...
[DEnormal, DEplot, DEplot3d, DEplot_polygon, DFacto...

> with(PDEtools);

[PDEplot, build, casesplit, charstrip, dchange, dco...
[PDEplot, build, casesplit, charstrip, dchange, dco...

Ordinary Differential Equations

The dsolve command is the principal tool in Maple for solving ordinary differential equations. The D operator and the diff command are also used. Maple also understands many specialized mathematical functions, such as the Dirac delta function illustrated in the second example. Maple can also solve systems of ODEs, as shown in the third example.

Solving a Second-order Differential Equation

The diff command computes the partial derivative of an expression with respect to a given variable. By contrast, the D operator computes derivatives of functions.

Consider a second-order ODE, diff(y(x),x,x)+5*diff(y(x),x)+6*y(x) = 0 .

You would enter this in Maple as follows:

> diff_eq1 := D(D(y))(x) + 5*D(y)(x) + 6*y(x) = 0;

diff_eq1 := `@@`(D,2)(y)(x)+5*D(y)(x)+6*y(x) = 0

The D operator in the previous expression finds the derivative of the function y .

Define the initial conditions to be y(0) = 0 and D(y)(0) = 1 , as follows.

> init_con := y(0)=0, D(y)(0)=1;

init_con := y(0) = 0, D(y)(0) = 1

Use the dsolve command to solve the equation.

> dsolve( {diff_eq1, init_con} , {y(x)} );

y(x) = exp(-2*x)-exp(-3*x)

Solving a Fourth-order Differential Equation

As another example, define a fourth-order differential equation, 10^6*diff(y(t),t,t,t,t) = Dirac( t -2) - Dirac( t -4).

Maple allows you to use many specialized mathematical functions, including the Dirac delta function.

> diff_eq2 := 10^6*(D@@4)(y)(t) = Dirac(t-2) - Dirac(t-4);

diff_eq2 := 1000000*`@@`(D,4)(y)(t) = Dirac(t-2)-Di...

In the previous input, the notation D@@4 means D is applied to the function y four times.

To continue the example, use the following Maple command to specify four boundary conditions:

y(0) = 0 , y(5) = 1 , D(y)(0) = 0 , and `@@`(D,2)(y)(5) = 1 .

> bound_con := y(0) = 0, y(5) = 1, D(y)(0) = 0, (D@@2)(y)(5) = 1;

bound_con := y(0) = 0, y(5) = 1, D(y)(0) = 0, `@@`(...

Solve the boundary value problem (BVP) and store the result in the variable solution .

> solution := dsolve( {diff_eq2, bound_con}, {y(t)} );

solution := y(t) = 1/6000000*Heaviside(t-2)*t^3-1/7...
solution := y(t) = 1/6000000*Heaviside(t-2)*t^3-1/7...
solution := y(t) = 1/6000000*Heaviside(t-2)*t^3-1/7...
solution := y(t) = 1/6000000*Heaviside(t-2)*t^3-1/7...
solution := y(t) = 1/6000000*Heaviside(t-2)*t^3-1/7...

Use the subs command to pick out the solution.

> expr := subs(solution, y(t));

expr := 1/6000000*Heaviside(t-2)*t^3-1/750000*Heavi...
expr := 1/6000000*Heaviside(t-2)*t^3-1/750000*Heavi...
expr := 1/6000000*Heaviside(t-2)*t^3-1/750000*Heavi...
expr := 1/6000000*Heaviside(t-2)*t^3-1/750000*Heavi...
expr := 1/6000000*Heaviside(t-2)*t^3-1/750000*Heavi...

Now that you have the solution, you can plot it by using the following Maple command:

> plot( expr, t=0..5, axes=BOXED,
title="Solution to a Fourth Order ODE" );

[Maple Plot]

Solving a System of ODEs

Maple can also solve systems of ODEs.

For example, solve the following system of two second-order equations:

diff(y(x),x,x) = z(x), diff(z(x),x,x) = y(x)

> sys := (D@@2)(y)(x) = z(x), (D@@2)(z)(x) = y(x);

sys := `@@`(D,2)(y)(x) = z(x), `@@`(D,2)(z)(x) = y(...

Solve the system without providing additional conditions. Maple automatically generates the appropriate constants, _C1 , _C2 , _C3 , and _C4 .

> dsolve( {sys}, {y(x), z(x)} );

{y(x) = _C1*cos(x)+_C2*sin(x)+_C3*exp(x)+_C4*exp(-x...
{y(x) = _C1*cos(x)+_C2*sin(x)+_C3*exp(x)+_C4*exp(-x...

Maple can convert a system of ODEs, like the one directly above, to a first-order system by using the convertsys command. Moreover, the dsolve command can solve even more differential equations numerically by using various methods, including Classical, Gear single-step and multiple-step extrapolation, and the Livermore Stiff ODE solver.

Partial Differential Equations

The pdsolve command can find closed-form solutions to many partial differential equations. In each solution, arbitrary functions are returned as _F1 , _F2 , and so on.

As an example, consider the PDE diff(U(x,y),x,x,y,y,y) = 0 .

> pde := D[1, 1, 2, 2, 2](U)(x, y) = 0;

pde := D[1,1,2,2,2](U)(x,y) = 0

> pdsolve(pde, U(x, y));

U(x,y) = _F5(x)+_F4(x)*y+1/2*_F3(x)*y^2+_F2(y)+_F1(...

The notation D[1](U) means the derivative of U with respect to its first variable and D[1,1,2,2,2](U) differentiates twice with respect to the first variable and three times with respect to the second variable.

Solving Non-homogeneous PDEs

Maple can also solve non-homogeneous PDEs, as follows.

> pde := D[1, 1, 2, 2, 2](U)(x, y) = sin(x*y);

pde := D[1,1,2,2,2](U)(x,y) = sin(x*y)

> pdsolve( pde, U(x, y) );

U(x,y) = _F5(x)+_F4(x)*y+1/2*_F3(x)*y^2+_F2(y)+_F1(...
U(x,y) = _F5(x)+_F4(x)*y+1/2*_F3(x)*y^2+_F2(y)+_F1(...
U(x,y) = _F5(x)+_F4(x)*y+1/2*_F3(x)*y^2+_F2(y)+_F1(...

Plotting Solution Surfaces

In Maple, you can also plot solution surfaces for PDEs.

Consider the PDE diff(z,x)+z*diff(z,y) = 0 .

pde := D[1](z)(x, y) + z(x, y)*D[2](z)(x, y) = 0;

pde := D[1](z)(x,y)+z(x,y)*D[2](z)(x,y) = 0

To plot a solution surface you must specify the initial data; that is, a parameterized curve in three-dimensional space. You would enter this in Maple as follows.

> ini := [0, s, sech(s)], s=-5..5:

> PDEplot( pde, z(x, y), ini, numsteps=[10, 30], numchar=30,
basechar=true, method=internal,
title="A PDE Plot-Internal Method", style=hidden );

[Maple Plot]

Click here to return to the Main Menu.

© 2009 by the Rector and Visitors of the University of Virginia.

The information contained on the University of Virginia’s Department of Information Technology and Communication (ITC) website is provided as a public service with the understanding that ITC makes no representations or warranties, either expressed or implied, concerning the accuracy, completeness, reliability or suitability of the information, including warrantees of title, non-infringement of copyright or patent rights of others. These pages are expected to represent the University of Virginia community and the State of Virginia in a professional manner in accordance with the University of Virginia’s Computing Policies.