Find y(0.2) for `y'=-y`, `x_0=0, y_0=1`, with step length 0.1 using Runge-Kutta 4 method (first order differential equation) Solution:Given `y'=-y, y(0)=1, h=0.1, y(0.2)=?`
Fourth order Runge-Kutta (RK4) method formula
`k_1=h f(x_n,y_n)
`k_2=h f(x_n+h/2,y_n+k_1/2
`k_3=h f(x_n+h/2,y_n+k_2/2
`k_4=h f(x_n+h,y_n+k_3
`y_(n+1)=y_n+1/6(k_1+2k_2+2k_3+k_4)`
for `n=0,x_0=0,y_0=1`
`k_1=hf(x_0,y_0)`
`=(0.1)f(0,1)`
`=(0.1)*(-1)`
`=-0.1`
`k_2=hf(x_0+h/2,y_0+k_1/2)`
`=(0.1)f(0.05,0.95)`
`=(0.1)*(-0.95)`
`=-0.095`
`k_3=hf(x_0+h/2,y_0+k_2/2)`
`=(0.1)f(0.05,0.9525)`
`=(0.1)*(-0.9525)`
`=-0.0952`
`k_4=hf(x_0+h,y_0+k_3)`
`=(0.1)f(0.1,0.9048)`
`=(0.1)*(-0.9048)`
`=-0.0905`
`y_1=y_0+1/6(k_1+2k_2+2k_3+k_4)`
`=1+1/6[-0.1+2(-0.095)+2(-0.0952)+(-0.0905)]`
`=0.9048`
`x_1=x_0+h=0+0.1=0.1`
for `n=1,x_1=0.1,y_1=0.9048`
`k_1=hf(x_1,y_1)`
`=(0.1)f(0.1,0.9048)`
`=(0.1)*(-0.9048)`
`=-0.0905`
`k_2=hf(x_1+h/2,y_1+k_1/2)`
`=(0.1)f(0.15,0.8596)`
`=(0.1)*(-0.8596)`
`=-0.086`
`k_3=hf(x_1+h/2,y_1+k_2/2)`
`=(0.1)f(0.15,0.8619)`
`=(0.1)*(-0.8619)`
`=-0.0862`
`k_4=hf(x_1+h,y_1+k_3)`
`=(0.1)f(0.2,0.8187)`
`=(0.1)*(-0.8187)`
`=-0.0819`
`y_2=y_1+1/6(k_1+2k_2+2k_3+k_4)`
`=0.9048+1/6[-0.0905+2(-0.086)+2(-0.0862)+(-0.0819)]`
`=0.8187`
`x_2=x_1+h=0.1+0.1=0.2`
`:.y(0.2)=0.8187`
| `n` | `x_n` | `y_n` | `k_1` | `k_2` | `k_3` | `k_4` | `x_(n+1)` | `y_(n+1)` |
| 0 | 0 | 1 | -0.1 | -0.095 | -0.0952 | -0.0905 | 0.1 | 0.9048 |
| 1 | 0.1 | 0.9048 | -0.0905 | -0.086 | -0.0862 | -0.0819 | 0.2 | 0.8187 |
This material is intended as a summary. Use your textbook for detail explanation.
Any bug, improvement, feedback then