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

In[14]:= |

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:

In[15]:= |

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

In[16]:= |

Out[16]= |

You can then evaluate like any other function:

In[17]:= |

Out[17]= |

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

In[18]:= |

Out[18]= |

Use Plot3D to plot the solution:

In[20]:= |

Out[20]= |

Use DSolve with the inhomogeneous PDE with the initial condition :

In[1]:= |

Out[1]= |

Get just the solution from the nested list:

In[2]:= |

Out[2]= |

Evaluate the solution for given values of the parameters:

In[3]:= |

Out[3]= |

Now, use Plot3D to plot the solution:

In[5]:= |

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 :

In[6]:= |

Out[6]= |

Define a function , corresponding to the solution :

In[7]:= |

Out[7]= |

Evaluate the solution function for given values of the parameters:

In[8]:= |

Out[8]= |

Substitute values for the parameters:

In[9]:= |

Out[9]= |

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

In[10]:= |

Out[10]= |

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

In[11]:= |

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 :

In[12]:= |

Out[12]= |

Plot the solution with Plot3D:

In[15]:= |

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 :

In[13]:= |

Out[13]= |

Evaluate the solution with values specified for and :

In[14]:= |

Out[14]= |

Plot the solution with Plot3D:

In[24]:= |

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:

In[7]:= |

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

In[9]:= |

Out[9]= |

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

In[10]:= |

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:

In[11]:= |

Out[11]= | Play Animation ▪ |