Runge-Kutta (RK4) Method Calculator
Numerically solve a first-order ODE \( \frac{dy}{dx} = f(x, y) \) using the classical Runge–Kutta method of order 4 (RK4). We show every intermediate slope (k1–k4) and the resulting y values.
1. Problem setup
Use JavaScript/Math syntax: x + y, x*y, Math.sin(x), y - x*x. We already expose common Math functions via with(Math){...}.
2. Solution steps
No computation yet. Fill the form and click “Run RK4”.
Runge–Kutta 4th order formula
Given \(\frac{dy}{dx} = f(x, y)\) and a current point \((x_n, y_n)\) with step \(h\):
k₁ = f(xₙ, yₙ)
k₂ = f(xₙ + h/2, yₙ + h·k₁/2)
k₃ = f(xₙ + h/2, yₙ + h·k₂/2)
k₄ = f(xₙ + h, yₙ + h·k₃)
yₙ₊₁ = yₙ + (h/6)(k₁ + 2k₂ + 2k₃ + k₄)
This method is popular because it strikes an excellent balance between accuracy and computational cost.
Tips
- If the solution diverges, try a smaller step size \(h\).
- For stiff ODEs, RK4 might not be the best choice.
- Always check your function syntax if you get NaN results.