MATHEMATICA HOW TO

# How to | Solve a Partial Differential Equation

Mathematica's differential equation solving functions can be applied to many different classes of differential equations, automatically selecting the appropriate algorithms without the need for preprocessing by the user. One such class is partial differential equations (PDEs).

Using D to take derivatives, this sets up the transport equation, , and stores it as :

 Out[14]=

Use DSolve to solve the equation and store the solution as . The first argument to DSolve is an equation, the second argument is the function to solve for, and the third argument is a list of the independent variables:

 Out[15]=

The answer is given as a rule and C[1] is an arbitrary function.

To use the solution as a function, say , use (the short form of ReplaceAll) and (the short form of Part):

 Out[16]=

You can then evaluate like any other function:

 Out[17]=

You can also add an initial condition like by making the first argument to DSolve a list. The solution is stored as :

 Out[18]=

Use Plot3D to plot the solution:

 Out[20]=

Use DSolve with the inhomogeneous PDE with the initial condition :

 Out[1]=

Get just the solution from the nested list:

 Out[2]=

Evaluate the solution for given values of the parameters:

 Out[3]=

Now, use Plot3D to plot the solution:

 Out[5]=

You can also work with PDEs that have non-numeric coefficients.

Use DSolve to solve a inhomogeneous PDE, for example, with the initial condition . The solution is stored as :

 Out[6]=

Define a function , corresponding to the solution :

 Out[7]=

Evaluate the solution function for given values of the parameters:

 Out[8]=

Substitute values for the parameters:

 Out[9]=

Plot the solution for a given set of values of parameters:

 Out[10]=

Use Manipulate to show how the solution changes with respect to the parameters , , and :

 Out[11]= Play Animation ▪

The examples so far use DSolve to obtain symbolic solutions to PDEs. When a given PDE does not contain parameters, NDSolve can be used to obtain numerical solutions. The results of NDSolve are given as InterpolatingFunction objects.

Here, the solution produced by NDSolve is stored as :

 Out[12]=

Plot the solution with Plot3D:

 Out[15]=

The InterpolatingFunction object can be evaluated, plotted, and used in other operations.

Get just the InterpolatingFunction solution from and assign it to the new symbol :

 Out[13]=

Evaluate the solution with values specified for and :

 Out[14]=

Plot the solution with Plot3D:

 Out[24]=

When the PDE contains parameters, NDSolve can be used for each specific value of the parameters. In addition, you can set up a function that uses NDSolve and takes parameter values.

Use NumericQ to prevent the function from evaluating for non-numeric values of the parameter:

Find the solution corresponding to a specific value of the parameter, 5 in this case:

 Out[9]=

Plot the solution using Plot3D. Evaluate is necessary so that the evaluations occur in the correct order:

 Out[10]=

NDSolve can also be used with other Mathematica functions, like Manipulate.

Solve the PDE corresponding to a given value of the parameter , and then plot the resulting solution:

 Out[11]= Play Animation ▪