Differential Equations – Runge-Kutta Method

Interactive Numerical Solver, Graphs, and Tutorial

About the Runge-Kutta Method

This is an interactive tool to explore the numerical Runge-Kutta method. This method is used to approximate solutions to differential equations and is very powerful for solving a wide range of problems in science and engineering.

Consider the differential equation:

\( y' = f(x, y) \) with \( y(x_0) = K \) (initial value)

We wish to approximate the solution over an interval \( [a, b] \). We divide this interval into \( n \) smaller intervals of size \( h \). The 4th order Runge-Kutta method provides an approximation as follows:

Let \( y_0 = K \) (starting value)
\( y_{i+1} = y_i + \frac{1}{6}[k_1 + 2k_2 + 2k_3 + k_4] \) for \( i = 0, 1, \dots, n-1 \)

where:
\( k_1 = h \cdot f(x_i, y_i) \)
\( k_2 = h \cdot f(x_i + \frac{h}{2}, y_i + \frac{k_1}{2}) \)
\( k_3 = h \cdot f(x_i + \frac{h}{2}, y_i + \frac{k_2}{2}) \)
\( k_4 = h \cdot f(x_i + h, y_i + k_3) \)

The local truncation error is of the order \( O(h^5) \) and in principle decreases as \( h \) decreases.

Equations Used in This Demo

Tutorial

All differential equations in this demo have the same initial value \( y(0) = 1 \) and exact solutions for comparison.

  1. Select the first differential equation \( y' = x^2 \). At the start, \( h = 1.25 \) and \( n = 8 \).
  2. Examine the exact (blue curve) and approximate (red points) solutions on the graph.
  3. Decrease \( h \) by increasing \( n \) (or decrease \( h \) directly) and observe how the approximation improves.
  4. Select the other differential equations and analyze the results.
  5. Compare the exact and approximate values in the table below the graph.

Runge-Kutta Calculator

Your browser does not support the HTML5 canvas element.

Results

Comparison between exact solution and Runge-Kutta approximation:

Step (i) xᵢ Approximate yᵢ Exact y(xᵢ) Error k₁ k₂ k₃ k₄

Additional Resources

More references on differential equations: