Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Numerical solutions and error

Chapter 10 - Follow the local rule in finite steps

Many useful differential equations have no solution expressible by a finite combination of familiar elementary functions. Numerical methods turn the rate rule into a sequence of approximations.

Euler's method uses the current slope for one short step:

yn+1=yn+hf(tn,yn),tn+1=tn+h. \boxed{y_{n+1}=y_n+h f(t_n,y_n)},\qquad t_{n+1}=t_n+h.

It is the tangent-line approximation repeated.

Lab: shrink the step

Euler step-size explorerCompare the polygonal approximation with the exact curve.

exact solutionEuler approximation

For each equation, compare h=1h=1, 0.50.5, 0.250.25, and 0.10.1. Smaller steps usually reduce error, but they require more work. "Numerical" does not mean "unreliable"; it means error must be estimated and controlled.

Worked example: show every step

Approximate y′=t−yy'=t-y, y(0)=1y(0)=1, with h=0.5h=0.5three Euler steps
  1. Start. (t0,y0)=(0,1)(t_0,y_0)=(0,1). The slope is f(0,1)=−1f(0,1)=-1.
  2. Step to t=0.5t=0.5. y1=1+0.5(−1)=0.5y_1=1+0.5(-1)=0.5.
  3. Recompute the slope. At (0.5,0.5)(0.5,0.5), f=0.5−0.5=0f=0.5-0.5=0. Do not reuse the old slope.
  4. Step to t=1t=1. y2=0.5+0.5(0)=0.5y_2=0.5+0.5(0)=0.5.
  5. Recompute again. At (1,0.5)(1,0.5), f=0.5f=0.5. Thus y3=0.5+0.5(0.5)=0.75y_3=0.5+0.5(0.5)=0.75 at t=1.5t=1.5.
  6. Behavior check. The state first falls because t−y<0t-y\lt 0, pauses near the line y=ty=t, then rises after t−y>0t-y\gt 0. The discrete values reproduce that qualitative change.

A table is part of the reasoning

nntnt_nyny_nslope f(tn,yn)f(t_n,y_n)next yy
00.01.000-1.0000.500
10.50.5000.0000.500
21.00.5000.5000.750

The table prevents a common error: evaluating the new slope at a mixture of old and new coordinates.

Local and global error

Euler replaces a curved segment by a tangent step. If the exact solution has bounded second derivative, one step's local truncation error (the unscaled one-step defect from exact starting data) is O(h2)O(h^2). Some texts divide this defect by hh and call the result local truncation error instead. If ff is also Lipschitz in the state near the solution, accumulation across a fixed time interval gives global error O(h)O(h). These are upper-order bounds; special solutions can have zero error.

Practical consequence: halving hh should roughly halve Euler's global error once the steps are small enough for this small-step pattern to appear.

Error estimate. Euler with h=0.2h=0.2 has error about 0.08 at a fixed final time. What error would first-order behavior predict for h=0.1h=0.1?

Better slopes: midpoint and Runge-Kutta

Euler uses the slope at the start of a step. A midpoint method samples a slope near the middle. Classical fourth-order Runge-Kutta blends four slope samples. The central design idea is the same: spend more rate evaluations to approximate the curve across each step more accurately.

You do not need to memorize this fourth-order method, often called RK4, here. You should be able to ask:

  • where does the method sample slopes?
  • what order of global error does it claim?
  • does halving the step produce the expected convergence?
  • does the numerical curve respect known equilibria, signs, and bounds?

Numerical stability is not physical stability

For y′=−10yy'=-10y, the true solution decays. Euler gives

yn+1=(1−10h)yn. y_{n+1}=(1-10h)y_n.

If h=0.3h=0.3, the multiplier is −2-2: the approximation alternates and grows even though the true system decays. The step is too large for Euler's stability region.

Error clinic: trusting a smooth-looking plot

A plotting tool can connect inaccurate points smoothly. Test convergence by rerunning with a smaller step, and compare the result with qualitative facts from the differential equation.

Fade the computation

Use Euler with h=0.25h=0.25 for y′=y(1−y)y'=y(1-y), y(0)=0.2y(0)=0.2.

  1. y1=0.2+0.25[0.2(0.8)]=‾y_1=0.2+0.25[0.2(0.8)]=\underline{\hspace{4em}}.
  2. Evaluate the next slope at (t1,y1)=(0.25,‾)(t_1,y_1)=(0.25,\underline{\hspace{3em}}).
  3. Compute y2y_2 and confirm that the approximation stays between 0 and 1.
Check two steps

y1=0.24y_1=0.24. Then the slope is 0.24(0.76)=0.18240.24(0.76)=0.1824, so y2=0.24+0.25(0.1824)=0.2856y_2=0.24+0.25(0.1824)=0.2856. Both points respect the phase-line prediction of growth toward 1.

Practice

  1. Practice - Euler table

    10.1 Use Euler with h=0.2h=0.2 to approximate y(0.6)y(0.6) for y′=y−ty'=y-t, y(0)=1y(0)=1. Show a slope table.

    Detailed solution

  2. Practice - convergence

    10.2 For y′=yy'=y, y(0)=1y(0)=1, derive Euler's approximation yn=(1+h)ny_n=(1+h)^n. Compare h=1,1/2,1/4h=1,1/2,1/4 at t=1t=1 with ee.

    Detailed solution

  3. Integrated - qualitative check

    10.3 Design a test that would catch a numerical solution of P′=P(1−P/10)P'=P(1-P/10), P(0)=2P(0)=2, crossing above 10.

    Detailed solution

  4. Challenge - step stability

    10.4 For y′=−ayy'=-ay with a>0a\gt 0, find all h>0h\gt 0 for which Euler approximations decay in magnitude. Which subset decays without alternating sign?

    Detailed solution

  5. Practice - extension

    10.5 The explicit midpoint method uses k1=f(tn,yn)k_1=f(t_n,y_n), k2=f(tn+h/2,yn+hk1/2)k_2=f(t_n+h/2,y_n+hk_1/2), and yn+1=yn+hk2y_{n+1}=y_n+hk_2. Apply two steps with h=0.5h=0.5 to y′=y−t, y(0)=0y'=y-t,\ y(0)=0. Compare y(1)y(1) with two Euler steps and the exact value from y=t+1−ety=t+1-e^t.

    Detailed solution

  6. Challenge - transfer

    10.6 For z′=rz(1−z)z'=rz(1-z), r>0r\gt 0, Euler gives zn+1=zn+hrzn(1−zn)z_{n+1}=z_n+hrz_n(1-z_n). Show that 0<zn<10\lt z_n\lt 1 implies 0<zn+1<10\lt z_{n+1}\lt 1 whenever 0<hr≤10\lt hr\le1. Test r=1, h=2, z0=0.75r=1,\ h=2,\ z_0=0.75 to demonstrate overshoot, and explain why a bound-preserving step is not automatically accurate.

    Detailed solution

Retrieve the whole loop

Choose one equation from any earlier chapter and state:

  1. its structural fingerprint;
  2. a qualitative prediction;
  3. an analytic method, if available;
  4. a numerical fallback; and
  5. two independent checks.

Next: Enter the mixed practice studio, where the method is never named for you.