Connect via MCP →

Enter Calculation

Formula

Advertisement

Results

y(xn) — RK4 approximation
0.7615941538
classical 4th-order Runge-Kutta
Step size h 0.02
Subdivisions n 50
F(x,y) evaluations 200
i / x y (approx)
0 0
0.02 0.0199973337
0.04 0.0399786803
0.06 0.0599281034
0.08 0.079829769
0.1 0.0996679945
0.12 0.1194272984
0.14 0.1390924477
0.16 0.1586485041
0.18 0.1780808679
0.2 0.1973753199
0.22 0.2165180612
0.24 0.2354957492
0.26 0.2542955322
0.28 0.2729050801
0.3 0.291312612
0.32 0.3095069207
0.34 0.3274773943
0.36 0.3452140335
0.38 0.3627074669
0.4 0.3799489616
0.42 0.3969304313
0.44 0.4136444414
0.46 0.4300842106
0.48 0.4462436094
0.5 0.4621171563
0.52 0.4777000112
0.54 0.4929879656
0.56 0.5079774318
0.58 0.5226654285
0.6 0.5370495658
0.62 0.5511280273
0.64 0.5648995515
0.66 0.5783634117
0.68 0.591519394
0.7 0.6043677756
0.72 0.6169093013
0.74 0.6291451598
0.76 0.6410769595
0.78 0.6527067042
0.8 0.6640367685
0.82 0.675069873
0.84 0.6858090604
0.86 0.6962576708
0.88 0.7064193184
0.9 0.7162978682
0.92 0.7258974128
0.94 0.7352222508
0.96 0.7442768652
0.98 0.7530659027
1 0.7615941538

What this calculator does

This tool numerically solves a first-order ordinary differential equation of the form \(y' = F(x, y)\) with a given initial condition \(y(x_0) = y_0\), over the interval from \(x_0\) to \(x_n\). It uses the classical fourth-order Runge-Kutta method (RK4), one of the most widely used and reliable single-step integrators in numerical analysis. The result is a table of points \((x_i, y_i)\) approximating the true solution, plus the final value \(y(x_n)\). This is a pure-math tool with no country or unit scope.

How to use it

Enter the right-hand side \(F(x,y)\) as an expression in x and y (for example 1-y^2, x+y, x*y, or sin(x)+y). Supported operators are + - * / ^ and functions such as sin, cos, tan, exp, log, ln, sqrt, abs, tanh, plus constants pi and e. Set the start \(x_0\), initial value \(y_0\), end \(x_n\), and choose how many equal subdivisions \(n\) to use. More subdivisions give higher accuracy because the global error of RK4 shrinks like \(h^4\).

The formula explained

The interval is split into \(n\) equal steps of width \(h = (x_n - x_0)/n\). At each step RK4 samples the slope four times: once at the start (\(k_1\)), twice at the midpoint (\(k_2\), \(k_3\)), and once at the end (\(k_4\)). The next value is a weighted average,

$$y_{n+1} = y_n + \frac{1}{6}\left(k_1 + 2k_2 + 2k_3 + k_4\right)$$

This cancels error terms up to fourth order, giving a local truncation error of \(O(h^5)\) and global error \(O(h^4)\).

Diagram of one RK4 step showing four slope evaluations k1 to k4 over step size h
RK4 combines four slope estimates (\(k_1\)–\(k_4\)) across each step to advance from \((x_n, y_n)\) to \((x_{n+1}, y_{n+1})\).

Worked example

Solve \(y' = 1 - y^2\) with \(x_0 = 0\), \(y_0 = 0\), \(x_n = 1\) and \(n = 10\) (\(h = 0.1\)). The exact solution is \(y = \tanh(x)\). The first RK4 step gives

$$y_1 = 0.0996679,\quad \tanh(0.1) = 0.0996680$$

After all ten steps,

$$y(1) = 0.7615942,\quad \tanh(1) = 0.7615942$$

to seven digits.

Line chart comparing exact solution curve with RK4 numerical points lying close to it
RK4 numerical points (dots) track the exact solution curve closely across the interval.

FAQ

Why is RK4 better than Euler's method? Euler uses one slope per step (error \(O(h)\)). RK4 uses four and averages them, achieving \(O(h^4)\) accuracy for the same step size, so far fewer steps are needed for a target precision.

How many steps should I pick? Start with 50. If the solution is smooth, that is usually plenty; for rapidly varying or near-stiff problems, increase to 100, 200 or 500.

What if I get NaN or Infinity? The solution may have diverged or \(F(x,y)\) hit an invalid operation (like log of a negative or division by zero). Check the expression and try a smaller interval or more steps.

Last updated: