How to | Use Derivatives for Setting Up Differential Equations

*Mathematica*'s functions for solving differential equations can be applied to many different classes of differential equations, including ordinary differential equations (ODEs), partial differential equations (PDEs), differential-algebraic equations (DAEs), and boundary value problems (BVPs). Using derivatives to set up these equations for solving in

*Mathematica* is essential.

For an ODE, you can express the derivative of a function

of

with respect to

in several ways.

The most common way is to use

D:

Out[8]= | |

You can specify the order of differentiation, which in this case is 1:

Out[4]= | |

Using

also gives the derivative

:

Out[9]= | |

Using

is shorthand for

Derivative:

Out[10]= | |

FullForm shows that

and

Derivative are equivalent:

Out[2]//FullForm= |

| |

Use

D to set up the ODE

for solving and then store the equation as

:

Out[6]= | |

Use

TraditionalForm to see the ODE as it would appear in a mathematics textbook or journal article:

Out[7]//TraditionalForm= |

| |

Once the ODE is set up, use

DSolve to solve it symbolically:

Out[8]= | |

The solution

is represented as a rule in a nested list. For information on getting this solution out of the list and using it, see

How to: Use Rule Solutions.

Most of the time, ODEs are accompanied by boundary and initial conditions. Thus, evaluation of derivatives of functions for specific values of variables needs to be used frequently. This can be done in several ways. Here,

is used as an example.

Use

(shorthand for

ReplaceAll) to substitute

for

.

*Mathematica* first evaluates

D, then performs the replacement:

Out[12]= | |

Or, just evaluate

directly by using

:

Out[13]= | |

Also equivalent is

Derivative:

Out[14]= | |

As another example, set up the ODE

,

,

, for solving:

Out[1]= | |

Use

DSolve to obtain the symbolic solution:

Out[3]= | |

Of course, you can solve directly without setting up:

Out[4]= | |

Alternatively, you can express the ODE as a PDE and solve it for

instead of

:

Out[17]= | |

Out[19]= | |

Here, the ODE

,

is set up:

Out[4]= | |

Use

DSolve to obtain the symbolic solution:

Out[5]= | |

Instead of using

DSolve, you can use

NDSolve to obtain a numerical solution that corresponds to specific values of

that are involved in one of the coefficients of the ODE.

The following example gives the solution when

.

NDSolve gives results in terms of

InterpolatingFunction objects:

Out[6]= | |

The following function

gives numerical solutions for each value of

:

Plot the results at

and

.

Evaluate is used so that

evaluates properly in

Plot:

Out[34]= | |

*Mathematica* can also set up and solve PDEs.

The function

is used here to show the different ways partial derivatives can be expressed in

*Mathematica*.

The most common way to get a partial derivative is to use

D:

Out[6]= | |

Out[7]= | |

Out[8]= | |

You can accomplish the same thing by using slightly different syntax for

D:

Out[11]= | |

Out[12]= | |

Out[13]= | |

Alternatively, use

Derivative:

Out[12]= | |

Out[13]= | |

Out[14]= | |

FullForm shows that these methods are equivalent:

Out[15]//FullForm= |

| |

Next, consider several variations of a PDE.

Set up the PDE

for solving:

Out[17]= | |

Use

DSolve to find a symbolic solution to the PDE. The result is given in terms of an arbitrary function

C:

Out[19]= | |

The solution can also be obtained in terms of a pure function.

Function represents a pure function in

*Mathematica*:

Out[18]= | |

Use

DSolve to obtain a symbolic solution to the PDE

,

:

Out[10]= | |

Use

NDSolve to obtain a numeric solution to the PDE

,

,

. The solution is stored as

for later use:

Out[14]= | |

Use

Plot3D to visualize the result of

NDSolve:

Out[19]= | |

In the cases above, the derivatives and partial derivatives are given in terms of variables. Here, they are evaluated numerically.

Both of the following ways can be used to express the values of partial differentials, such as

:

Out[29]= | |

Out[28]= | |

In addition to ODEs and PDEs,

*Mathematica* can also solve DAEs (differential-algebraic equations).

As an example, consider the DAE

,

satisfying

:

Use

DSolve to obtain a symbolic result for the DAE:

Out[32]= | |

To see the solution at

and

, use

to substitute these values into the solution:

Out[33]= | |

Out[34]= | |

You can also produce the same plot by first substituting

and

to

, and then using

NDSolve:

Out[35]= | |

As before, visualize the solution with

Plot:

Out[36]= | |