A differential equation states a rule for how a quantity changes, and asks for the quantity. The rule is often easy to write down (“it shrinks at a rate proportional to its size”) when the quantity itself is not. The exponential is the answer to the simplest such rule, \(y' = y\); cosh, sinh, cos and sin answer the next simplest. A differential equation can also be run as a loop: start from a state, step it forward by its rate, repeat. Doing that well is numerical integration, and this chapter ends with its two basic tools, Euler's method and Runge–Kutta, and with the condition on the step size that keeps them from blowing up.
The paper solves no differential equations. What it needs from here is the exponential as the solution of \(y' = ky\) (used in chapter 4), and the step-size condition of section 6.8, which reappears as the learning-rate limit of gradient descent in section 7.5.
An ordinary differential equation (ODE) relates an unknown function \(y(t)\) of one variable to its derivatives. A first-order ODE gives the slope:
\[ y'(t) = f(t, y(t)). \]Read it as a rate law: at time \(t\), in state \(y\), the state changes at rate \(f(t, y)\). Examples:
The equation alone has many solutions; fixing the initial value \(y(t_0) = y_0\) picks one. When \(f\) is smooth, there is exactly one solution through each starting point [boyce]. The order of an ODE is that of the highest derivative in it: \(y'' = -y\) is second order. “Ordinary” means one independent variable \(t\); with several, it would be a partial differential equation.
A picture shows what the rule says before solving anything. At each point \((t, y)\), draw a short segment with slope \(f(t, y)\). This slope field (direction field) is a map of arrows; a solution is a curve that follows them everywhere.
An equation is separable when the rate is a function of \(t\) times a function of \(y\): \(y' = g(t)\, h(y)\). Then the \(y\)'s can be moved to one side and the \(t\)'s to the other, and each side integrated:
\[ \frac{dy}{h(y)} = g(t)\, dt \quad\Longrightarrow\quad \int \frac{dy}{h(y)} = \int g(t)\, dt + C. \]Treating \(dy/dt\) as a fraction to split looks like a trick; it is the chain rule (section 2.3) read backwards, applied to \(H(y(t))\) where \(H' = 1/h\) [openstax].
\(y' = ky\). Separate: \(dy/y = k\, dt\). Integrate: \(\ln |y| = kt + C\). Exponentiate: \(|y| = e^C e^{kt}\). With \(y(0) = y_0\):
Fact. The solution of \(y' = ky\), \(y(0) = y_0\), is \(y(t) = y_0\, e^{kt}\). With \(k = 1\), \(y_0 = 1\): \(\exp\) is the function that is its own derivative and is 1 at 0.
Check it directly: \(\frac{d}{dt} y_0 e^{kt} = k\, y_0 e^{kt} = k y\). It is the only solution, by the uniqueness of section 6.1. For \(k > 0\) it grows, for \(k < 0\) it decays, and the time for \(y\) to halve (for \(k < 0\)) is \(\ln 2 / |k|\), whatever \(y_0\) is.
The rate law can also be run as a loop: from \(y = 100\), repeatedly add \(h \cdot (-ky)\) and advance \(t\) by \(h\). With \(k = 0.5\) and \(h = 10^{-5}\) it reaches 60.652990 at \(t = 1\) and 13.533461 at \(t = 4\), against \(100 e^{-0.5} = 60.653066\) and \(100 e^{-2} = 13.533528\): five digits. The loop is Euler's method (section 6.6) with a step small enough to hide its error. With \(k = 1\) and \(n\) steps of size \(1/n\), it computes \((1 + 1/n)^n\): the sequence of section 1.5 whose limit is \(e\).
\(y' = y(1-y)\). Separate and split the fraction (partial fractions: \(\frac{1}{y(1-y)} = \frac{1}{y} + \frac{1}{1-y}\)):
\[ \int \left(\frac{1}{y} + \frac{1}{1-y}\right) dy = \ln\left|\frac{y}{1-y}\right| = t + C \quad\Longrightarrow\quad y(t) = \frac{1}{1 + \left(\frac{1}{y_0} - 1\right) e^{-t}}. \]This is the logistic sigmoid \(\sigma(t) = 1/(1 + e^{-t})\), shifted. It is the softmax of two numbers (chapter 15): \(\sigma(t) = e^t/(e^t + e^0)\). The curves of figure 6.1 are this formula.
A first-order equation is linear when \(y\) and \(y'\) appear only to the first power:
\[ y' + a(t)\, y = b(t). \]Multiply both sides by \(\mu(t) = e^{A(t)}\), where \(A' = a\). Since \(\mu' = a \mu\), the left side becomes the derivative of a product (section 2.2):
\[ \mu y' + a \mu y = (\mu y)' = \mu b \quad\Longrightarrow\quad y(t) = \frac{1}{\mu(t)} \left( \int \mu(t)\, b(t)\, dt + C \right). \]\(\mu\) is the integrating factor: it makes the left side something we can integrate.
Example. \(y' + y = t\). Here \(a = 1\), \(\mu = e^t\), and \((e^t y)' = t e^t\). By parts (section 3.5), \(\int t e^t\, dt = (t - 1) e^t\), so \(y = t - 1 + C e^{-t}\). With \(y(0) = 2\), \(C = 3\). The solution forgets its start at rate \(e^{-t}\) and settles onto the line \(t - 1\).
Example: smoothing. \(y' = (u - y)/\tau\), a quantity \(y\) chasing an input \(u\) with time constant \(\tau\): an RC low-pass filter, or a thermometer. For constant \(u\) the integrating factor gives
\[ y(t) = u + (y_0 - u)\, e^{-t/\tau}. \]You have written its discrete version: the exponential moving average y += alpha * (u - y). That is one Euler step of this equation with \(\alpha = h/\tau\). After \(n\) steps the old value's weight is \((1-\alpha)^n \approx e^{-nh/\tau}\).
Every closed-form solution of sections 6.2–6.4 was checked by putting it back into its equation, with derivatives by central differences: the residuals are \(10^{-8}\) or less.
A second-order equation involves \(y''\): acceleration. A mass on a spring obeys \(y'' = -y\) (force pulls back toward 0, in suitable units). The linear ones with constant coefficients,
\[ y'' + b\, y' + c\, y = 0, \]are solved by a guess. Try \(y = e^{rt}\): then \(y' = r e^{rt}\), \(y'' = r^2 e^{rt}\), and the equation becomes \((r^2 + br + c)\, e^{rt} = 0\). So \(e^{rt}\) is a solution exactly when \(r\) is a root of the characteristic equation \(r^2 + br + c = 0\). Two roots give two solutions, and since the equation is linear, any combination \(A e^{r_1 t} + B e^{r_2 t}\) is a solution too. The two constants are fixed by \(y(0)\) and \(y'(0)\): a second-order equation needs a position and a velocity to start [boyce].
\(y'' = y\). \(r^2 = 1\), \(r = \pm 1\): \(e^t\) and \(e^{-t}\). Their even and odd combinations are \(\cosh t\) and \(\sinh t\) (section 4.5), which are the convenient basis because \(\cosh 0 = 1\), \(\cosh' 0 = 0\), \(\sinh 0 = 0\), \(\sinh' 0 = 1\):
\[ y'' = y,\ \ y(0) = a,\ y'(0) = b \quad\Longrightarrow\quad y = a \cosh t + b \sinh t. \]\(y'' = -y\). \(r^2 = -1\) has no real root. With complex numbers, \(r = \pm i\) and Euler's formula \(e^{it} = \cos t + i \sin t\) (put \(it\) in the exponential series of section 5.4 and sort the real and imaginary terms) turns them into the real solutions \(\cos t\) and \(\sin t\). Directly: \(\cos'' = -\cos\) and \(\sin'' = -\sin\).
\[ y'' = -y,\ \ y(0) = a,\ y'(0) = b \quad\Longrightarrow\quad y = a \cos t + b \sin t. \]The sign is everything: \(y'' = y\) pushes away from 0 and the solutions grow like \(e^t\); \(y'' = -y\) pulls back and they oscillate forever. This is why cosh and cos have the same series up to signs.
Damping. Add friction proportional to velocity: \(y'' + 2\zeta y' + y = 0\), with damping ratio \(\zeta \ge 0\). The roots are \(r = -\zeta \pm \sqrt{\zeta^2 - 1}\).
These are the three behaviours of any control loop, from a disk head's seek to a PLL.
Several quantities that change together form a system: \(\mathbf{u}' = F(t, \mathbf{u})\), with \(\mathbf{u}\) an array. A higher-order equation becomes a system by naming its derivatives. For \(y'' = -y\), let \(\mathbf{u} = (y, y')\):
\[ \mathbf{u}' = \begin{pmatrix} y' \\ y'' \end{pmatrix} = \begin{pmatrix} u_2 \\ -u_1 \end{pmatrix} = \begin{pmatrix} 0 & 1 \\ -1 & 0 \end{pmatrix} \mathbf{u} = A \mathbf{u}. \]A linear system with constant coefficients is \(\mathbf{u}' = A\mathbf{u}\), with \(A\) a matrix (section 9.1). It is solved like \(y' = ky\): \(\mathbf{u}(t) = e^{At} \mathbf{u}(0)\), where the matrix exponential is defined by the series of section 5.3 with matrix powers, \(e^{At} = I + At + (At)^2/2! + \dots\) [boyce]. For the \(A\) above, \(A^2 = -I\), and the series sorts into the cosine and sine series:
\[ e^{At} = \begin{pmatrix} \cos t & \sin t \\ -\sin t & \cos t \end{pmatrix}, \]a rotation matrix (section 9.6). The state \((y, y')\) goes round a circle; the oscillator conserves \(y^2 + y'^2\) (its energy). Summed numerically at \(t = 1.3\), the series gives the rotation matrix to all 15 printed digits.
For computing, a system is no harder than one equation: every method of the next two sections applies with \(y\) read as an array and each update done entrywise. The oscillator shows what can go wrong. One Euler step (section 6.6) multiplies \(\mathbf{u}\) by \(I + hA\), and
\[ \|(u_1 + h u_2,\; u_2 - h u_1)\|^2 = (1 + h^2)(u_1^2 + u_2^2), \]so every step stretches the radius by \(\sqrt{1 + h^2}\): Euler spirals outward. With \(h = 0.01\), ten turns are 6283 steps, and the radius ends at \((1 + h^2)^{6283/2} = 1.369074\), 37% too big; the computed run gives exactly that. RK4 (section 6.7) with the same step stays on the circle to within \(5 \times 10^{-11}\).
Most ODEs have no formula for their solution. We compute it instead, at times \(t_n = t_0 + nh\) with a step size \(h\). The simplest idea: from the current point, follow the slope for one step.
\[ y_{n+1} = y_n + h\, f(t_n, y_n). \]That is the linear approximation (section 2.4), \(y(t + h) \approx y(t) + h\, y'(t)\), used over and over: Euler's method.
How big is the error? By Taylor's theorem (section 5.5), \(y(t + h) = y(t) + h y'(t) + \tfrac12 h^2 y''(c)\): one step makes a local error of about \(\tfrac12 h^2 y''\). To reach a fixed time \(T\) takes \(T/h\) steps, and the local errors add up (and propagate, which changes the constant but not the power) to a global error of order \((T/h) \cdot h^2 = O(h)\) [burden]. Euler's method is first order: halve the step, halve the error.
On \(y' = y\), \(y(0) = 1\), integrated to \(t = 1\) (exact: \(e\)):
| \(h\) | \(y_n \approx y(1)\) | error | error\(/h\) | ratio to previous |
|---|---|---|---|---|
| 1/10 | 2.593742460100 | \(1.245 \times 10^{-1}\) | 1.2454 | |
| 1/20 | 2.653297705144 | \(6.498 \times 10^{-2}\) | 1.2997 | 1.916 |
| 1/40 | 2.685063838390 | \(3.322 \times 10^{-2}\) | 1.3287 | 1.956 |
| 1/640 | 2.716161207948 | \(2.121 \times 10^{-3}\) | 1.3572 | 1.997 |
| 1/10240 | 2.718149111735 | \(1.327 \times 10^{-4}\) | 1.3590 | 2.000 |
The ratio goes to 2, and error\(/h\) goes to a constant, \(e/2 \approx 1.3591\) (exercise 6 derives it). Every correct digit costs ten times the work: about a million steps for six digits. That is too slow for anything serious, which is why the next section exists.
Euler uses the slope at the start of the step, where it is already out of date. Better: sample the slope at several points inside the step and average. The classical fourth-order Runge–Kutta method (RK4) takes four samples:
\[ \begin{aligned} k_1 &= f(t_n,\; y_n) \\ k_2 &= f(t_n + \tfrac{h}{2},\; y_n + \tfrac{h}{2} k_1) \\ k_3 &= f(t_n + \tfrac{h}{2},\; y_n + \tfrac{h}{2} k_2) \\ k_4 &= f(t_n + h,\; y_n + h k_3) \\ y_{n+1} &= y_n + \tfrac{h}{6} (k_1 + 2k_2 + 2k_3 + k_4) \end{aligned} \]\(k_1\) is Euler's slope. \(k_2\) is the slope at the midpoint reached with \(k_1\); \(k_3\) the slope at the midpoint reached with \(k_2\); \(k_4\) the slope at the end.
Why four samples. The true solution over one step is the Taylor series \(y(t + h) = y + h y' + \tfrac{h^2}{2} y'' + \tfrac{h^3}{6} y^{(3)} + \tfrac{h^4}{24} y^{(4)} + O(h^5)\), where every derivative of \(y\) can be written through \(f\) and its partial derivatives. A method that combines \(s\) slope samples has \(s\) weights and the positions of its samples to choose; requiring its step to agree with the series through \(h^p\) gives a set of equations, the order conditions. One sample can match through \(h\) (Euler), two through \(h^2\) (the midpoint method), and four through \(h^4\). Order 5 needs six samples, not five, which is why four is the sweet spot [hairer].
Why the weights 1, 2, 2, 1. Look at the case where \(f\) depends on \(t\) only. Then \(y(t + h) - y(t) = \int_t^{t+h} f\), and the best three-point rule for that integral is Simpson's, weights \(\tfrac16, \tfrac46, \tfrac16\) at the start, middle and end (section 3.7). When \(f\) depends on \(t\) only, \(k_2 = k_3\) and RK4 is Simpson's rule. In general RK4 splits the middle weight \(\tfrac46\) between two estimates of the midpoint slope, \(k_2\) and \(k_3\). \(k_2\) is taken at a midpoint reached by an Euler half step, \(k_3\) at a better midpoint reached with \(k_2\); their errors in the \(h^2\) and \(h^3\) terms partly cancel when averaged, which is what lets the method reach \(h^4\) when \(f\) depends on \(y\) too. \(k_4\) is the end slope, reached with \(k_3\).
So the local error is \(O(h^5)\) and the global error \(O(h^4)\) [hairer], [burden]. Halve the step and the error drops by 16. Both methods on the logistic equation, where the slope depends on \(y\), against the exact solution of section 6.2:
#include <math.h>
#include <stdio.h>
/* Euler and RK4 on the logistic equation y' = y (1 - y), y(0) = 0.1, up to t = 5.
Exact solution 1 / (1 + 9 e^-t). */
static double f(double t, double y) { (void)t; return y * (1 - y); }
static double euler(double h, int n)
{
double t = 0, y = 0.1;
for (int i = 0; i < n; i++, t += h)
y += h * f(t, y);
return y;
}
static double rk4(double h, int n)
{
double t = 0, y = 0.1;
for (int i = 0; i < n; i++, t += h) {
double k1 = f(t, y);
double k2 = f(t + h / 2, y + h / 2 * k1);
double k3 = f(t + h / 2, y + h / 2 * k2);
double k4 = f(t + h, y + h * k3);
y += h / 6 * (k1 + 2 * k2 + 2 * k3 + k4);
}
return y;
}
int main(void)
{
double exact = 1 / (1 + 9 * exp(-5)), pe = 0, pr = 0;
printf(" h Euler error ratio RK4 error ratio f evals (RK4)\n");
for (int n = 10; n <= 640; n *= 2) {
double h = 5.0 / n;
double ee = fabs(euler(h, n) - exact), er = fabs(rk4(h, n) - exact);
if (pe)
printf("%.5f %.3e %5.2f %.3e %5.2f %d\n", h, ee, pe / ee, er, pr / er, 4 * n);
else
printf("%.5f %.3e %.3e %d\n", h, ee, er, 4 * n);
pe = ee;
pr = er;
}
return 0;
}
h Euler error ratio RK4 error ratio f evals (RK4) 0.50000 8.411e-03 5.032e-05 40 0.25000 3.769e-03 2.23 2.939e-06 17.12 80 0.12500 1.800e-03 2.09 1.785e-07 16.46 160 0.06250 8.809e-04 2.04 1.102e-08 16.21 320 0.03125 4.360e-04 2.02 6.843e-10 16.10 640 0.01562 2.169e-04 2.01 4.264e-11 16.05 1280 0.00781 1.082e-04 2.00 2.662e-12 16.02 2560
How the program maps to the formulas:
f(t, y) is the right side \(f(t, y) = y(1 - y)\). It takes \(t\) although it ignores it, so that both methods are written for the general \(y' = f(t, y)\).euler, the loop body is \(y_{n+1} = y_n + h f(t_n, y_n)\), and t += h advances \(t_n\) to \(t_{n+1}\).rk4, k1 to k4 are \(k_1\) to \(k_4\), in that order because each uses the one before: y + h / 2 * k1 is the Euler estimate of \(y(t_n + h/2)\), y + h / 2 * k2 the improved one, y + h * k3 the estimate of \(y(t_n + h)\). The update h / 6 * (k1 + 2 * k2 + 2 * k3 + k4) is the weighted average slope times \(h\).main runs both with \(n\) steps of \(h = 5/n\) to \(t = 5\) and doubles \(n\) each row, so each ratio column is error\((2h)\)/error\((h)\), which tends to \(2^p\) for a method of order \(p\). The last column counts evaluations of \(f\), four per RK4 step, the real cost.Euler's ratio goes to 2, RK4's to 16, as the orders say. Count the cost in evaluations of \(f\), the expensive part in real problems: RK4 with 160 evaluations (\(h = 0.125\)) is as accurate (\(1.8 \times 10^{-7}\)) as Euler with 400 000 steps. Higher order wins whenever the solution is smooth, the same way Simpson beats the trapezoid rule.
Production solvers go further: they take two estimates of different order from the same samples, use their difference as an error estimate, and adapt \(h\) step by step (embedded Runge–Kutta pairs, such as Dormand–Prince) [hairer], [nr].
Error that shrinks with \(h\) is half the story. The other half is whether it stays bounded at all. Take the test equation
\[ y' = -\lambda y, \qquad \lambda > 0, \]whose solution \(e^{-\lambda t}\) decays to 0. Euler gives \(y_{n+1} = y_n - h\lambda y_n = (1 - h\lambda)\, y_n\), so \(y_n = (1 - h\lambda)^n\). That decays only if \(|1 - h\lambda| < 1\):
Fact. Euler's method on \(y' = -\lambda y\) is stable exactly when \(h < 2/\lambda\). For \(1/\lambda < h < 2/\lambda\) the iterates alternate in sign while they shrink; for \(h > 2/\lambda\) they alternate and grow without bound.
With \(\lambda = 50\), after about \(1/h\) steps (\(t \approx 1\)):
| \(h\) | \(1 - h\lambda\) | Euler | backward Euler |
|---|---|---|---|
| 0.010 | 0.50 | \(7.9 \times 10^{-31}\) | \(2.5 \times 10^{-18}\) |
| 0.030 | −0.50 | \(-1.2 \times 10^{-10}\) | \(7.4 \times 10^{-14}\) |
| 0.039 | −0.95 | \(2.6 \times 10^{-1}\) | \(6.1 \times 10^{-13}\) |
| 0.041 | −1.05 | \(3.2\) | \(2.4 \times 10^{-12}\) |
| 0.050 | −1.50 | \(3.3 \times 10^{3}\) | \(1.3 \times 10^{-11}\) |
The threshold is \(h = 0.04\). At \(h = 0.041\), slightly past it, the decaying solution is computed as one that grows: \(1.05^{24}\). The true answer, \(e^{-50} \approx 2 \times 10^{-22}\), is reached by none of them; but the stable ones at least decay, as the true solution does, while the unstable ones produce a number unrelated to it. RK4 multiplies by \(R(-h\lambda)\) per step, with \(R(z) = 1 + z + z^2/2 + z^3/6 + z^4/24\) (the Taylor polynomial of \(e^z\): on this equation RK4 is exact through \(h^4\)); \(|R(-x)| < 1\) holds up to \(x = 2.785\), so RK4's threshold is \(h \lambda < 2.785\), bigger but still finite: every explicit method, one that computes \(y_{n+1}\) from known values only, has one [hairer].
The cure is an implicit method. Backward Euler uses the slope at the end of the step: \(y_{n+1} = y_n + h f(t_{n+1}, y_{n+1})\). On the test equation, \(y_{n+1} = y_n / (1 + h\lambda)\), which decays for every \(h > 0\). The price: \(y_{n+1}\) appears on both sides, so each step solves an equation (a linear system, for a linear ODE).
An equation is stiff when it has a fast-decaying component next to a slow one you care about. The step size of an explicit method is then set by stability for the fast part, long after that part has died out, not by accuracy for the slow part. Example: \(y' = -1000\,(y - \cos t)\). After a transient of length about \(1/1000\), \(y\) just follows \(\cos t\), a slow and smooth curve. Euler still needs \(h < 2/1000\). Errors near \(t = 1\), from \(y(0) = 0\):
| \(h\) | steps | Euler | backward Euler |
|---|---|---|---|
| 0.001 | 1000 | \(2.7 \times 10^{-7}\) | \(-2.7 \times 10^{-7}\) |
| 0.0019 | 526 | \(5.1 \times 10^{-7}\) | \(-5.2 \times 10^{-7}\) |
| 0.0021 | 476 | \(-5.0 \times 10^{19}\) | \(-5.7 \times 10^{-7}\) |
| 0.1 | 10 | \(-9.0 \times 10^{19}\) | \(-2.8 \times 10^{-5}\) |
Euler is fine at \(h = 0.0019\) and explodes at \(h = 0.0021\), on either side of \(2/1000\). Backward Euler takes ten steps of \(h = 0.1\) and is accurate to \(3 \times 10^{-5}\). Chemical kinetics and circuit simulation (SPICE) are stiff, and their solvers are implicit [burden].
Watch out. The same condition appears whenever a loop does x -= h * (rate proportional to x). Gradient descent on a quadratic is Euler's method on \(x' = -\nabla f(x)\), and its learning rate must stay below \(2/\lambda_{\max}\), with \(\lambda_{\max}\) the steepest curvature (section 7.5). An exponential moving average with \(\alpha > 2\) diverges for the same reason.
\(y' = -ky\), \(y = y_0 e^{-kt}\), and \(e^{-1000k} = 1/2\) gives \(k = \ln 2/1000 \approx 6.93 \times 10^{-4}\) per token.
Separable: \(dy/y = t\, dt\), \(\ln y = t^2/2 + C\), \(y = e^{t^2/2}\). Check: \(y' = t e^{t^2/2} = t y\).
\(\mu = e^{2t}\), \((e^{2t} y)' = 4 e^{2t}\), \(e^{2t} y = 2 e^{2t} + C\), \(y = 2 + C e^{-2t}\); \(y(0) = 0\) gives \(C = -2\): \(y = 2(1 - e^{-2t}) \to 2\).
\(r^2 = -4\), \(r = \pm 2i\): \(y = \cos 2t\). Period \(\pi\).
y += alpha * (u - y) is Euler's method on \(y' = (u - y)/\tau\) with \(\alpha = h/\tau\). For which \(\alpha\) does it converge to \(u\), and for which does it oscillate on the way?
The error \(y - u\) is multiplied by \(1 - \alpha\) per step. It converges for \(0 < \alpha < 2\), monotonically for \(\alpha \le 1\), with alternating overshoot for \(1 < \alpha < 2\). Section 6.8 with \(h\lambda = \alpha\).
\(n \ln(1 + 1/n) = n(1/n - 1/(2n^2) + \dots) = 1 - 1/(2n) + \dots\), so \((1 + 1/n)^n = e \cdot e^{-1/(2n) + \dots} \approx e (1 - 1/(2n))\). The error is \(e/(2n) = (e/2) h\): the constant 1.3591 of the table in section 6.6.
rk4.c to count only RK4 and find the largest \(h\) with error below \(10^{-6}\) at \(t = 5\). Then estimate it from the table without running anything.
From the table: \(2.9 \times 10^{-6}\) at \(h = 0.25\) and \(1.8 \times 10^{-7}\) at \(h = 0.125\). Error \(\approx C h^4\) with \(C \approx 2.9 \times 10^{-6}/0.25^4 \approx 7.5 \times 10^{-4}\), so \(h \approx (10^{-6}/C)^{1/4} \approx 0.19\), about 26 steps. A direct search finds 27 steps (\(h = 0.185\)).
Backward Euler solves \((I - hA)\mathbf{u}_{n+1} = \mathbf{u}_n\). \(I - hA\) stretches every vector by \(\sqrt{1+h^2}\) (the same computation as for \(I + hA\)), so its inverse shrinks by that factor. Both are wrong: one spirals out, one spirals in. For orbits one uses methods that conserve energy (symplectic methods) [hairer].