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.

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

  1. 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

Frequently Asked Questions

Last updated: 2026-05-23 · Reviewed by Nham Vu