Loading...
Loading...
Numerical Analysis · Axiom Academy
EXAMPLE Runge-Kutta Method (RK4) Step-by-step walkthrough of the 4th-order Runge-Kutta algorithm Solve the initial value problem: Using RK4 with step size h = 0.5 , compute y(0.5) . Step 1: Setup - Identify f(t, y) and Initial Values The ODE is y' = y - t² + 1. What is the function f(t, y)? Since y' = y - t² + 1, we identify: Initial values: t₀ = 0, y₀ = 0.5, h = 0.5 We want to find y₁ = y(0.5) using one step of RK4. Calculate k₁ = f(t₀, y₀) = f(0, 0.5) k₁ = y₀ - t₀² + 1 = 0.5 - 0² + 1 = ? k₁ = f(0, 0.5) = 0.5 - 0² + 1 = 1.5 This represents the slope at the starting point (t₀, y₀). Calculate k₂ = f(t₀ + h/2, y₀ + (h/2)k₁) t = t₀ + h/2 = 0 + 0.25 = 0.25 y = y₀ + (h/2)k₁ = 0.5 + (0.25)(1.5) = 0.5 + 0.375 = 0.875 Now compute f(0.25, 0.875) = 0.875 - 0.25² + 1 = ? k₂ = f(0.25, 0.875) = 0.875 - (0.25)² + 1 k₂ = 0.875 - 0.0625 + 1 = 1.8125 This is the slope at the midpoint, using k₁ to estimate y. For k₃: k₃ = f(t₀ + h/2, y₀ + (h/2)k₂) y = 0.5 + (0.25)(1.8125) = 0.5 + 0.453125 = 0.953125 For k₄: k₄ = f(t₀ + h, y₀ + h·k₃) What are the values of k₃ and k₄? k₃ = f(0.25, 0.953125) = 0.953125 - 0.0625 + 1 = 1.890625 y = 0.5 + (0.5)(1.890625) = 0.5 + 0.9453125 = 1.4453125 k₄ = f(0.5, 1.4453125) = 1.4453125 - 0.25 + 1 = 2.1953125 With k₁ = 1.5, k₂ = 1.8125, k₃ = 1.890625, k₄ = 2.1953125 Weighted average: k₁ + 2k₂ + 2k₃ + k₄ = 1.5 + 2(1.8125) + 2(1.890625) + 2.1953125 = 1.5 + 3.625 + 3.78125 + 2.1953125 = 11.1015625 y₁ = y₀ + (h/6)(weighted average) y₁ = 0.5 + (0.5/6)(11.1015625)
This is the written version of the interactive lesson above. See the full Numerical Analysis course.