# 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:

In[1]:= |

Out[1]= |

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

In[2]:= |

Out[2]= |

Using also gives the derivative :

In[3]:= |

Out[3]= |

Using is shorthand for Derivative:

In[4]:= |

Out[4]= |

FullForm shows that and Derivative are equivalent:

In[5]:= |

Out[5]//FullForm= | |

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

In[1]:= |

Out[1]= |

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

In[2]:= |

Out[2]//TraditionalForm= | |

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

In[3]:= |

Out[3]= |

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

In[4]:= |

Out[4]= |

Or, just evaluate directly by using :

In[5]:= |

Out[5]= |

Also equivalent is Derivative:

In[6]:= |

Out[6]= |

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

In[7]:= |

Out[7]= |

Use DSolve to obtain the symbolic solution:

In[8]:= |

Out[8]= |

Of course, you can solve directly without setting up:

In[9]:= |

Out[9]= |

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

In[10]:= |

Out[10]= |

In[11]:= |

Out[11]= |

In[12]:= |

Out[12]= |

Use DSolve to obtain the symbolic solution:

In[13]:= |

Out[13]= |

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:

In[14]:= |

Out[14]= |

The following function gives numerical solutions for each value of :

In[15]:= |

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

In[16]:= |

Out[16]= |

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:

In[1]:= |

Out[1]= |

In[2]:= |

Out[2]= |

In[3]:= |

Out[3]= |

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

In[4]:= |

Out[4]= |

In[5]:= |

Out[5]= |

In[6]:= |

Out[6]= |

Alternatively, use Derivative:

In[7]:= |

Out[7]= |

In[8]:= |

Out[8]= |

In[9]:= |

Out[9]= |

FullForm shows that these methods are equivalent:

In[10]:= |

Out[10]//FullForm= | |

Next, consider several variations of a PDE.

In[11]:= |

Out[11]= |

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

In[12]:= |

Out[12]= |

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

In[13]:= |

Out[13]= |

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

In[14]:= |

Out[14]= |

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

In[15]:= |

Out[15]= |

Use Plot3D to visualize the result of NDSolve:

In[16]:= |

Out[16]= |

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[1]:= |

Out[1]= |

In[2]:= |

Out[2]= |

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

As an example, consider the DAE , satisfying :

In[1]:= |

Use DSolve to obtain a symbolic result for the DAE:

In[2]:= |

Out[2]= |

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

In[3]:= |

Out[3]= |

In[4]:= |

Out[4]= |

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

In[5]:= |

Out[5]= |

As before, visualize the solution with Plot:

In[6]:= |

Out[6]= |