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 {eqn1,eqn2,…} for the function u[x,y] over the rectangular domain [xmin,xmax]×[ymin,ymax] |
NDSolve[{eqn1,eqn2,…},u,{x,y}∈Ω] | find a numerical solution of {eqn1,eqn2,…} for the function u[x,y] over the domain Ω |
NDSolve[{eqn1,eqn2,…},u,{t,tmin,tmax},{x,y}∈Ω] | find a numerical solution of the time-dependent equations {eqn1,eqn2,…} for the function u[t,x,y] over the spatial domain Ω for times between tmin and tmax. |
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.
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.
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 would be 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.
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.
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 satisfied 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 .
This solution is the same as the one shown above, and both are computed using the finite element method. The automatic selection was 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.
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.
Some of the visualization commands accept the domain notation, so you can use them directly for visualizing the solution.
In some cases it is possible to see the mesh with a plot by using the option Mesh->All.
NDSolve handles equations that have an independent variable that is time-like, in the sense that the solution evolves so that variables 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.
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.
When the spatial geometry is irregular, NDSolve will automatically use finite elements.