- 2070 Bhadra · 6 marks
Shooting method algorithm
Short answer
Convert the boundary value problem to an initial value problem by guessing the missing initial slope s=y'(a). Integrate to x=b, compute the miss distance phi(s)=y(b)-beta, and improve s using the secant formula until |phi|<epsilon. The final IVP solution gives the boundary value problem solution.
Write an algorithm to solve two point boundary value problem using shooting method.
The shooting method converts a two-point boundary value problem
y'' = f(x, y, y'), y(a) = α, y(b) = β
into an initial value problem. The missing initial slope y'(a) = s is guessed ("the shot"), the IVP is integrated to x = b, and s is corrected until y(b) hits β.
Algorithm
- Write the ODE as a system: y' = z, z' = f(x, y, z).
- Choose two trial slopes s₀ and s₁ (for example s₀ = (β − α)/(b − a) and s₁ = s₀ + 1).
- For a trial slope s, solve the IVP y(a) = α, z(a) = s from a to b using RK-4 (or Euler/RK-2) with step h, and record the end value y(b; s).
- Form the miss-distance φ(s) = y(b; s) − β.
- Improve the slope by the secant formula s₂ = s₁ − φ(s₁)·(s₁ − s₀) / (φ(s₁) − φ(s₀)). (For a linear ODE φ is linear in s, so this gives the exact slope after two shots.)
- Set s₀ ← s₁, s₁ ← s₂ and repeat steps 3–5 until |φ(s)| < ε (tolerance, e.g. 10⁻⁴).
- Solve the IVP once more with the final slope; its solution values are the answer to the BVP.
Pseudo-code
READ a, b, alpha, beta, h, eps, s0, s1
phi0 ← Shoot(s0) − beta
REPEAT
phi1 ← Shoot(s1) − beta
IF |phi1| < eps THEN EXIT LOOP
s2 ← s1 − phi1·(s1 − s0)/(phi1 − phi0)
s0 ← s1; phi0 ← phi1; s1 ← s2
UNTIL iterations exceed limit
PRINT s1 and the table of (x, y) from Shoot(s1)
FUNCTION Shoot(s):
x ← a; y ← alpha; z ← s
WHILE x < b
apply one RK-4 step to y' = z, z' = f(x, y, z)
x ← x + h
RETURN y // value at x = b
Flow
guess s0, s1
|
integrate IVP -> y(b)
|
|y(b) - beta| < eps ? --no--> new s (secant) --+
|yes |
output solution <--------------------------+
Bisection can be used instead of the secant step when two slopes giving φ of opposite signs are known.
✓ Answer checked by Claude Opus 5.5 (high effort)
Related questions
- Elliptic: 0≤x,y≤3 boundary · Numerical Method, chapter 7
- Laplace: five-point formula, 2x2 · Numerical Method, chapter 7
- BVP: y'' = e^x + 2y' - y · Numerical Method, chapter 6 · asked 4×
- BVP: y'' = x + y · Numerical Method, chapter 6 · asked 4×
- Program for RK-4 first order IVP · Numerical Method, chapter 6
- Program for RK-4 second order IVP · Numerical Method, chapter 6
- Resection, two point problem, intersection · Surveying II, chapter 5
- Two point problem; advantages, disadvantages · Surveying I, chapter 6
- Initial value problem y''−4y'+3y · Mathematics, chapter 4 · asked 3×
- Initial value problem y''+2y'+5y=0 · Mathematics, chapter 4 · asked 3×