This is documentation for Mathematica 8, which was
based on an earlier version of the Wolfram Language.
View current documentation (Version 11.1)


finds a numerical solution to the ordinary differential equations eqns for the function y with the independent variable x in the range to .
finds a numerical solution to the partial differential equations eqns.
finds numerical solutions for the functions .
  • NDSolve gives solutions for rather than for the function y itself.
  • Differential equations must be stated in terms of derivatives such as , obtained with D, not total derivatives obtained with Dt.
  • NDSolve solves a wide range of ordinary differential equations as well as many partial differential equations.
  • NDSolve can also solve many delay differential equations.
  • In ordinary differential equations the functions must depend only on the single variable x. In partial differential equations they may depend on more than one variable.
  • The differential equations must contain enough initial or boundary conditions to determine the solutions for the completely.
  • Initial and boundary conditions are typically stated in the form , , etc., but may consist of more complicated equations.
  • The , , etc. can be lists, specifying that is a function with vector or general list values.
  • Periodic boundary conditions can be specified using .
  • The point that appears in the initial or boundary conditions need not lie in the range to over which the solution is sought.
  • In delay differential equations, initial history functions are given in the form , where is in general a function of x.
  • The differential equations in NDSolve can involve complex numbers.
  • NDSolve can solve many differential-algebraic equations, in which some of the eqns are purely algebraic, or some of the variables are implicitly algebraic.
  • The can be functions of the dependent variables, and need not include all such variables.
  • The following options can be given:
AccuracyGoalAutomaticdigits of absolute accuracy sought
DependentVariablesAutomaticthe list of all dependent variables
EvaluationMonitorNoneexpression to evaluate whenever the function is evaluated
InterpolationOrderAutomaticthe continuity degree of the final output
MaxStepFraction1/10maximum fraction of range to cover in each step
MaxSteps10000maximum number of steps to take
MaxStepSizeAutomaticmaximum size of each step
MethodAutomaticmethod to use
NormFunctionAutomaticthe norm to use for error estimation
PrecisionGoalAutomaticdigits of precision sought
StartingStepSizeAutomaticinitial step size used
StepMonitorNoneexpression to evaluate when a step is taken
WorkingPrecisionMachinePrecisionprecision to use in internal computations
  • The option NormFunction->f specifies that the estimated errors for each of the should be combined using .
  • AccuracyGoal effectively specifies the absolute local error allowed at each step in finding a solution, while PrecisionGoal specifies the relative local error.
  • If solutions must be followed accurately when their values are close to zero, AccuracyGoal should be set larger, or to Infinity.
  • The setting for MaxStepFraction specifies the maximum step to be taken by NDSolve as a fraction of the range of values for each independent variable.
  • Possible explicit settings for the Method option include:
"Adams"predictor-corrector Adams method with orders 1 through 12
"BDF"implicit backward differentiation formulas with orders 1 through 5
"ExplicitRungeKutta"adaptive embedded pairs of 2(1) through 9(8) Runge-Kutta methods
"ImplicitRungeKutta"families of arbitrary-order implicit Runge-Kutta methods
interleaved Runge-Kutta methods for separable Hamiltonian systems
"MethodOfLines"method of lines for solution of PDEs
  • With Method->{"controller", Method->"submethod"} or Method->{"controller", Method->{m1, m2, ...}} possible controller methods include:
"Composition"compose a list of submethods
"DoubleStep"adapt step size by the double-step method
"EventLocator"respond to specified events
"Extrapolation"adapt order and step size using polynomial extrapolation
"FixedStep"use a constant step size
"OrthogonalProjection"project solutions to fulfill orthogonal constraints
"Projection"project solutions to fulfill general constraints
"Splitting"split equations and use different submethods
"StiffnessSwitching"switch from explicit to implicit methods if stiffness is detected
  • Methods used mainly as submethods include:
"ExplicitEuler"forward Euler method
"ExplicitMidpoint"midpoint rule method
"ExplicitModifiedMidpoint"midpoint rule method with Gragg smoothing
"LinearlyImplicitEuler"linearly implicit Euler method
"LinearlyImplicitMidpoint"linearly implicit midpoint rule method
linearly implicit Bader-smoothed midpoint rule method
"LocallyExact"numerical approximation to locally exact symbolic solution
  • The setting InterpolationOrder->All specifies that NDSolve should generate solutions that use interpolation of the same order as the underlying method used. »
Solve a first-order ordinary differential equation:
Use the solution in a plot:
Use the function and its derivative in a plot:
Find specific values:
Second-order nonlinear ordinary differential equation:
Plot the function and its first two derivatives:
System of ordinary differential equations:
This solves the heat equation in 1 dimension:
Alternative form of equation:
Solve a first-order ordinary differential equation:
Click for copyable input
Use the solution in a plot:
Click for copyable input
Use the function and its derivative in a plot:
Click for copyable input
Find specific values:
Click for copyable input
Second-order nonlinear ordinary differential equation:
Click for copyable input
Plot the function and its first two derivatives:
Click for copyable input
System of ordinary differential equations:
Click for copyable input
Click for copyable input
This solves the heat equation in 1 dimension:
Click for copyable input
Click for copyable input
Alternative form of equation:
Click for copyable input
Specify any order equation. Reduction to normal form is done automatically:
Directly differentiate the solution to make a phase-plot:
Directly specify a system of equations:
Solve for a vector-valued function:
Plot the four components of the solution:
Different equivalent ways of specifying a harmonic oscillator as a second-order equation:
As a system of first-order equations:
Using a vector variable with the dimension deduced from the initial condition:
Use matrix-valued variables to compute the fundamental matrix solution:
Compare to the exact solution:
Define a van der Pol equation:
The solution's "stiff" behavior that the default solver automatically handles:
Other methods may not be able to solve this system:
Equations can have multiple distinct solutions:
The solution is continuous, as it integrates the piecewise function once:
The solution is differentiable, whereas is continuous only:
A nonlinear multipoint boundary value problem:
Solve a delay differential with two constant delays and initial history function :
Discontinuities are propagated from at intervals equal to the delays:
Investigate stability for a linear delay differential equation:
A differential equation with an algebraic constraint:
Nonlinear advection-diffusion equation in 1 dimension:
Define a system of PDEs of mixed parabolic-hyperbolic type:
Nonlinear sine-Gordon equation in two spatial dimensions with periodic boundary conditions:
Plot the solution at the final time:
Plot the time evolution of a radial cross section of the solution:
The names of functions need not be symbols:
Use defaults to solve a celestial mechanics equation with sensitive dependence on initial conditions:
Higher accuracy and precision goals give a different result:
Increasing the goals extends the correct solution further:
Set up a very large system of equations:
Solve for all the dependent variables, but save only the solution for :
Total number of evaluations:
The distance between successive evaluations; negative distance means a rejected step:
Use InterpolationOrder->All to get interpolation the same order as the method:
This is more time consuming than the default interpolation order used:
It is much better in between steps:
Features with small relative size in the integration interval can be missed:
Use MaxStepFraction to ensure features are not missed, independent of interval size:
Integration stops short of the requested interval:
More steps are needed to resolve the solution:
Plot the solution in the phase plane:
The default step control may miss a suddenly varying feature:
A smaller MaxStepSize setting ensures that NDSolve catches the feature:
Attempting to compute the number of positive integers less than misses several events:
Setting a small enough MaxStepSize ensures that none of the events are missed:
Differences between values of x at successive steps with the default solution method:
With an explicit Runge-Kutta method the step size is changed more often:
Difference order of 8:
With a difference order of 3, the steps are much smaller:
Extrapolation tends to take very large steps:
Plot the actual solution error when using different error estimation norms:
A plot of the best solution:
The solution cannot be completed because the square root function is not sufficiently smooth:
When the solving is delayed the equation is treated as a DAE instead:
For a very large interval, a short-lived feature near the start may be missed:
Setting a sufficiently small step size to start with ensures that the input is not missed:
Plot the solution at each point where a step is taken in the solution process:
Total number of steps involved in finding the solution:
Differences between values of x at successive steps:
Error in the solution to a harmonic oscillator over 100 periods:
When the working precision is increased, the local tolerances are correspondingly increased:
With a large working precision, sometimes the method is quite effective:
The solution depends strongly on initial conditions:
The Lotka-Volterra predator-prey equations []:
Phase plane plot:
The Lorenz equations []:
Look at the appearance of the blue sky catastrophe orbit:
Simple model for soil temperature at depth x with periodic heating at the surface:
Simple wave evolution with periodic boundary conditions:
Plot the solution:
Wolfram's nonlinear wave equation []:
This solves a dimensional version of the equation:
Reduced 3-body problem :
A formulation suitable for a number of different initial conditions:
A soliton profile perturbed by a periodic potential:
View solutions of the Mackey-Glass delay differential equation:
Symbolic versus numerical differential equation solving:
The defining equation for JacobiSN:
Numerically compute values of an integral at different points in an interval:
For functions of the independent variable, NDSolve effectively gives an indefinite integral:
Finding an event is related to finding a root of a function of the solution:
Event location finds the root accurately and efficiently:
This gives as a function of for a differential equation:
Find a root of :
Solve the equivalent boundary value problem:
The error tends to grow as one goes further from the initial conditions:
Find the difference between numerical and exact solutions:
Error for a nonlinear equation:
For high-order methods the default interpolation may have large errors between steps:
Interpolation with the order corresponding to the method reduces the error between steps:
Here is a system of differential-algebraic equations:
Find the solution with :
NDSolve cannot find the solution with because the solution does not exist:
NDSolve is limited to index 1, but the solution with has index 2:
Define a nonlinear PDE:
The spatial discretization is based on the initial value, which varies less than the final value:
By increasing the minimal number of spatial grid points, you can accurately compute the final value:
The plot demonstrates the onset of a spatially more complex solution:
Define a heat equation with an initial value that is a step function:
Discontinuities in the initial value may result in too many spatial grid points:
Setting the number of spatial grid points smaller results in essentially as good a solution:
Define a Laplace equation with initial values:
The solver only works for equations well posed as initial value (Cauchy) problems:
The ill-posedness shows up as numerical instability:
This finds a trivial solution of a boundary value problem:
You can find other solutions by giving starting conditions for the solution search:
New in 2 | Last modified in 7