# Runge Kutta method example

Hi, can someone plz explain where the formulas for $w_{i+1}$ come from? Thanks!

• I don't see Runge-Kutta, just midpoint and Euler... – coffeemath May 6 '16 at 23:03
• This is the second order of Runge Kutta, which can be considered as Euler and midpoint method. But I don't know where the formula comes from. – J.doe May 6 '16 at 23:13
• OK unfortunately I didn't know the connection. But it looks like you got the "Solution" from a text or notes, what does text say about the method? – coffeemath May 6 '16 at 23:16
• The midpoint method given is $w_{i+1}=w_i+hf(t_i+h/2, w_i+hf(t_i,w_i)/2)$, for i= 0, 1, ..., N-1. I substituted the value with the symbols, but I get a different result than that listed above. – J.doe May 6 '16 at 23:24

The iteration formula for the Midpoint Rule is given by:

$\tag 1 w_{i+1} = w_i + h f\left(t_i + \dfrac{h}{2}, w_i +\dfrac{h}{2} f\left(t_i, w_i\right)\right), w_0 = \alpha = 0.5, N = 10, h = 0.2, t_i = 0.2i$

We have:

• $f(t, y) = y-t^2 + 1$
• $t_i + \dfrac{h}{2} = 0.2 i + 0.1$
• $f(t_i, w_i) = w_i - t_i^2 + 1 = w_i -(0.2i)^2 + 1 = w_i -0.04 i^2 + 1$

From $(1)$, we have:

$$w_{i+1} = w_i + 0.2 f \left(0.2 i + 0.1, w_i + 0.1(w_i -0.04 i^2 + 1) \right) \\ =w_i + .2(1.1~ w_i -0.044i^2 -0.04 i + 1.09 )$$

Hence:

$$w_{i+1} = 1.22 w_i - 0.0088i^2 - 0.008 i + 0.218$$

Give the second one a go.

• Nice! As an aside, you might find the align environment useful: meta.math.stackexchange.com/a/5024/139123 – David K May 6 '16 at 23:59
• @DavidK: Thanks, I was trying to use align and for some reason always screw it up! :-) – Moo May 7 '16 at 0:01
• Oh I treated $t+i$ as $t_0$ and that's why I always get the wrong answer. Thanks a lot!! – J.doe May 7 '16 at 0:21
• Hi, what does $t$ mean in the formula? – J.doe May 8 '16 at 17:23
• I am not sure I follow, you have a function $f(t, y)$, it is time. The $t_i$ is the step size in the numerical iteration. – Moo May 8 '16 at 19:40