What this calculator does
This tool numerically solves a second-order ordinary differential equation written in the form \(y'' = F(x, y, y')\) over an interval \([x_0, x_n]\), using the classic fourth-order Runge-Kutta (RK4) method. You supply the right-hand side \(F\) as a math expression in \(x\), \(y\) and \(p\) (where \(p\) stands for \(y'\)), the initial conditions \(y(x_0)\) and \(y'(x_0)\), the interval endpoints, and the number of steps. The calculator returns a full table of \(x\), \(y\) and \(y'\) values plus the endpoint values. It is pure numerical analysis and applies universally.
How to use it
Enter \(F(x, y, p)\) — for example -4*p - 4*y for \(y'' + 4y' + 4y = 0\). Set \(x_0\), \(y_0 = f(x_0)\), and \(p_0 = y'(x_0)\). Set the end point \(x_n\) and choose the number of subintervals \(n\) (more steps means a smaller step size \(h = (x_n - x_0)/n\) and higher accuracy). Pick how many significant digits to display. The error of RK4 is \(O(h^4)\) globally, so doubling \(n\) roughly cuts the error by a factor of 16.
The formula explained
A second-order ODE is reduced to a system of two first-order equations by setting \(p = y'\): then \(y' = p\) and \(p' = F(x, y, p)\). RK4 advances both unknowns each step using four weighted slope evaluations (\(k\) for \(y\), \(j\) for \(p\)), combining them as $$\frac{k_1 + 2k_2 + 2k_3 + k_4}{6} \quad\text{and}\quad \frac{j_1 + 2j_2 + 2j_3 + j_4}{6}.$$
Worked example
Take \(y'' = -4p - 4y\) with \(x_0 = 0\), \(y_0 = 0\), \(p_0 = 1\), \(x_n = 1\) and a single coarse step (\(n = 1\), \(h = 1\)). The four stages give \(k_1=1\), \(k_2=-1\), \(k_3=2\), \(k_4=-5\) and \(j_1=-4\), \(j_2=2\), \(j_3=-6\), \(j_4=12\). Then $$y(1) = \frac{1 - 2 + 4 - 5}{6} = -\frac{1}{3} = -0.3333$$ and $$p(1) = 1 + \frac{-4 + 4 - 12 + 12}{6} = 1.$$ The exact solution is \(y = x e^{-2x}\), so \(y(1) = e^{-2} = 0.1353\); one giant step of \(h = 1\) is far too coarse. Using \(n = 50\) or \(100\) converges right onto the exact value.
FAQ
Can I integrate backward? Yes — set \(x_n\) less than \(x_0\) and the step size \(h\) becomes negative, integrating from \(x_0\) down to \(x_n\).
Why does my answer look wrong with few steps? RK4 accuracy depends on a small step size. Increase \(n\) until successive results stop changing.
What functions can F contain? + - * / ^, parentheses, and sin, cos, tan, asin, acos, atan, sinh, cosh, tanh, exp, log/ln, log10, sqrt, abs, plus the constants pi and e.