# Numerical Solutions of ordinary differential equations

Numerically solving $y'=f(x,y)$ with $k_1=f(x_n,y_n), k_2=f(x_n+c_2*h, y_n+c_2*h*k_1), y_{n+1}=y_n+h(b_1*k_1+b_2*k_2)$

what would the local truncation error be?

Also, how would we perform a Taylor expansion on this to show that it is second order, provided $b_1+b_2=1$ and $b_2*c_2=\frac{1}{2}$?

Many thanks.

-
What is your definition of order? –  Rudy the Reindeer Jan 18 '11 at 13:55
Do you define a method to be of order $p$ iff the local truncation error $e = O(h^{p})$? –  Rudy the Reindeer Jan 18 '11 at 15:10

The local truncation error of a numerical method is the error the method makes in one iteration. This means, to compute this error you assume that you know the exact solution $y(x_n)$ and you apply your method to compute an approximation for $y(x_{n+1})$. Let's call the approximation $y_{n+1}$.

You can rewrite your exact solution $y(x)$ using a Taylor expansion. Because you're interested in $y(x_{n+1}) = y(x_n + h)$, you expand around $x_n$ and then evaluate at $x_n + h$.

The expansion is this:

$$T_y (x) = y(x_n) + (x - x_n)*f(x_n, y(x_n)) + \frac{(x - x_n)^2}{2}*\frac{\partial}{\partial x}f(x_n, y(x_n)) + ...$$

Note that $x_n$ is a constant. Now evaluate $T_y$ at $x_n + h$ to obtain:

$$T_y (x_n + h) = y(x_n) + h*f(x_n, y(x_n)) + \frac{h^2}{2}*\frac{\partial}{\partial x}f(x_n, y(x_n)) + ...$$

Note that $T_y (x_n + h) = y(x_n + h)$, i.e. the Taylor expansion is identical with the exact solution $y$ assuming $h$ is small.

To calculate the local truncation error you just need to compute the difference between $y_{n + 1}$ and $T_y (x_n + h)$:

$$e := T_y (x_n + h) - y_{n+1} =$$ $$(y(x_n) + h*f(x_n, y(x_n)) + \frac{h^2}{2}*\frac{\partial}{\partial x}f(x_n, y(x_n)) + ...) - (y_n + h*(b_1 k_1 + b_2 k_2))$$

You use $y_n = y(x_n)$, your assumption, to obtain: $$e = h(f(x_n, y_n) - b_1f(x_n, y_n) - b_2 f(x_n + c_2 h, y_n + c_2 h k_1)) + \frac{h^2}{2}*\frac{\partial}{\partial x}f(x_n, y_n) + ...$$

If $f(x_n, y_n) - b_1f(x_n, y_n) - b_2 f(x_n + c_2 h, y_n + c_2 h k_1)$ is non-zero, your truncation error is $O(h)$.

With $b_2 = 1 - b_1$ you get

$$f(x_n, y_n) - b_1f(x_n, y_n) - b_2 f(x_n + c_2 h, y_n + c_2 h k_1) = b_2f(x_n, y_n) - b_2 f(x_n + c_2 h, y_n + c_2 h k_1)$$

So $$e = b_2 h (f(x_n, y_n) - f(x_n + c_2 h, y_n + c_2 h k_1)) + \frac{h^2}{2}*\frac{\partial}{\partial x}f(x_n, y_n) + ...$$

To finish this, you do the Taylor expansion for $f$ at $(x_n, y_n)$ and use the last condition $b_2 c_2 = \frac{1}{2}$, then the coefficient of $h$ in $e$ vanishes and you see that it's order 2. You can find the details here: Local truncation error calculation

-