Introduction to Numerical Differential Equations

Numerical solution of differential equations.

This generates a numerical solution to the equation y'(x)==y(x) with 0<x<2. The result is given in terms of an (RefLink[InterpolatingFunction, paclet:ref/InterpolatingFunction]):

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

Here is the value of y(1.5):

y[1.5]/.%

With an algebraic equation such as (x^2)+3x+1==0, each solution for x 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 y'(x)==y(x), you want to get an approximation to the function y(x) as the independent variable x varies over some range.

The Wolfram Language represents numerical approximations to functions as (RefLink[InterpolatingFunction, paclet:ref/InterpolatingFunction]) objects. These objects are functions which, when applied to a particular x, return the approximate value of y(x) at that point. The (RefLink[InterpolatingFunction, paclet:ref/InterpolatingFunction]) effectively stores a table of values for y((Subscript[x, i])), then interpolates this table to find an approximation to y(x) at the particular x you request.

Using results from (RefLink[NDSolve, paclet:ref/NDSolve]).

This solves a system of two coupled differential equations:

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:

z[2]/.%

Here is a plot of the solution for z[x] found on line 3. (RefLink[Plot, paclet:ref/Plot]) is discussed in "Basic Plotting":

Plot[Evaluate[z[x]/.%3],{x,0,Pi}]

Numerical solution of partial differential equations.