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 [x0, xn], using the second-order Runge-Kutta method (the midpoint/modified-Euler RK2 scheme). You provide the right-hand side F as an expression in x, y and p (where p stands for y'), the initial values y(x0) and y'(x0), the interval endpoints and the number of steps. The result is a table of (x, y, y') values marching across the interval. This is pure numerical analysis, so it applies identically anywhere.
How to use it
Type the forcing function F using x, y and p, for example -4*p-4*y for \(y'' = -4y' - 4y\). Operators + - * / ^ (or **) and functions sin, cos, tan, exp, log, ln, sqrt, abs, pow plus constants pi, e are supported. Set x0, the initial y0 and y'0 = p0, the end point xn, and pick the number of subintervals n. More steps means a smaller step size \(h = (x_n - x_0)/n\) and lower error (global error is \(O(h^2)\)).
The formula explained
The equation is first reduced to a first-order system by letting \(p = y'\), giving \(y' = p\) and \(p' = F(x, y, p)\). Each RK2 step samples the slope at the start and at the midpoint and combines them: \(j_1 = h\cdot F(x,y,p)\), \(k_1 = h\cdot p\), then \(j_2\) and \(k_2\) are evaluated at the midpoint and used to advance p and y. The local truncation error is \(O(h^3)\) per step.
Worked example
With F = -4*p-4*y, x0 = 0, y0 = 0, p0 = 1, xn = 1, n = 50, the step size is \(h = 0.02\). The first step gives \(y_1 = 0.0192\) and \(p_1 = 0.9224\). Iterating to x = 1 yields $$y(1) \approx 0.13533 \quad\text{and}\quad y'(1) \approx -0.13533,$$ matching the exact solution \(y = x\cdot e^{-2x}\) whose value at x = 1 is \(e^{-2} = 0.135335\).
FAQ
Is this RK2 or RK4? This is second-order Runge-Kutta (midpoint rule), not the classical fourth-order method, so it is only second-order accurate globally.
Can xn be less than x0? Yes. The step size simply becomes negative and integration proceeds backward, which is mathematically valid.
Why did I get an error row? Evaluation problems such as division by zero, log of a non-positive number or sqrt of a negative number inside F stop the integration and report the location.