(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);
> with(PDEtools);
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,
.
You would enter this in Maple as follows:
> diff_eq1 := D(D(y))(x) + 5*D(y)(x) + 6*y(x) = 0;
The
D
operator in the previous expression finds the derivative of the
function
.
Define the initial conditions to be y(0) = 0 and
, as follows.
> init_con := y(0)=0, D(y)(0)=1;
Use the dsolve command to solve the equation.
> dsolve( {diff_eq1, init_con} , {y(x)} );
Solving a Fourth-order Differential Equation
As another example, define a fourth-order differential equation,
= 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);
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:
,
,
, and
.
> bound_con := y(0) = 0, y(5) = 1, D(y)(0) = 0, (D@@2)(y)(5) = 1;
Solve the boundary value problem (BVP) and store the result in the variable
.
> solution := dsolve( {diff_eq2, bound_con}, {y(t)} );
Use the subs command to pick out the solution.
> expr := subs(solution, y(t));
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" );
Solving a System of ODEs
Maple can also solve systems of ODEs.
For example, solve the following system of two second-order equations:
> sys := (D@@2)(y)(x) = z(x), (D@@2)(z)(x) = y(x);
Solve the system without providing additional conditions. Maple automatically generates the appropriate constants,
,
,
, and
.
> dsolve( {sys}, {y(x), z(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
,
, and so on.
As an example, consider the PDE
.
> pde := D[1, 1, 2, 2, 2](U)(x, y) = 0;
> pdsolve(pde, U(x, y));
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);
> pdsolve( pde, U(x, y) );
Plotting Solution Surfaces
In Maple, you can also plot solution surfaces for PDEs.
Consider the PDE
.
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 );