Intro to Runge-Kutta
Download
Report
Transcript Intro to Runge-Kutta
Introduction to the Runge-Kutta
algorithm for approximating
derivatives
PHYS 361
Spring, 2011
review: Euler method
General form of first-oder Diff Eq: d x(t) f (x,t)
dt
Example: decay equation
f (x,t)
x
To implement a numerical solution,
we must approximate the derivative.
The Euler method is the simplest approach: dx x x i1 x i
dt
t
t i1 t i
(forward difference)
Substituting this into our decay equation, we can solve for xi+1
xi1 xi f (x,t)t
This is equivalent to linearly extrapolating x(t) from xi to xi+1
or... using the Taylor series expansion for x(t) and cutting out all terms
t2 or higher. This makes the Euler method “first order accurate”
involving
Taylor series
dx
1 d2x
2
x(t t) x(t)
t
t ...
2
dt
2 dt
Substitute f(x) for dx/dt (from our equation), keep up to 2nd order in dt
1 f f
2
x(ti1 ) x(t i ) f it f
t
2 x t i
This approach is fine if we know df/dx and df/dt
Runge-Kutta
make use of Mean value theorem
Same idea as Euler method, but aim for “exact” solution by using the
“mean value” slope, instead of the slope at ti.
xi1 xi t f (xm ,tm )
x
xm
ti
tm
Approximate the mean value slope
by evaluating f(x,t) at xm and tm
1
tm t i t
2
ti+1
Use Euler method to approximate xm: x i1/ 2 x i
Decay example:
f (N,t)
N
t
f (x i ,ti )
2
2nd order R-K has two steps
4th order R-K has four steps
Runge-Kutta... another approach
Approximate mean slope by averaging slopes at ti, ti+1, and ti+1/2
Decay example:
x
f (N,t)
N
f1 f (xi ,ti )
xi
xm
xi+1
ti
tm
ti+1
Use weighted average of slopes:
t
x m1 x i
f1
2
t
x m2 x i
f2
2
x
i1 x i t f 3
f 2 f (xm1,tm )
f 3 f (xm2,tm )
f 4 f ( x
i1,t i1)
t
x i1 x i f
1 2 f2 2 f3 f4
6