# Numerical Solution of Differential Equations

The function NDSolve discussed in "Numerical Differential Equations" allows you to find numerical solutions to differential equations. NDSolve handles both single differential equations, and sets of simultaneous differential equations. It can handle a wide range of *ordinary differential equations* as well as some *partial differential equations*. In a system of ordinary differential equations there can be any number of unknown functions , but all of these functions must depend on a single "independent variable" , which is the same for each function. Partial differential equations involve two or more independent variables. NDSolve can also handle *differential‐algebraic equations* that mix differential equations with algebraic ones.

NDSolve[{eqn_{1},eqn_{2},…},y,{x,x_{min},x_{max}}] | |

find a numerical solution for the function with in the range to | |

NDSolve[{eqn_{1},eqn_{2},…},{y_{1},y_{2},…},{x,x_{min},x_{max}}] | |

find numerical solutions for several functions |

Finding numerical solutions to ordinary differential equations.

NDSolve represents solutions for the functions as InterpolatingFunction objects. The InterpolatingFunction objects provide approximations to the over the range of values to for the independent variable .

NDSolve finds solutions iteratively. It starts at a particular value of , then takes a sequence of steps, trying eventually to cover the whole range to .

In order to get started, NDSolve has to be given appropriate initial or boundary conditions for the and their derivatives. These conditions specify values for , and perhaps derivatives , at particular points . In general, at least for ordinary differential equations, the conditions you give can be at any : NDSolve will automatically cover the range to .

In[1]:= |

Out[1]= |

In[2]:= |

Out[2]= |

In[3]:= |

Out[3]= |

When you use NDSolve, the initial or boundary conditions you give must be sufficient to determine the solutions for the completely. When you use DSolve to find symbolic solutions to differential equations, you can get away with specifying fewer initial conditions. The reason is that DSolve automatically inserts arbitrary constants C[i] to represent degrees of freedom associated with initial conditions that you have not specified explicitly. Since NDSolve must give a numerical solution, it cannot represent these kinds of additional degrees of freedom. As a result, you must explicitly give all the initial or boundary conditions that are needed to determine the solution.

In a typical case, if you have differential equations with up to derivatives, then you need to give initial conditions for up to derivatives, or give boundary conditions at points.

In[4]:= |

Out[4]= |

In[5]:= |

Out[5]= |

In[6]:= |

Out[6]= |

In[7]:= |

Out[7]= |

In most cases, all the initial conditions you give must involve the same value of , say . As a result, you can avoid giving both and explicitly. If you specify your range of as , then the Wolfram Language will automatically generate a solution over the range to .

In[8]:= |

Out[8]= |

You can give initial conditions as equations of any kind. In some cases, these equations may have multiple solutions. In such cases, NDSolve will correspondingly generate multiple solutions.

In[9]:= |

Out[9]= |

In[10]:= |

Out[10]= |

You can use NDSolve to solve systems of coupled differential equations.

In[11]:= |

Out[11]= |

In[12]:= |

Out[12]= |

In[13]:= |

Out[13]= |

Unknown functions in differential equations do not necessarily have to be represented by single symbols. If you have a large number of unknown functions, you will often find it more convenient, for example, to give the functions names like .

In[14]:= |

Out[14]= |

In[15]:= |

Out[15]= |

In[16]:= |

Out[16]= |

NDSolve can handle functions whose values are lists or arrays. If you give initial conditions like , then NDSolve will assume that is a function whose values are lists of length .

In[17]:= |

Out[17]= |

In[18]:= |

Out[18]= |

option name | default value | |

MaxSteps | Automatic | maximum number of steps in to take |

StartingStepSize | Automatic | starting size of step in to use |

MaxStepSize | Automatic | maximum size of step in to use |

NormFunction | Automatic | the norm to use for error estimation |

Special options for NDSolve.

NDSolve has many methods for solving equations, but essentially all of them at some level work by taking a sequence of steps in the independent variable , and using an adaptive procedure to determine the size of these steps. In general, if the solution appears to be varying rapidly in a particular region, then NDSolve will reduce the step size or change the method so as to be able to track the solution better.

In[19]:= |

Out[19]= |

In[20]:= |

Out[20]= |

Through its adaptive procedure, NDSolve is able to solve "stiff" differential equations in which there are several components which vary with at very different rates.

In[21]:= |

Out[21]= |

In[22]:= |

Out[22]= |

NDSolve follows the general procedure of reducing step size until it tracks solutions accurately. There is a problem, however, when the true solution has a singularity. In this case, NDSolve might go on reducing the step size forever, and never terminate. To avoid this problem, the option MaxSteps specifies the maximum number of steps that NDSolve will ever take in attempting to find a solution. For ordinary differential equations the default setting is MaxSteps->10000.

In[23]:= |

Out[23]= |

In[24]:= |

Out[24]= |

The default setting for MaxSteps should be sufficient for most equations with smooth solutions. When solutions have a complicated structure, however, you may occasionally have to choose larger settings for MaxSteps. With the setting MaxSteps->Infinity there is no upper limit on the number of steps used.

In[25]:= |

Out[25]= |

In[26]:= |

Out[26]= |

When NDSolve solves a particular set of differential equations, it always tries to choose a step size appropriate for those equations. In some cases, the very first step that NDSolve makes may be too large, and it may miss an important feature in the solution. To avoid this problem, you can explicitly set the option StartingStepSize to specify the size to use for the first step.

The equations you give to NDSolve do not necessarily all have to involve derivatives; they can also just be algebraic. You can use NDSolve to solve many such *differential‐algebraic equations*.

In[27]:= |

Out[27]= |

In[28]:= |

Out[28]= |

NDSolve[{eqn_{1},eqn_{2},…},u,{t,t_{min},t_{max}},{x,x_{min},x_{max}},…] | |

solve a system of partial differential equations for | |

NDSolve[{eqn_{1},eqn_{2},…},{u_{1},u_{2},…},{t,t_{min},t_{max}},{x,x_{min},x_{max}},…] | |

solve a system of partial differential equations for several functions |

Finding numerical solutions to partial differential equations.

In[29]:= |

Out[29]= |

In[30]:= |

Out[30]= |

In[31]:= |

Out[31]= |

In[32]:= |

Out[32]= |

In[33]:= |

Out[33]= |

In[34]:= |

Out[34]= |

In[35]:= |

Out[35]= |

In[36]:= |

Out[36]= |