Intuition What this page is for
The parent note built the two engines: Shooting and Finite Difference. This page drives both through every road condition — linear, nonlinear, convection terms, degenerate grids, limiting refinement, a physics word problem, and a sneaky exam twist. Each example is tagged with the matrix cell it fills, so you can see there are no gaps.
Before we start, a self-contained toolkit — every symbol used below, defined right here.
Definition The linear-BVP finite-difference template (defined here, used everywhere below)
A general linear second-order BVP is written
y ′′ = p ( x ) y ′ + q ( x ) y + r ( x ) , y ( a ) = α , y ( b ) = β .
==p ( x ) == multiplies the first derivative y ′ — the convection term (a "drift" that pushes one direction).
==q ( x ) == multiplies y itself — the reaction/stiffness term.
==r ( x ) == is the source — everything with no y in it (forcing, heating).
Chop [ a , b ] into N equal steps of width h = N b − a ; interior nodes are x 1 , … , x N − 1 . Replacing y ′ and y ′′ by central differences and multiplying by h 2 gives, at each interior node i , the three-coefficient stencil :
lower ( 1 + 2 h p i ) y i − 1 diag − ( 2 + h 2 q i ) y i + upper ( 1 − 2 h p i ) y i + 1 = RHS h 2 r i .
where p i = p ( x i ) , etc. This is the only FDM formula we use; each example just plugs numbers into it.
Common mistake Three traps we flag inline (defined here, referenced by name below)
Trap "RHS": the known boundary values y 0 = α and y N = β must be moved to the right-hand side when they appear in the stencil at i = 1 or i = N − 1 . Forget this and your matrix has the wrong size.
Trap "refine": never trust a single grid. Halve h and check the error drops ≈ 4 × (because central differences are O ( h 2 ) ). If it doesn't, the setup is wrong.
Trap "order": use the central difference for y ′ (it is O ( h 2 ) ); a one-sided forward difference is only O ( h ) and drags the whole scheme to first order.
Two more words we lean on constantly:
Interior node : a grid point strictly between the two ends — the ones we must solve for . The ends are already given.
Residual : how far our current answer is from satisfying the rule. For shooting it is ϕ ( s ) = y ( b ; s ) − β : the gap between where our shot landed and the bucket β .
Cell
What makes it different
Example
A. Linear + shooting
ϕ ( s ) is a straight line → exact in 2 shots
Ex 1
B. Nonlinear + shooting
ϕ ( s ) is curved → must iterate secant
Ex 2
C. Linear FDM, p = 0
symmetric tridiagonal, no convection
Ex 3
D. Linear FDM, p = 0
asymmetric off-diagonals (convection)
Ex 4
E. Degenerate grid (N = 2 )
only ONE interior node → single equation
inside Ex 3
F. Limiting case: refine h
check error falls ∝ h 2 (halve h → 4 1 error)
Ex 5
G. Sign check: which side did we land?
overshoot vs undershoot, negative residual
Ex 6
H. Real-world word problem
heated rod, units, physical read-off
Ex 7
I. Exam twist: derivative (Neumann) boundary
y ′ ( b ) given, not y ( b ) → ghost node
Ex 8
Every method-cell (A–I) is hit at least once below.
y ′′ = 4 y , y ( 0 ) = 0 , y ( 1 ) = sinh 2 by shooting.
True solution is y = sinh ( 2 x ) , so y ′ ( 0 ) = 2 . Pretend we don't know that.
Forecast: the ODE is linear , so how many shots do we need before the answer is exact — 2, 5, or "infinitely many"?
Shot 1: guess s 0 = 0 . Solving y ′′ = 4 y , y ( 0 ) = 0 , y ′ ( 0 ) = 0 gives y ≡ 0 , so y ( 1 ; 0 ) = 0 .
Why this step? We need one data point ( s , landing ) . Zero slope is the cheapest probe — it tells us the baseline landing.
Shot 2: guess s 1 = 1 . By linearity y = 2 1 sinh ( 2 x ) (slope-1 solution), so y ( 1 ; 1 ) = 2 1 sinh 2 ≈ 1.8134 .
Why this step? A line needs two points. Now we know ϕ at two slopes.
Interpolate to the root. Target β = sinh 2 ≈ 3.6269 :
s ⋆ = s 0 + ( s 1 − s 0 ) y ( 1 ; s 1 ) − y ( 1 ; s 0 ) β − y ( 1 ; s 0 ) = 0 + 1 ⋅ 1.8134 − 0 3.6269 − 0 = 2.0.
Why this step? For linear ODEs y ( b ; s ) is a straight line in s , so the exact root is one interpolation away — no iteration.
Verify: s ⋆ = 2 matches the true y ′ ( 0 ) = 2 exactly. Forecast answer: 2 shots. ✓
y ′′ = y 2 , y ( 0 ) = 0 , y ( 1 ) = 1 by shooting.
Because of the y 2 the ODE is nonlinear , so ϕ ( s ) is a curve , not a line.
Forecast: will two shots nail it, or will the residual still be nonzero after interpolating twice?
For a clean, checkable arithmetic we use the secant formula on made-up-but-consistent landing data. Suppose our IVP solver returns:
y ( 1 ; s 0 = 0.5 ) = 0.60 , y ( 1 ; s 1 = 1.0 ) = 1.30.
Target β = 1 , so residuals ϕ 0 = 0.60 − 1 = − 0.40 , ϕ 1 = 1.30 − 1 = + 0.30 .
Secant step.
s 2 = s 1 − ϕ 1 ϕ 1 − ϕ 0 s 1 − s 0 = 1.0 − 0.30 ⋅ 0.30 − ( − 0.40 ) 1.0 − 0.5 .
Why this step? We approximate the curve ϕ ( s ) by the straight line through the last two points and hit its root — the secant idea, no derivative of ϕ needed.
Arithmetic. 0.70 0.5 = 0.7143 ; 0.30 × 0.7143 = 0.2143 ; so s 2 = 1.0 − 0.2143 = 0.7857 .
Why this step? This is the next, better slope guess.
Not done! We must fire a new IVP at s 2 , get a new residual, and repeat — because the true ϕ curves away from our line.
Why this step? On a curved ϕ , one secant line only approximates the root; iteration drives ∣ ϕ ∣ → tol.
Verify: the residual straddled zero (ϕ 0 < 0 < ϕ 1 ), so the root is bracketed between 0.5 and 1.0 ; our s 2 = 0.7857 lands inside — a sane secant step. Forecast answer: iterate, not two shots. ✓
y ′′ = y , y ( 0 ) = 0 , y ( 1 ) = sinh 1 , take N = 2 so h = 0.5 .
Match to the template: p = 0 , q = 1 , r = 0 . With N = 2 there is exactly one interior node x 1 = 0.5 — the degenerate case.
Forecast: with only one unknown, how many equations do we solve — a system, or a single line?
Write the grouped stencil using the template with p = 0 , q = 1 :
( 1 ) y 0 − ( 2 + h 2 ) y 1 + ( 1 ) y 2 = 0.
Why this step? Substituting p = 0 kills the off-diagonal asymmetry (lower = upper = 1 ); q = 1 , h 2 = 0.25 fixes the middle coefficient.
Insert boundary values y 0 = 0 , y 2 = sinh 1 = 1.1752 :
0 − 2.25 y 1 + 1.1752 = 0.
Why this step? y 0 , y N are known numbers — move them to the RHS (Trap "RHS" ).
Solve the one equation. y 1 = 2.25 1.1752 = 0.5223.
Why this step? One interior node ⇒ the tridiagonal system collapses to a single scalar equation (Cell E).
Verify: true sinh ( 0.5 ) = 0.5211 ; error ≈ 0.0012 . Small even with 2 intervals, and it will shrink like h 2 (proved next). ✓
y ′′ = 2 y ′ − y + e x , y ( 0 ) = 1 , y ( 1 ) = e , take N = 4 so h = 0.25 . Write the equation at node i = 1 (x 1 = 0.25 ).
Match to the template: p = 2 , q = − 1 , r = e x . Now the off-diagonals differ — that asymmetry is the convection.
Forecast: will the coefficient multiplying y i − 1 (lower) be bigger or smaller than the one on y i + 1 (upper)?
Compute the three coefficients with h = 0.25 :
lower = 1 + 2 h p = 1 + 0.25 = 1.25 ,
diag = − ( 2 + h 2 q ) = − ( 2 + 0.0625 ⋅ ( − 1 )) = − ( 2 − 0.0625 ) = − 1.9375 ,
upper = 1 − 2 h p = 1 − 0.25 = 0.75 .
Why this step? Direct substitution into the template's lower/diag/upper slots.
RHS = h 2 e x 1 = 0.0625 e 0.25 = 0.0625 ⋅ 1.2840 = 0.08025 .
Why this step? r ( x ) = e x evaluated at the node, scaled by h 2 .
Equation at i = 1 (with y 0 = 1 moved right):
− 1.9375 y 1 + 0.75 y 2 = 0.08025 − 1.25 ( 1 ) = − 1.16975.
Why this step? y 0 is known; subtract 1.25 y 0 to the RHS (Trap "RHS" ).
Verify: with p = 2 > 0 , the term 2 h p adds to the lower (1.25 ) but subtracts from the upper (0.75 ), so lower > upper — the upwind side is heavier, exactly what positive convection produces. Forecast answer: lower is bigger. ✓
Worked example Take the FDM of Ex 3 (
y ′′ = y , exact sinh ) at x = 0.5 for N = 2 and N = 4 . Confirm the error quarters.
Forecast: halving h (from 0.5 to 0.25 ) should shrink the error by a factor of about... 2, 4, or 8?
N = 2 error (Ex 3): ∣0.5223 − 0.5211∣ = 0.00122 .
Why this step? This is our coarse-grid benchmark.
Set up the N = 4 system explicitly. Now h = 0.25 , h 2 = 0.0625 ; interior nodes x 1 = 0.25 , x 2 = 0.5 , x 3 = 0.75 . With p = 0 , q = 1 every diagonal is − ( 2 + h 2 ) = − 2.0625 and every off-diagonal is 1 . Boundaries y 0 = 0 , y 4 = sinh 1 = 1.1752 go to the RHS (Trap "RHS" ), so
⎩ ⎨ ⎧ − 2.0625 y 1 + y 2 = − y 0 = 0 , y 1 − 2.0625 y 2 + y 3 = 0 , y 2 − 2.0625 y 3 = − y 4 = − 1.1752.
Why this step? A finer grid means three coupled interior equations — a genuine tridiagonal system.
Solve by the Thomas method (forward-eliminate, back-substitute).
Row 1: y 1 = y 2 /2.0625 .
Substitute into row 2: ( y 2 /2.0625 ) − 2.0625 y 2 + y 3 = 0 ⇒ − 1.5776 y 2 + y 3 = 0 ⇒ y 3 = 1.5776 y 2 .
Substitute into row 3: y 2 − 2.0625 ( 1.5776 y 2 ) = − 1.1752 ⇒ y 2 ( 1 − 3.2538 ) = − 1.1752 ⇒ y 2 = − 2.2538 − 1.1752 = 0.52140.
Why this step? Thomas is just Gaussian elimination that exploits the tridiagonal shape — eliminate below the diagonal, then back-substitute for the value we want, y 2 = y ( 0.5 ) .
N = 4 error: ∣0.52140 − 0.52110∣ = 0.00030 . Ratio 0.00030 0.00122 ≈ 4.1 .
Why this step? This is the observed error-shrink factor.
Verify: the central stencil is O ( h 2 ) , so halving h predicts × 4 1 error. We saw ≈ 4.1 × smaller — matches (Trap "refine" : always refine to trust). Forecast answer: factor 4. ✓
Figure: three shooting attempts for y ′′ = y , y ( 0 ) = 0 , all launched from the left end. The magenta curve (slope s 0 = 0 ) stays flat and ends below the navy dashed "bucket" line β = sinh 1 — an undershoot. The violet curve (slope s 1 = 2 ) rises steeply and ends above the bucket — an overshoot. The orange curve (slope s ⋆ = 1 ) lands exactly on the bucket. Read the sign of the residual straight off the picture: below the dashed line ⇒ ϕ < 0 , above ⇒ ϕ > 0 , on it ⇒ ϕ = 0 .
y ′′ = y , y ( 0 ) = 0 , y ( 1 ) = sinh 1 ≈ 1.1752 , interpret the two shooting shots by sign .
Forecast: if we shoot with slope s 0 = 0 , do we land short of or beyond the bucket β ?
Shot s 0 = 0 : y ( 1 ; 0 ) = 0 . Residual ϕ 0 = 0 − 1.1752 = − 1.1752 < 0 .
Why this step? A negative residual means we landed below/short of the target — undershoot. In the figure this is the magenta path ending below the navy dashed bucket line.
Shot s 1 = 2 : y ( 1 ; 2 ) = 2 sinh 1 ≈ 2.3504 . Residual ϕ 1 = 2.3504 − 1.1752 = + 1.1752 > 0 .
Why this step? A positive residual means we shot over — the violet path ends above the bucket.
Root is bracketed. Since ϕ 0 < 0 < ϕ 1 , the true slope lies between 0 and 2 ; interpolation lands at s ⋆ = 1 (the orange path, which touches the bucket).
Why this step? Opposite signs guarantee a crossing — the geometric meaning of "aim between a short shot and a long shot."
Verify: s ⋆ = 0 + 2 ⋅ 2.3504 − 0 1.1752 − 0 = 1.0 , the true slope. Sign logic and root agree. ✓
Worked example A rod of length
L = 1 m conducts heat with an internal source. Steady temperature T ( x ) obeys
T ′′ = − 100 ( ∘ C / m 2 ) , T ( 0 ) = 2 0 ∘ C , T ( 1 ) = 2 0 ∘ C .
Estimate the mid-rod temperature T ( 0.5 ) by FDM with N = 2 (h = 0.5 ).
Forecast: with both ends at 2 0 ∘ and heating inside, is the middle hotter or cooler than 2 0 ∘ ?
Match to the template. Rewrite T ′′ = 0 ⋅ T ′ + 0 ⋅ T + ( − 100 ) , so p = 0 , q = 0 , r = − 100 .
Why this step? Reading off p , q , r lets us reuse the one stencil formula.
Stencil at x 1 = 0.5 , h 2 = 0.25 : y 0 − 2 y 1 + y 2 = h 2 r = 0.25 ( − 100 ) = − 25.
Why this step? p = q = 0 gives the pure "1, −2, 1" stencil; the RHS carries the source r .
Insert T 0 = T 2 = 20 : 20 − 2 T 1 + 20 = − 25 ⇒ − 2 T 1 = − 65 ⇒ T 1 = 32. 5 ∘ C .
Why this step? Both ends known; single equation gives the midpoint (Trap "RHS" applied).
Verify: exact solution T = 20 + 50 x ( 1 − x ) gives T ( 0.5 ) = 20 + 50 ( 0.25 ) = 32. 5 ∘ C — matches exactly (for constant r the central stencil is exact on this parabola). Units are ∘ C throughout. Forecast answer: hotter, 32. 5 ∘ . ✓
y ′′ = y , y ( 0 ) = 0 , y ′ ( 1 ) = cosh 1 ≈ 1.5431 (a slope given at the right end). Take N = 2 , h = 0.5 ; set up the equations.
The right boundary is now a derivative , not a value — the classic exam curveball.
Forecast: at x = 1 we have no y 2 value handed to us. Where does the missing equation come from?
Introduce a ghost node y 3 at x 3 = 1.5 (just outside the rod) and write the central derivative at the boundary node x 2 = 1 :
y ′ ( 1 ) ≈ 2 h y 3 − y 1 = cosh 1 ⇒ y 3 = y 1 + 2 h cosh 1 = y 1 + 1.5431.
Why this step? Using a central (not one-sided) difference at the boundary keeps O ( h 2 ) accuracy (Trap "order" ). The ghost node y 3 is the fictitious value the central formula needs.
Write the y ′′ = y stencil at BOTH unknown nodes i = 1 , 2 (here p = 0 , q = 1 , h 2 = 0.25 , diag = − 2.25 ):
i = 1 : y 0 − 2.25 y 1 + y 2 = 0 , i = 2 : y 1 − 2.25 y 2 + y 3 = 0.
Why this step? Node 2 is now an unknown (only its slope was given, not its value), so it needs its own stencil equation — and that equation contains the ghost y 3 .
Eliminate the ghost. Substitute y 3 = y 1 + 1.5431 (from step 1) into the node-2 equation:
y 1 − 2.25 y 2 + ( y 1 + 1.5431 ) = 0 ⇒ 2 y 1 − 2.25 y 2 = − 1.5431.
Why this step? The ghost value is now expressed in terms of a real unknown plus known data, so it disappears and we are left with a solvable 2 × 2 system.
Solve the 2 × 2 with y 0 = 0 :
from i = 1 : − 2.25 y 1 + y 2 = 0 ⇒ y 2 = 2.25 y 1 . Sub into step-3 equation: 2 y 1 − 2.25 ( 2.25 y 1 ) = − 1.5431 ⇒ ( 2 − 5.0625 ) y 1 = − 1.5431 ⇒ y 1 = − 3.0625 − 1.5431 = 0.5039. Then y 2 = 1.1338.
Why this step? Back-substitution — the Thomas idea by hand for a tiny system.
Verify: exact y = sinh x gives sinh ( 0.5 ) = 0.5211 and sinh ( 1 ) = 1.1752 . Our coarse N = 2 estimates 0.5039 , 1.1338 are in the right ballpark and would converge as h → 0 . The ghost-node trick correctly supplied the missing equation. ✓
Recall Rapid self-test
Which matrix cell needs iteration even though shooting is used? ::: Cell B — nonlinear ODE makes ϕ ( s ) curved.
A negative residual ϕ ( s 0 ) < 0 means we shot… ::: short (undershot the target β ).
Halving h in a central-difference FDM changes the error by roughly… ::: a factor of 4 1 (it is O ( h 2 ) ).
With a Neumann boundary y ′ ( b ) given, what do we add? ::: a ghost node plus a central-difference equation for the slope.
Why is the lower off-diagonal bigger than the upper when p > 0 ? ::: the convection term 2 h p adds to the lower, subtracts from the upper.
Mnemonic Cover-the-matrix checklist
"Line Once, Curve Iterate, Grid Then Ghost."
Linear shoot = one interpolation; nonlinear = secant loop; FDM grids the interior; a slope-boundary adds a ghost node.