The simplest of RK methods is the 2-step RK solver. At each time step t(n), given y(n), the solution to advance to y(n+1) is:
The RK2 method from the above equations can be quite easily implemented for fixed step size integration. The algorithm can be summarized as:
1) % Define step size (h), initial function y(0), initial time t0, final time tf
2) nosteps = (tf – t0)/h
3) for i ← 1 to nosteps
- Calculate derivative function f[t0,y[i-1]]
- q1 ← y[i-1] + 0.5*h* f[t0,y[i-1]]
- t0 ← t0 + 0.5*h
- Calculate f[t0,q1]
- y[i] ← y[i-1] + h*f[t0,q1]
- t0 ← t0 + h
- q1 ← y[i-1] + 0.5*h* f[t0,y[i-1]]
- t0 ← t0 + 0.5*h
- Calculate f[t0,q1]
- y[i] ← y[i-1] + h*f[t0,q1]
- t0 ← t0 + h
4) Display results
[…] 2-step RK method is pretty much the same as the Euler’s method performed with two time steps. The 2-step RK method […]
ReplyDelete