4.8.28Numerical Methods

Boundary value problems — shooting method, finite difference

2,137 words10 min readdifficulty · medium2 backlinks

WHAT is a BVP?

WHY do these arise? Steady-state physics: temperature along a rod with both ends fixed, deflection of a beam clamped at both ends, electrostatic potential between two plates. Nothing evolves in time — the answer must satisfy constraints everywhere at once.


METHOD 1 — Shooting Method

HOW (the algorithm):

  1. Guess s0s_0 for the slope y(a)y'(a). Solve the IVP \to get y(b;s0)y(b;s_0).
  2. Guess s1s_1. Solve again y(b;s1)\to y(b;s_1).
  3. Use the secant method (we usually can't differentiate ϕ\phi cheaply): sn+1=snϕ(sn)snsn1ϕ(sn)ϕ(sn1).s_{n+1} = s_n - \phi(s_n)\,\frac{s_n - s_{n-1}}{\phi(s_n)-\phi(s_{n-1})}.
  4. Repeat until ϕ(sn)<tol|\phi(s_n)|<\text{tol}.

METHOD 2 — Finite Difference Method (FDM)

HOW — derive the difference formulas from Taylor series (first principles):

Grid: xi=a+ihx_i = a+ih, h=baNh=\dfrac{b-a}{N}, i=0,,Ni=0,\dots,N. Let yiy(xi)y_i\approx y(x_i).

Expand: yi+1=yi+hyi+h22yi+h36yi+y_{i+1}=y_i+hy_i'+\tfrac{h^2}{2}y_i''+\tfrac{h^3}{6}y_i'''+\dots yi1=yihyi+h22yih36yi+y_{i-1}=y_i-hy_i'+\tfrac{h^2}{2}y_i''-\tfrac{h^3}{6}y_i'''+\dots

Subtract → odd terms survive, yiy_i'' cancels: yi+1yi1=2hyi+h33yi+    yiyi+1yi12h(O(h2)).y_{i+1}-y_{i-1}=2hy_i'+\tfrac{h^3}{3}y_i'''+\dots \;\Rightarrow\; y_i' \approx \frac{y_{i+1}-y_{i-1}}{2h}\quad (O(h^2)).

Add → odd terms cancel, isolate yiy_i'': yi+1+yi1=2yi+h2yi+h412yi+    yiyi+12yi+yi1h2(O(h2)).y_{i+1}+y_{i-1}=2y_i+h^2 y_i''+\tfrac{h^4}{12}y_i''''+\dots \;\Rightarrow\; y_i'' \approx \frac{y_{i+1}-2y_i+y_{i-1}}{h^2}\quad (O(h^2)).

Apply to a linear BVP y=p(x)y+q(x)y+r(x)y'' = p(x)y' + q(x)y + r(x). Substitute stencils at each interior xix_i: yi+12yi+yi1h2=piyi+1yi12h+qiyi+ri.\frac{y_{i+1}-2y_i+y_{i-1}}{h^2}=p_i\frac{y_{i+1}-y_{i-1}}{2h}+q_i y_i + r_i. Multiply by h2h^2 and group yi1,yi,yi+1y_{i-1},y_i,y_{i+1}: (1+h2pi)loweryi1  (2+h2qi)diagyi  +(1h2pi)upperyi+1=h2ri.\underbrace{\left(1+\tfrac{h}{2}p_i\right)}_{\text{lower}}y_{i-1}\;\underbrace{-\,(2+h^2 q_i)}_{\text{diag}}\,y_i\;+\underbrace{\left(1-\tfrac{h}{2}p_i\right)}_{\text{upper}}y_{i+1}=h^2 r_i.

This is a tridiagonal linear system Ay=dA\mathbf{y}=\mathbf{d} with y0=α, yN=βy_0=\alpha,\ y_N=\beta moved to the right side. Solve in O(N)O(N) by the Thomas algorithm (tridiagonal Gaussian elimination).

Figure — Boundary value problems — shooting method, finite difference

Shooting vs Finite Difference

Shooting Finite Difference
Idea Guess slope, root-find Solve all nodes at once
Reuses IVP solver (RK4) Linear algebra (Thomas)
Nonlinear BVP Easy (secant outside) Needs Newton on system
Stiff/long domain Can blow up Stable
Accuracy RK4 order O(h2)O(h^2) (central)

Recall Feynman: explain to a 12-year-old

Imagine you must throw a ball so it lands exactly in a far-off bucket. You don't know the right throwing angle. Shooting: throw once (too short), throw again (too far), then split the difference — keep adjusting the angle until it lands in the bucket. Finite difference: instead of throwing, you draw the ball's path as lots of tiny connected dots and force the dots to obey the rule "each dot is the average-ish of its neighbours," then solve the dot-puzzle so the first and last dots sit where they must. Both find the same curve — one by aiming, one by puzzle-solving.


Flashcards

What distinguishes a BVP from an IVP?
BVP gives one condition at each endpoint (y(a),y(b)y(a),y(b)); IVP gives all conditions (y,yy,y') at a single point, so IVP can march but BVP cannot.
Core idea of the shooting method?
Guess the missing slope y(a)=sy'(a)=s, solve the resulting IVP, treat landing error ϕ(s)=y(b;s)β\phi(s)=y(b;s)-\beta, and root-find ϕ(s)=0\phi(s)=0 (usually via secant).
Why does the linear shooting shortcut give the answer in exactly 2 shots?
For a linear ODE, y(b;s)y(b;s) is linear in ss, so ϕ(s)\phi(s) is a straight line determined exactly by two points — linear interpolation hits the root with no iteration.
Secant update formula for shooting?
sn+1=snϕ(sn)snsn1ϕ(sn)ϕ(sn1)s_{n+1}=s_n-\phi(s_n)\dfrac{s_n-s_{n-1}}{\phi(s_n)-\phi(s_{n-1})}.
Central difference for yy' and its order?
yiyi+1yi12hy_i'\approx\dfrac{y_{i+1}-y_{i-1}}{2h}, accurate to O(h2)O(h^2).
Central difference for yy'' and its order?
yiyi+12yi+yi1h2y_i''\approx\dfrac{y_{i+1}-2y_i+y_{i-1}}{h^2}, accurate to O(h2)O(h^2) (the +1,2,+1+1,-2,+1 stencil).
How do you derive the yy'' stencil?
Add the Taylor expansions of yi+1y_{i+1} and yi1y_{i-1}; odd-power terms cancel, leaving yi+1+yi1=2yi+h2yi+O(h4)y_{i+1}+y_{i-1}=2y_i+h^2y_i''+O(h^4), then solve for yiy_i''.
Tridiagonal FDM coefficients for y=py+qy+ry''=p y'+qy+r?
Lower 1+h2pi1+\tfrac h2 p_i, diagonal (2+h2qi)-(2+h^2q_i), upper 1h2pi1-\tfrac h2 p_i, RHS h2rih^2 r_i.
Which algorithm efficiently solves the FDM system and at what cost?
The Thomas algorithm (tridiagonal Gaussian elimination), O(N)O(N).
When prefer FDM over shooting?
Stiff problems or long domains where small slope errors in shooting blow up; FDM keeps errors local and is more stable.
Why is using a forward difference for yy' a bad idea in a central-difference FDM?
It's only O(h)O(h), degrading the whole scheme from second order to first order.
What must you do with y0y_0 and yNy_N when assembling the FDM matrix?
Move their (known) contributions to the right-hand side vector at the first and last interior equations.

Connections

  • Initial Value Problems — shooting reduces a BVP to repeated IVPs.
  • Runge-Kutta methods — the inner IVP solver for shooting.
  • Root finding — Secant and Newton — the outer loop of shooting.
  • Taylor series — source of every finite-difference stencil and its error order.
  • Tridiagonal systems — Thomas algorithm — solves the FDM linear system.
  • Truncation error and order of accuracy — why O(h2)O(h^2) matters.
  • Partial Differential Equations — finite differences — same stencils in 2D (Laplace/Poisson).

Concept Map

contrast with

arise from

solved by

solved by

guess slope s

turns BVP into

root-find on

solved via

if ODE linear

replace derivatives by

solve all points

IVP one point conditions

BVP conditions at both ends

Steady-state physics

Shooting method

Finite difference

Missing slope y prime a

Solve IVP with RK4 or Euler

phi s equals y b minus beta

Secant method

Exact in 2 shots

Algebra on grid

Simultaneous linear system

Hinglish (regional understanding)

Intuition Hinglish mein samjho

Dekho, BVP (boundary value problem) ka matlab hai ki tumhe do alag-alag ends par condition di gayi hai — jaise rod ke dono sire ka temperature, ya y(0)y(0) aur y(1)y(1). IVP me sab kuch ek hi point par milta hai isliye tum aage march kar sakte ho, lekin BVP me start ka slope y(a)y'(a) pata hi nahi hota, to direct march nahi chalega. Yahin do techniques kaam aati hain.

Shooting method ekdum cannon aim karne jaisa hai. Tum missing slope s=y(a)s=y'(a) ka ek guess maaro, us guess se IVP solve karo (RK4 vagaira se), aur dekho ki y(b)y(b) kahan gira. Agar target β\beta se kam aaya to slope badhao, zyada aaya to ghatao. Yeh adjusting kaam secant method se hota hai. Mast baat: agar ODE linear hai, to sirf do shots me exact answer aa jata hai, kyunki landing y(b)y(b) slope ka straight-line function hota hai.

Finite difference thoda alag soch hai — yahan tum aim nahi karte, balki poore domain ko chhote-chhote grid points me kaat dete ho. Har point par derivative ko Taylor series se nikla hua formula laga dete ho: yyi+12yi+yi1h2y''\approx\frac{y_{i+1}-2y_i+y_{i-1}}{h^2} (yaad rakho: beech me minus two!). Isse ek tridiagonal linear system ban jata hai jo Thomas algorithm se fatafat solve hota hai. Saare points ek saath solve hote hain, isliye yeh stiff problems me shooting se zyada stable rehta hai.

Exam tip: stencil ka sign mat bhulo, boundary values y0,yNy_0,y_N ko RHS me shift karo, aur central difference hi use karo (forward difference order kam kar deta hai). Accuracy $O

Go deeper — visual, from zero

Test yourself — Numerical Methods

Connections