MathLabs

Applied and computational mathematics

Numerical solution of differential equations

Step-by-step methods like Euler's and Runge–Kutta that approximate solutions when exact formulas are unavailable.

IntuitionApproximating a curve one small step at a time

Most differential equations that appear in physics, engineering, and finance have no closed form written with elementary functions. Numerical methods replace the exact curve y(t)y(t) by a sequence of approximations y0,y1,y2,…y_0, y_1, y_2, \ldots, computed step by step using only the slope f(t,y)f(t,y) that the equation provides at each point. The smaller the step size hh, the closer the broken line of approximations hugs the true curve — but smaller steps also mean more arithmetic, so every method balances accuracy against cost.

Interactive plot showing a secant line converging to the tangent line as the step shrinks, illustrating the linear approximation behind Euler's method.
Zooming from a secant line into a tangent line at t0t_0: an Euler step follows exactly this tangent direction for a distance hh before recomputing the slope.

SchoolEuler's method

Definition: Euler's method (explicit)

Given the initial value problem y′=f(t,y)y' = f(t, y) with y(t0)=y0y(t_0) = y_0, choose a step size hh and set tn=t0+nht_n = t_0 + nh. Euler's method advances the approximation using the update rule yn+1=yn+hf(tn,yn)y_{n+1} = y_n + h f(t_n, y_n), repeating for n=0,1,2,…n=0,1,2,\ldots.

y′=f(t,y),y(t0)=y0y' = f(t, y), \qquad y(t_0) = y_0

Here f(t,y)f(t,y) is the given slope function, hh is the fixed step size, and yny_n is the approximation to the true value y(tn)y(t_n) produced after nn steps. Each step simply follows the tangent line predicted by f(t,y)f(t,y) at the current point for a horizontal distance hh, then re-evaluates the slope at the new point — geometrically the picture is a chain of straight segments approximating the curve.

yn+1=yn+hf(tn,yn)y_{n+1} = y_n + h f(t_n, y_n)
Comparing step-by-step methods for y′=f(t,y)y'=f(t,y)
MethodEvaluations of ff per stepGlobal error orderSuitable for stiff equations?
Explicit Euler1O(h)O(h)No (needs a very small hh)
Classical RK44O(h4)O(h^4)No (still needs small hh for stiff problems)
Implicit Euler1 (plus solving one equation)O(h)O(h)Yes (A-stable for any h>0h>0)

UndergraduateConvergence: how accurate is each method?

Suppose f(t,y)f(t,y) is Lipschitz continuous in yy with constant LL, and the exact solution satisfies ∣y′′(t)∣≤M|y''(t) | \le M on [t0,T][t_0, T]. Then the global error en=y(tn)−yne_n = y(t_n) - y_n after nn steps of size hh obeys ∣en∣≤hM2L(eL(tn−t0)−1)|e_n| \le \frac{hM}{2L}\left(e^{L(t_n-t_0)}-1\right).

Why is it true?

Each individual Euler step commits a small local error of size O(h2)O(h^2) from truncating the Taylor series after the linear term, but these local errors can compound over the roughly (T−t0)/h(T-t_0)/h steps needed to reach a fixed time TT. The theorem shows the compounding is mild: the Lipschitz condition prevents small local mistakes from being amplified faster than exponentially, so the global error drops to first order, O(h)O(h), in the step size — one order worse than the local error, which is the typical pattern for one-step methods.

Proof

Write the local error committed in one step as the difference between the exact solution advanced by Taylor expansion and the Euler update. Taylor's theorem gives y(tn+1)=y(tn)+hf(tn,y(tn))+h22y′′(ξn)y(t_{n+1}) = y(t_n) + h f(t_n, y(t_n)) + \frac{h^2}{2} y''(\xi_n) for some ξn\xi_n between tnt_n and tn+1t_{n+1}, so the local truncation error is τn=h22y′′(ξn)\tau_n = \frac{h^2}{2} y''(\xi_n), bounded by h2M2\frac{h^2 M}{2} using the assumption ∣y′′(t)∣≤M|y''(t) | \le M.

Subtract the Euler update yn+1=yn+hf(tn,yn)y_{n+1} = y_n + h f(t_n, y_n) from this exact Taylor expansion. Writing en=y(tn)−yne_n = y(t_n) - y_n, the difference of the two right-hand sides gives en+1=en+h[f(tn,y(tn))−f(tn,yn)]+τne_{n+1} = e_n + h\left[f(t_n, y(t_n)) - f(t_n, y_n)\right] + \tau_n. The Lipschitz condition bounds the bracketed term by L∣en∣L|e_n|, so ∣en+1∣≤(1+hL)∣en∣+h2M2|e_{n+1}| \le (1+hL)|e_n| + \frac{h^2 M}{2}.

Since e0=0e_0 = 0 (the starting value is exact), unrolling this recursion by induction gives ∣en∣≤h2M2∑k=0n−1(1+hL)k=hM2L[(1+hL)n−1]|e_n| \le \frac{h^2M}{2}\sum_{k=0}^{n-1}(1+hL)^k = \frac{hM}{2L}\left[(1+hL)^n - 1\right], using the geometric-series identity. Finally, (1+hL)n≤eLhn=eL(tn−t0)(1+hL)^n \le e^{Lhn} = e^{L(t_n-t_0)} because 1+x≤ex1+x\le e^x for all real xx, which turns the bound into ∣en∣≤hM2L(eL(tn−t0)−1)|e_n| \le \frac{hM}{2L}\left(e^{L(t_n-t_0)}-1\right) — exactly the claimed inequality, and manifestly O(h)O(h) for fixed tnt_n.

The classical fourth-order Runge–Kutta method, defined by the stages k1=f(tn,yn)k_1 = f(t_n, y_n), k2=f(tn+h2,yn+h2k1)k_2 = f\left(t_n+\frac{h}{2}, y_n+\frac{h}{2}k_1\right), k3=f(tn+h2,yn+h2k2)k_3 = f\left(t_n+\frac{h}{2}, y_n+\frac{h}{2}k_2\right), k4=f(tn+h,yn+hk3)k_4 = f(t_n+h, y_n+hk_3) and update yn+1=yn+h6(k1+2k2+2k3+k4)y_{n+1} = y_n + \frac{h}{6}(k_1+2k_2+2k_3+k_4), has local truncation error O(h5)O(h^5) per step and, under the same Lipschitz assumption as before, global error O(h4)O(h^4) after nn steps.

Why is it true?

RK4 evaluates the slope four times per step at cleverly chosen intermediate points instead of once, and averages them with weights 1,2,2,11,2,2,1 (out of 66). This extra work buys three more orders of accuracy compared to Euler's method: matching the Taylor expansion of the true solution through the h4h^4 term, instead of stopping after the linear term.

Proof

Expand each stage in a Taylor series around (tn,yn)(t_n, y_n). Since k1=f(tn,yn)=y′(tn)k_1=f(t_n,y_n)=y'(t_n), and k2,k3k_2, k_3 evaluate ff at the midpoint using yny_n shifted by half a step in the direction of an earlier stage, substituting the chain rule for y′=fy'=f, y′′=ft+fyfy''=f_t+f_yf, and y′′′=ftt+2ftyf+fyyf2+fy(ft+fyf)y'''=f_{tt}+2f_{ty}f+f_{yy}f^2+f_y(f_t+f_yf) into each kik_i produces four polynomials in hh agreeing with y′(tn),y′′(tn),y′′′(tn)y'(t_n), y''(t_n), y'''(t_n) up to the orders that each stage can see.

Forming the weighted combination 16(k1+2k2+2k3+k4)\frac{1}{6}(k_1+2k_2+2k_3+k_4) and multiplying by hh, the coefficients of h1,h2,h3h^1, h^2, h^3 and h4h^4 in this sum are exactly the coefficients of the Taylor expansion y(tn+h)=y(tn)+hy′(tn)+h22y′′(tn)+h36y′′′(tn)+h424y(4)(tn)+⋯y(t_n+h) = y(t_n) + hy'(t_n) + \frac{h^2}{2}y''(t_n) + \frac{h^3}{6}y'''(t_n) + \frac{h^4}{24}y^{(4)}(t_n) + \cdots through the h4h^4 term — this is precisely the classical set of order conditions that the coefficients c=(0,12,12,1)c=(0,\frac12,\frac12,1) and b=(16,13,13,16)b=(\frac16,\frac13,\frac13,\frac16) of the RK4 tableau were chosen to satisfy.

Because the two series agree through h4h^4, the first term where they can differ is the O(h5)O(h^5) term, so the local truncation error is O(h5)O(h^5) per step. As in the Euler case, telescoping these local errors over the n≈(T−t0)/hn\approx (T-t_0)/h steps needed to reach a fixed time using the Lipschitz condition on ff loses exactly one power of hh, giving a global error of O(h4)O(h^4).

AdvancedStiff equations and implicit methods

A differential equation is called stiff when it mixes very different time scales: some components of the solution decay extremely fast while others change slowly, forcing explicit methods to take tiny steps just to stay numerically stable, even though accuracy alone would allow much larger ones. For the simple test equation y′=λyy'=\lambda y with λ<0\lambda<0, Euler's method is stable only when ∣1+hλ∣≤1|1+h\lambda|\le 1 holds, i.e. when h≤2∣λ∣h \le \frac{2}{|\lambda|}, so a strongly negative λ\lambda (a fast-decaying mode) forces hh to be tiny.

yn+1=yn+hf(tn+1,yn+1)y_{n+1} = y_n + h f(t_{n+1}, y_{n+1})

Implicit methods such as backward (implicit) Euler, yn+1=yn+hf(tn+1,yn+1)y_{n+1} = y_n + h f(t_{n+1}, y_{n+1}), require solving an equation for yn+1y_{n+1} at every step (often by Newton's method when ff is nonlinear), but in exchange they remain stable for any step size on this test equation — a property called A-stability — which is exactly what is needed for stiff systems arising in chemical kinetics, circuit simulation, and control theory.

UndergraduateReal-World Applications and Worked Examples

Numerical integrators for differential equations are the computational backbone of simulation software: they advance the state of a physical or financial system forward in time using nothing but the governing equation and a starting condition. Circuit simulators use them to predict voltages and currents, orbital mechanics software uses them to propagate satellite trajectories, chemical engineers use stiff solvers to model fast reaction networks, and quantitative finance uses them to simulate interest-rate and option-pricing models.

Example: Discharging an RC circuit with Euler's method

A capacitor in an RC circuit discharges according to dVdt=−V\frac{dV}{dt} = -V (time measured in units of RCRC) with initial voltage V(0)=5V(0)=5. Use Euler's method with step h=0.1h=0.1 to estimate V(0.2)V(0.2).

Solution

Here f(t,V)=−Vf(t,V) = -V, so the update rule is simply Vn+1=Vn−hVn=(1−h)VnV_{n+1} = V_n - hV_n = (1-h)V_n with h=0.1h=0.1.

First step: V1=V0−hV0=5−0.1(5)=4.5V_1 = V_0 - h V_0 = 5 - 0.1(5) = 4.5.

Second step: V2=V1−hV1=4.5−0.1(4.5)=4.05V_2 = V_1 - hV_1 = 4.5 - 0.1(4.5) = 4.05, so the Euler estimate is V(0.2)≈4.05V(0.2)\approx 4.05.

The exact solution is V(t)=5e−tV(t) = 5e^{-t}, giving 5e−0.2≈4.09375e^{-0.2}\approx 4.0937, so the two-step Euler estimate is off by about 0.0440.044 — consistent with a first-order, O(h)O(h), global error that shrinks proportionally to hh.

Example: Why a fast reaction forces a tiny step size

A simplified chemical kinetics model has a fast-decaying transient governed by y′=−50(y−cos⁡t)y' = -50(y-\cos t) with y(0)=0y(0)=0. Determine the largest step size for which explicit Euler's method stays numerically stable, and explain what changes if implicit Euler is used instead.

Solution

Near the fast transient the equation behaves like the linear test equation y′≈−50yy'\approx -50y, so the relevant value is λ=−50\lambda=-50. Explicit Euler is stable exactly when ∣1+hλ∣≤1|1+h\lambda|\le 1, which for λ=−50\lambda=-50 becomes ∣1−50h∣≤1|1-50h|\le 1, i.e. 0≤h≤0.040\le h\le 0.04 — a very small ceiling even though the slow part of the solution barely changes over that interval.

If hh is chosen larger than 0.040.04, the numerical values start oscillating with growing amplitude even though the true solution is smooth and bounded: this is a stability failure, not an accuracy failure, because the local truncation error would actually be acceptable at a much larger hh.

Switching to implicit Euler, yn+1=yn+hf(tn+1,yn+1)y_{n+1} = y_n + h f(t_{n+1}, y_{n+1}), the stability requirement for the same test equation becomes ∣11−hλ∣≤1\left|\frac{1}{1-h\lambda}\right|\le 1, which holds for every h>0h>0 when λ<0\lambda<0: the method is A-stable, so the step size can instead be chosen based purely on how accurately the slow part of the solution needs to be tracked, not on the fast transient.

Using Euler's method with y′=yy'=y, y(0)=1y(0)=1, and step size h=0.5h=0.5, what is the approximation y1y_1 after one step?

What is the global order of accuracy of the classical fourth-order Runge–Kutta (RK4) method?

When explicit Euler is applied to a stiff differential equation, what typically happens if the step size is only slightly larger than the stability threshold?

Which of the following is a typical real-world use of numerical differential-equation solvers?

References

  1. J. C. Butcher (2016). Numerical Methods for Ordinary Differential Equations
  2. E. Hairer, S. P. Norsett, G. Wanner (1993). Solving Ordinary Differential Equations I: Nonstiff Problems