Numerical Solution of Partial Differential Equations

The Wolfram Language function NDSolve has extensive capability for solving partial differential equations (PDEs). A unique feature of NDSolve is that given PDEs and the solution domain in symbolic form, NDSolve automatically chooses numerical methods that appear best suited to the problem structure. Commonly, the automatic algorithm selection works quite well, but it is useful to have an understanding of the methods used, both to better understand the solutions provided and to use method options to get better solutions or improve efficiency.

NDSolve[{eqn1,eqn2,},u,{x,xmin,xmax},{y,ymin,ymax}]find a numerical solution of for the function over the rectangular domain
NDSolve[{eqn1,eqn2,},u,{x,y}Ω]find a numerical solution of for the function over the domain Ω
NDSolve[{eqn1,eqn2,},u,{t,tmin,tmax},{x,y}Ω]find a numerical solution of the time-dependent equations for the function over the spatial domain Ω for times between and .

Finding numerical solutions to partial differential equations with NDSolve.

NDSolve uses finite element and finite difference methods for discretizing and solving PDEs. The numerical method of lines is used for time-dependent equations with either finite element or finite difference spatial discretizations and details of this are described in the tutorial "The Numerical Method of Lines". Finite element methods are more general and are described extensively in their own tutorials.

The following examples give a brief introduction to how equations may be entered and methods are automatically chosen.

Load a package useful for examining solutions.
In[1]:=
Click for copyable input
Solve a Poisson equation in two variables on a rectangular region with zero boundary conditions.
In[2]:=
Click for copyable input
Out[2]=
In[3]:=
Click for copyable input
Out[3]=

The input above uses notation with derivatives given explicitly. For some problems it is more expressive and correct to use an operator form. By default, the common operators Grad, Div, Curl, and Laplacian evaluate automatically, but for expressing PDEs it is typically better not to have these evaluate. It is possible to maintain the operator form using Inactive. In general, Inactive[f] represents an inactive form of f that does not evaluate. Inactive forms can be activated using Activate, but commands like NDSolve can also work with the inactive forms directly.

Evaluated and Inactive form of a differential operator.
In[4]:=
Click for copyable input
Out[4]=
In[5]:=
Click for copyable input
Out[5]=

Note that the inactive form has retained meaning from the operator form that might be lost with the explicit evaluation, for example, if were discontinuous, the derivative expressions are indeterminate whereas the operator expression can be well defined if has discontinuities corresponding to those of .

A convenient way to get inactive operators is to use Inactivate with the operators you want inactivated given in the pattern in the second argument.

Using Inactivate.
In[6]:=
Click for copyable input
Out[6]=

Perhaps the most convenient and certainly the most readable way to enter equations is to just use the typeset forms. These can be obtained by copying and pasting the output of inactive forms or by using the escape sequences given in the reference pages for each of the operators.

Typeset form for the Laplacian.
In[7]:=
Click for copyable input
Out[7]=
In[8]:=
Click for copyable input
Out[8]=

In the example above, the zero boundary conditions were given as explicit equations. An alternative is to use DirichletCondition[eqn,pred], which specifies that eqn should be satisified everywhere on the boundary of the domain where pred is True. Generalized Neumann boundary conditions may be specified using NeumannValue; since this is specific to the finite element method, the description of NeumannValue will be found in the finite element method tutorials.

Typically, the spatial variables are restricted to some domain and NDSolve recognizes the notation .

Solving a nicely typeset form of the Poisson equation.
In[9]:=
Click for copyable input
In[10]:=
Click for copyable input
Out[10]=

This solution is the same as the one shown above and both are computed using the finite element method. The automatic selection has done this for this example because both and have boundary conditions; the method of lines requires that there be an initial value problem for one of the independent variables.

The finite element method uses a mesh to compute the solution. You can see the mesh by extracting it from the solution.

Get the mesh from the solution and show its wire frame.
In[11]:=
Click for copyable input
Out[11]=
In[12]:=
Click for copyable input
Out[12]=

The finite element method is good at handling nonrectangular geometries as well. All that needs to be done to solve the problem over a different domain is to define that domain.

Solve the Poisson equation over the unit disk.
In[13]:=
Click for copyable input
In[14]:=
Click for copyable input
Out[14]=

Some of the visualization commands accept the domain notation, so you can use them directly for visualizing the solution.

Show the solution.
In[15]:=
Click for copyable input
Out[15]=
Show the mesh used to find the solution.
In[16]:=
Click for copyable input
Out[16]=

In some cases it is possible to see the mesh with a plot by using the option Mesh->All.

Show the plot of the solution surface along with the mesh.
In[17]:=
Click for copyable input
Out[17]=

NDSolve handles equations that have an independent variable that is time-like in the sense that the solution evolves in that variable from specified initial conditions are solved using the numerical method of lines with either a finite difference or finite element spatial discretization.

Consider as an example the problem of finding out how long it takes to get the center of a plate to a prescribed temperature from when steady heat is applied to the outside. This is modeled by the heat equation.

Solve the plate heating problem for a rectangular plate.
In[18]:=
Click for copyable input
Out[18]=
Plot the solution at the final time.
In[19]:=
Click for copyable input
Out[19]=

When the region is rectangular NDSolve uses finite differences by default; it is possible to specify the type and even specific details for the spatial discretization using Method options. The tutorials about method of lines and finite element methods give detailed information about the options and many examples using them.

Solve the plate heating problem for a rectangular plate using finite elements.
In[20]:=
Click for copyable input
Out[20]=

When the spatial geometry is irregular, NDSolve will automatically use finite elements.

Solve for a circular plate.
In[21]:=
Click for copyable input
In[22]:=
Click for copyable input
Out[22]=
Plot the solution for the circular plate at the final time.
In[23]:=
Click for copyable input
Out[23]=