THIS IS DOCUMENTATION FOR AN OBSOLETE PRODUCT.
SEE THE DOCUMENTATION CENTER FOR THE LATEST INFORMATION.

# NDSolve

 NDSolve[eqns, y, {x, xmin, xmax}]finds a numerical solution to the ordinary differential equations eqns for the function y with the independent variable x in the range xmin to xmax. NDSolve[eqns, y, {x, xmin, xmax}, {t, tmin, tmax}]finds a numerical solution to the partial differential equations eqns. NDSolve[eqns, {y1, y2, ...}, {x, xmin, xmax}]finds numerical solutions for the functions yi.
• NDSolve[eqns, y[x], {x, xmin, xmax}] gives solutions for y[x] rather than for the function y itself.
• Differential equations must be stated in terms of derivatives such as y'[x], 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 yi 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 yi completely.
• Initial and boundary conditions are typically stated in the form y[x0]c0, y'[x0]dc0, etc., but may consist of more complicated equations.
• The c0, dc0, etc. can be lists, specifying that y[x] is a function with vector or general list values.
• Periodic boundary conditions can be specified using y[x0]y[x1].
• The point x0 that appears in the initial or boundary conditions need not lie in the range xmin to xmax over which the solution is sought.
• In delay differential equations, initial history functions are given in the form y[x/;x<x0]c0, where c0 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 yi can be functions of the dependent variables, and need not include all such variables.
• The following options can be given:
 AccuracyGoal Automatic digits of absolute accuracy sought DependentVariables Automatic the list of all dependent variables EvaluationMonitor None expression to evaluate whenever the function is evaluated InterpolationOrder Automatic the continuity degree of the final output MaxStepFraction 1/10 maximum fraction of range to cover in each step MaxSteps 10000 maximum number of steps to take MaxStepSize Automatic maximum size of each step Method Automatic method to use NormFunction Automatic the norm to use for error estimation PrecisionGoal Automatic digits of precision sought StartingStepSize Automatic initial step size used StepMonitor None expression to evaluate when a step is taken WorkingPrecision MachinePrecision precision to use in internal computations
• The option NormFunction->f specifies that the estimated errors for each of the yi should be combined using f[{e1, e2, ...}].
• 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.
• With , NDSolve attempts to determine the dependent variables by analyzing the equations given.
• 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 "SymplecticPartitionedRungeKutta" interleaved Runge-Kutta methods for separable Hamiltonian systems
• 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 "LinearlyImplicitModifiedMidpoint" linearly implicit Bader-smoothed midpoint rule method "LocallyExact" numerical approximation to locally exact symbolic solution
• The setting 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:
 Out[1]=
Use the solution in a plot:
 Out[2]=
Use the function and its derivative in a plot:
 Out[3]=
Find specific values:
 Out[4]=

Second-order nonlinear ordinary differential equation:
 Out[1]=
Plot the function and its first two derivatives:
 Out[2]=

System of ordinary differential equations:
 Out[1]=
 Out[2]=

This solves the heat equation in 1 dimension:
 Out[1]=
 Out[2]=
Alternative form of equation:
 Out[3]=
 Scope   (15)
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 y[x] is continuous, as it integrates the piecewise function once:
The solution y[x] is differentiable, whereas y'[x] 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:
 Options   (21)
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 x1.
Total number of evaluations:
The distance between successive evaluations; negative distance means a rejected step:
Use 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:
Attempt to compute the number of positive integers less than 5 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 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 "Extrapolation" method is quite effective:
 Applications   (12)
The solution depends strongly on initial conditions:
Phase plane plot:
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:
This solves a 2+1 dimensional version of the equation:
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: