PHAS2441 Session 7 Second order Runge Kutta method

PHAS2441 Session 7:
Second-order Runge Kutta method.
February 2, 2015
We’re starting from Euler’s method for solving differential equations of the form
dx = f(x,t) (1)
to obtain x(t).
Given starting condition for some t, Euler’s method uses a Taylor expansion to solve the
equation at a later time t + h:
x(t + h) = x(t) + hdx + 1h2 d2x + . . . (2)
= x(t) + hf (x, t) + O(h2 ). (3)
In second-order Runge Kutta, we do a Taylor expansion around t + 12 h to obtain an expression for x(t + h):
1 1 􏰀dx􏰁 1 2􏰀d2x􏰁 3 x(t+h)=x(t+ h)+ h + h 2 +O(h) (4)
2 2 dt t+12h 8 dt t+12h
We can also calculate x(t) using a Taylor expansion around t + 12 h, which gives us
1 1 􏰀dx􏰁 1􏰀 1􏰁2 􏰀d2x􏰁
x(t) = x(t + h) − h + − h2 + O(h3) (5)
2 2 dt 1 2 2 dt2 1 t+2h t+2h
(note the sign change in the second term). Subtracting equation 4 from equation 5 and doing some minor rearrangement then gives us
+O(h ). (6) Conveniently, by doing this we’ve eliminated the troublesome terms involving d2x. Even
x(t+h)=x(t)+h
dt2 better, we’ve now reduced our errors from O(h2) in Euler’s method to O(h3) here.
However, we’re now left with the need to calculate
􏰀dx􏰁 􏰀 1 1􏰁
=f x(t+ h),t+ h . (7) dtt+12h 22
Programming Help
k1 =hf(x,t), (9) 1 1 􏰀􏰂 1 􏰃 1􏰁
k2 =hf(x+2k1,t+2h)=hf x(t)+2hf(x,t) ,t+2h (10) x(t + h) = x(t) + k2. (11)
The fourth-order Runge-Kutta method (i.e. the one that is accurate to h4 and has errors of order O(h5)) follows a similar procedure of taking Taylor expansions around differ- ent points and then eliminating unknowns by using different linear combinations, but is considerably more complicated.
The problem with this is that we don’t know x(t + 21 h). We can approximate it though, by using equation 3, to give
x(t + 12 h) = x(t) + 12 hf (x, t). (8) Substituting this result into equation 6 then gives us the set of equations which are known
as the second-order Runge Kutta method:
Code Help, Add WeChat: cstutorcs