---
title: "Shooting method algorithm"
subject: "Numerical Method"
chapter: 6
key: "semester_4/numerical_method:shooting-method-algorithm"
source: https://www.bctengineer.com/q/semester_4/numerical_method/shooting-method-algorithm
site: BCT Engineering
---

# Shooting method algorithm

Numerical Method · Chapter 6: Solution of ordinary differential equations

- Asked in: 2070 Bhadra, 6 marks
- Video: [Shooting Method for Boundary Value Problems | Lecture 57 | Numerical Methods for Engineers](https://www.youtube.com/watch?v=qIfxydBEdzg) — Jeffrey Chasnov
- Answer checked by Claude Opus 5.5 (high effort) on 2026-10-14
- Page: https://www.bctengineer.com/q/semester_4/numerical_method/shooting-method-algorithm
- Whole chapter: https://www.bctengineer.com/md/semester_4/numerical_method/chapter-6

## Question

Write an algorithm to solve two point boundary value problem using shooting method.

## 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.

## Answer

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
1. Write the ODE as a system: y' = z, z' = f(x, y, z).
2. Choose two trial slopes s₀ and s₁ (for example s₀ = (β − α)/(b − a) and s₁ = s₀ + 1).
3. 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).
4. Form the miss-distance φ(s) = y(b; s) − β.
5. 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.)
6. Set s₀ ← s₁, s₁ ← s₂ and repeat steps 3–5 until |φ(s)| < ε (tolerance, e.g. 10⁻⁴).
7. Solve the IVP once more with the final slope; its solution values are the answer to the BVP.

#### Pseudo-code
```text
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
```text
 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.

## Check yourself

The answer's key points as multiple-choice questions, with the correct option and why.

1. What does the shooting method do with a two-point BVP?
   A. Replaces derivatives by differences and solves a linear system
   B. Expands y as a power series about a
   C. Integrates from b to a with a random step
   D. Guesses the missing initial slope y'(a), solves an IVP, and adjusts the slope until y(b) matches the boundary value
   Answer: D. The BVP becomes a sequence of IVPs with the unknown slope tuned to hit y(b) = beta. (Key point: Idea)

2. What is the function whose root is sought?
   A. phi(s) = y(b; s) - beta
   B. phi(s) = y(a; s) - alpha
   C. phi(s) = y'(b; s) - beta
   D. phi(s) = s - alpha
   Answer: A. The root of the end-point error gives the correct slope. (Key point: Miss-distance)

3. How is the new slope found using the secant formula?
   A. s2 = (s0 + s1)/2 always
   B. s2 = s1 - phi(s1)(s1 - s0)/(phi(s1) - phi(s0))
   C. s2 = s1 + phi(s1)
   D. s2 = s1 - phi(s1)/(s1 - s0)
   Answer: B. It is a secant step on phi using the two latest shots. (Key point: Slope update)

4. For a linear ODE how many shots give the exact slope?
   A. One
   B. Three
   C. Two, since phi is linear in s
   D. Infinitely many iterations
   Answer: C. A linear phi is determined exactly by two points, so one secant step is exact. (Key point: Linear ODE)

## Related in Numerical Method

- [Elliptic: 0≤x,y≤3 boundary](https://www.bctengineer.com/question.md?key=semester_4%2Fnumerical_method%3Alaplace-uxx-0-3-boundary) — Numerical Method, chapter 7
- [Laplace: five-point formula, 2x2](https://www.bctengineer.com/question.md?key=semester_4%2Fnumerical_method%3Alaplace-five-point-iterative) — Numerical Method, chapter 7
- [BVP: y'' = e^x + 2y' - y](https://www.bctengineer.com/question.md?key=semester_4%2Fnumerical_method%3Abvp-finite-difference-e-x-2y) — Numerical Method, chapter 6, asked 4×
- [BVP: y'' = x + y](https://www.bctengineer.com/question.md?key=semester_4%2Fnumerical_method%3Abvp-finite-difference-x-plus-y) — Numerical Method, chapter 6, asked 4×
- [Program for RK-4 first order IVP](https://www.bctengineer.com/question.md?key=semester_4%2Fnumerical_method%3Ark4-program-first-order) — Numerical Method, chapter 6
- [Program for RK-4 second order IVP](https://www.bctengineer.com/question.md?key=semester_4%2Fnumerical_method%3Ark4-program-second-order) — Numerical Method, chapter 6

## Related in other subjects

- [Resection, two point problem, intersection](https://www.bctengineer.com/question.md?key=semester_4%2Fsurveying_ii%3Aresection-two-point-problem-ab-p) — Surveying II, chapter 5
- [Two point problem; advantages, disadvantages](https://www.bctengineer.com/question.md?key=semester_3%2Fsurveying_i%3Atwo-point-problem-adv-disadv) — Surveying I, chapter 6
- [Initial value problem y''−4y'+3y](https://www.bctengineer.com/question.md?key=semester_2%2Fmathematics%3Ainitial-value-problem-y-4y) — Mathematics, chapter 4, asked 3×
- [Initial value problem y''+2y'+5y=0](https://www.bctengineer.com/question.md?key=semester_2%2Fmathematics%3Ainitial-value-problem-y-2y) — Mathematics, chapter 4, asked 3×
