This is documentation for Mathematica 3, which was
based on an earlier version of the Wolfram Language.
View current documentation (Version 11.2)
 Documentation / Mathematica / The Mathematica Book / Practical Introduction / Numerical Mathematics  /

1.6.4 Numerical Differential Equations

Numerical solution of ordinary differential equations.

  • This generates a numerical solution to the equation with . The result is given in terms of an InterpolatingFunction

  • In[1]:= NDSolve[{y'[x] == y[x], y[0] == 1}, y, {x, 0, 2}]


  • Here is the value of

  • In[2]:= y[1.5] /. %


    With an algebraic equation such as , each solution for is simply a single number. For a differential equation, however, the solution is a function, rather than a single number. For example, in the equation , you want to get an approximation to the function as the independent variable varies over some range.
    Mathematica represents numerical approximations to functions as InterpolatingFunction objects. These objects are functions which, when applied to a particular , return the approximate value of at that point. The InterpolatingFunction effectively stores a table of values for , then interpolates this table to find an approximation to at the particular

    you request.

    Using results from NDSolve.

  • This solves a system of two coupled differential equations.
  • In[3]:= NDSolve[ {y'[x] == z[x], z'[x] == -y[x], y[0] == 0,
    z[0] == 1}, {y, z}, {x, 0, Pi} ]


  • Here is the value of z[2] found from the solution.
  • In[4]:= z[2] /. %


  • Here is a plot of the solution for z[x] found on line 3. Plot is discussed in Section 1.9.1.
  • In[5]:= Plot[Evaluate[z[x] /. %3], {x, 0, Pi}]