How to | Solve a Partial Differential Equation

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

Use DSolve to solve the equation and store the solution as soln. 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:

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

To use the solution as a function, say f[x,t], use /. (the short form of ReplaceAll) and [[...]] (the short form of Part):

You can then evaluate f[x,t] like any other function:

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

Use Plot3D to plot the solution:


Use DSolve with the inhomogeneous PDE with the initial condition :

Get just the solution from the nested list:

Evaluate the solution for given values of the parameters:

Now, use Plot3D to plot the solution:


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

Define a function Fsol, corresponding to the solution pdesol:

Evaluate the solution function for given values of the parameters:

Substitute values for the parameters:

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

Use Manipulate to show how the solution Fsol changes with respect to the parameters a, b, and c:


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

Plot the solution with Plot3D:

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

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

Evaluate the solution with values specified for x and t:

Plot the solution nsol2 with Plot3D:


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 fsol from evaluating for non-numeric values of the parameter:

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

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

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

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