Runge-Kutta Methods: Order of Accuracy

Claude prompt

This page was generated by Claude Code from the following prompt (with additional prompting):

let's create a demo, similar to the Euler one, but for multiple integration schemes. This one can be javascript instead of julia because we will not be showing code. Let's integrate a second-order equation, so show graphs of x and xdot and integrate the vector {x}. Show Euler by default, but also have midpoint, Ralston, and classical RK4. Below the time-series plot, also show the log-log error plots with all the trendlines plotted in light grey and the current one bolded

Test problem: a damped pendulum, \[ \ddot{x} = -\sin x - 0.1\,\dot{x}, \qquad x(0) = 2.5,\quad \dot{x}(0) = 0, \] written as a first-order system in the state vector \(\vec{x} = [x,\ \dot{x}]^T\): \[ \dot{\vec{x}} = \vec{f}(t, \vec{x}) = \begin{bmatrix} \dot{x} \\ -\sin x - 0.1\,\dot{x} \end{bmatrix}. \] Every method below applies the same update to the whole vector at once. There is no closed-form solution, so the "exact" curve is RK4 with \(h = 2.5\times10^{-4}\).

\[ \vec{x}_{i+1} = \vec{x}_i + h\,\vec{k}_1, \qquad \vec{k}_1 = \vec{f}(t_i, \vec{x}_i) \]

One slope per step, taken at the start. First order: global error \(O(h)\).

Black: reference solution. Colored dots: numerical steps. The red bar at \(t_f = 10\) is the global error in each component.

Global error \(\lVert \vec{x}_N - \vec{x}(t_f) \rVert\) at \(t_f\) against \(h\) on log-log axes. The slope of each line is the order of the method.


Back to top

ASEN 3502, CU Boulder. Last built Oct 7, 2026 at 11:14 AM MDT.