Numerical Methods/Solution of IVP

From Wikibooks, open books for an open world
Jump to: navigation, search

Suppose you are given  y'(x)=f(x,y) where y, the dependent variable, is a function of the independent variable x and y(x_0)=y_0 is given. This is an initial value problem of ODE's because it specifies the initial condition(s) and the differential equation giving y. The problem is to calculate the values of y at points x>x_0. There are a variety of numerical methods to solve this type of problem. They yield a numerical solution which is nothing but a series of values y_n corresponding to the points x_n.

The numerical solution is an approximate solution. The real solution denoted by y(x) could either be

  • impossible to get because the function f may be non integrable
  • too difficult to get

Anyways, a numerical solution gives us an algorithm to compute y_n based on already available information. So one could write a computer program to compute it. This is the basis of simulations.

Euler's Method is the simplest, and its somewhat similar to calculating the integral numerically. It is easy to see what is happening on a graph. At each point x_n you are just looking at what direction the derivative tells you to go, and you take a step in that direction.

Euler's Explicit Method[edit]

  • Let x_{n+1} = x_n + h, where h is some small step value.
  • Let y_{n+1} = y_n + h*f'(x_n,y_n).
  • Let y'_{n+1}=y-n+h*f(x_n,y_n).
  • Let y-{n+1}=y_n+((h/2)*[f{x_n,y_n}+f(x_n+1,y'_n+1)].

Examples[edit]

Now we will go over some examples of using this algorithm.

y'=x[edit]

Suppose we know also that we want to calculate f(1) using n=4 iterations. Thus h=1/4=.25.

  • x_0=0, y_0=5
  • x_1=.25, y_1=5+.25*f'(0,5)=5+.25*0=5
  • x_2=.5, y_2=5+.25*f'(.25,5)=5+.25*.25=5+.0625=5.0625
  • x_3=.75, y_3=5.0625+.25*f'(.5,5.0625)=5.0625+.25*.5=5.0625+.125=5.1875
  • x_4=1, y_4=5.1875+.25*f'(.75,5.1875)=5.1875+.25*.75=5.1875+.1875=5.375

So we are done, and we know that f(1)~=5.375.

We know the exact solution by integrating, y'=x, so y=x^2/2+c. In our case, to calculate c, we would substitute 0 for x and 5 for y to see that c=5. so f(1)=1^2/2+5 = 5.5.

Error analysis[edit]

The error only depends on the concavity of the function (the second derivative). Thus we can estimate the error as O(x^2). We can decrease the error by taking smaller step sizes.

Runge-Kutta Methods[edit]

Runge-Kutta methods are a family of algorithms particularly well-suited for numerically solving systems of simultaneous differential equations.

Suppose we have a pair of simultaneous equations of the form

\frac{dx}{dt}=f(t,x,y), and

\frac{dy}{dt}=g(t,x,y),

and we wish to numerically integrate these with respect to t, with a step size of \Delta t. We then compute the following quantities:


\begin{array}{lcl}m_1&=&f(t,x,y)\\
n_1&=&g(t,x,y)\\
m_2&=&f(t+\frac{\Delta t}{2}, x+\frac{m_1}{2}, y+\frac{n_1}{2})\\
n_2&=&g(t+\frac{\Delta t}{2}, x+\frac{m_1}{2}, y+\frac{n_1}{2})\\
m_3&=&f(t+\frac{\Delta t}{2}, x+\frac{m_2}{2}, y+\frac{n_2}{2})\\
n_3&=&g(t+\frac{\Delta t}{2}, x+\frac{m_2}{2}, y+\frac{n_2}{2})\\
m_4&=&f(t+\Delta t, x+m_3, y+n_3)\\
n_4&=&g(t+\Delta t, x+m_3, y+n_3)\\
\Delta x&=&\frac{1}{6}(m_1+2m_2+2m_3+m_4)\Delta t\\
\Delta y&=&\frac{1}{6}(n_1+2n_2+2n_3+n_4)\Delta t\\
\end{array}

x, y and t are then incremented by \Delta x, \Delta y and \Delta t respectively, and all the above quantities calculated again for the next step.

This method can obviously be extended to three or more simultaneous equations, and the error is of order \Delta t^5. The high accuracy and ease of implementation make this method a popular computational tool.

Also useful is the fact that \Delta t can be changed after any step of the algorithm, which allows rapid changes in the variables to be dealt with.