What is the Runge-Kutta 2nd Order Method Calculator?
This tool numerically solves a first-order ordinary differential equation (ODE) of the form \(y' = F(x, y)\) over an interval \([x_0, x_n]\), starting from the initial condition \(y_0 = f(x_0)\). It uses the 2nd-order Runge-Kutta method (the midpoint method), producing a table of \((x, y)\) approximations and the final value \(y_n = f(x_n)\). It is a universal mathematical tool with no country or jurisdiction restrictions.
How to use it
Enter the right-hand side \(F(x,y)\) as a math expression in \(x\) and \(y\) (for example 1-y^2, x*y, or sin(x)+y). Provide the initial point \(x_0\) and \(y_0\), the end of the range \(x_n\), and choose the number of equal subdivisions \(n\). The interval is split into \(n\) steps of size \(h = (x_n - x_0)/n\). A larger \(n\) gives a finer step and better accuracy. The display-precision selector only controls how many significant digits are shown.
The formula explained
The midpoint Runge-Kutta scheme advances the solution one step at a time:
$$k_1 = h \cdot F(x_i, y_i)$$$$k_2 = h \cdot F\left(x_i + \frac{h}{2},\; y_i + \frac{k_1}{2}\right)$$$$y_{i+1} = y_i + k_2, \qquad x_{i+1} = x_i + h$$The slope is estimated at the midpoint of the step, which cancels the leading error term. The local truncation error is \(O(h^3)\) and the global error is \(O(h^2)\), so halving \(h\) roughly quarters the error.
Worked example
Solve \(y' = 1 - y^2\) with \(x_0 = 0\), \(y_0 = 0\), \(x_n = 1\), \(n = 50\) (so \(h = 0.02\)). The exact solution is \(y = \tanh(x)\). Step 1: \(k_1 = 0.02 \cdot (1-0) = 0.02\); \(k_2 = 0.02 \cdot (1-0.01^2) = 0.019998\); \(y_1 = 0.019998\). Continuing all 50 steps gives \(y(1) \approx 0.76159\), matching \(\tanh(1) \approx 0.7615942\) to five decimals.
FAQ
How accurate is it? Accuracy improves with larger \(n\) because global error scales as \(h^2\). For stiff equations or very large steps the result can diverge.
Can \(x_n\) be less than \(x_0\)? Yes. Then \(h\) is negative and the method integrates backward in \(x\), which is still valid.
What functions can I use? Standard ones: sin, cos, tan, exp, ln, log, sqrt, plus +, -, *, /, ^ and parentheses, and the constants e and pi.