Runge-Kutta Calculator (RK4)
Numerically solve any first-order ODE dy/dx = f(x,y) using the classical 4th-order Runge-Kutta method. Enter f(x,y), initial conditions, step size, and number of steps to get a table of solution values.
Presets:
ODE: dy/dx = f(x, y)
Use x and y as variables. Supports sin, cos, exp, log, sqrt, ^, etc.
Steps
-
x final
-
y final
-
Solution Table
| Step | x | y |
|---|---|---|
| Press "Solve with RK4" to see results. | ||
Solution Curve y(x)
RK4 Formula Reference
k1 = h · f(xn, yn)
k2 = h · f(xn + h/2, yn + k1/2)
k3 = h · f(xn + h/2, yn + k2/2)
k4 = h · f(xn + h, yn + k3)
yn+1 = yn + (k1 + 2k2 + 2k3 + k4) / 6
Summary
Numerically solve any first-order ODE dy/dx = f(x,y) using the classical 4th-order Runge-Kutta method. Enter f(x,y), initial conditions, step size, and number of steps to get a table of solution values.
How it works
- The 4th-order Runge-Kutta method advances the solution from (xn, yn) to (xn+h, yn+1) using four slope estimates: k1 = h·f(xn, yn), k2 = h·f(xn+h/2, yn+k1/2), k3 = h·f(xn+h/2, yn+k2/2), k4 = h·f(xn+h, yn+k3), then yn+1 = yn + (k1 + 2k2 + 2k3 + k4)/6. This weighted average achieves 4th-order accuracy (global error O(h^4)). Expressions are evaluated by math.js, allowing any formula using x, y, standard operators, and built-in functions.
Use cases
- Solve motion equations such as dy/dx = -y + sin(x) numerically.
- Verify analytical solutions of first-order ODEs against numerical approximations.
- Explore how initial conditions affect the shape of solution curves.
- Compute population growth models dy/dx = r·y·(1 - y/K) step by step.
- Approximate solutions for ODEs with no closed-form antiderivative.
Frequently Asked Questions
Last updated: 2026-05-23 ·
Reviewed by Nham Vu