How to | Use Derivatives for Setting Up Differential Equations

The Wolfram Language'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 the Wolfram Language 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:

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

Using ' also gives the derivative f'[t]:

Using ' is shorthand for Derivative:

FullForm shows that ' and Derivative are equivalent:

    

Use D to set up the ODE for solving and then store the equation as ode:

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

Once the ODE is set up, use DSolve to solve it symbolically:

The solution f[t] 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 . The Wolfram Language first evaluates D, then performs the replacement:

Or, just evaluate directly by using ':

Also equivalent is Derivative:

As another example, set up the ODE , , for solving:

Use DSolve to obtain the symbolic solution:

Of course, you can solve directly without setting up:

Alternatively, you can express the ODE as a PDE and solve it for f[x,t] instead of f[t]:

Here, the ODE , is set up:

Use DSolve to obtain the symbolic solution:

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:

The following function F gives numerical solutions for each value of :

Plot the results at and . Evaluate is used so that F evaluates properly in Plot:

For more information, see How to: Plot the Results of NDSolve.

    

The Wolfram Language can also set up and solve PDEs.

The function is used here to show the different ways partial derivatives can be expressed in the Wolfram Language.

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

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

Alternatively, use Derivative:

FullForm shows that these methods are equivalent:

Next, consider several variations of a PDE.

Set up the PDE for solving:

Use DSolve to find a symbolic solution to the PDE. The result is given in terms of an arbitrary function C[1]:

The solution can also be obtained in terms of a pure function. Function represents a pure function in the Wolfram Language:

Use DSolve to obtain a symbolic solution to the PDE , :

Use NDSolve to obtain a numeric solution to the PDE , , . The solution is stored as sol for later use:

Use Plot3D to visualize the result of NDSolve:

    

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 :

    

In addition to ODEs and PDEs, the Wolfram System can also solve DAEs (differential-algebraic equations).

As an example, consider the DAE , satisfying :

Use DSolve to obtain a symbolic result for the DAE:

To see the solution at and , use /. to substitute these values into the solution:

Now plot the solution:

You can also produce the same plot by first substituting and to eqns, and then using NDSolve:

As before, visualize the solution with Plot: