Shooting Method

The shooting method solves a boundary value problem y″ = f(x, y, y′), y(a) = α, y(b) = β by turning it into initial value problems. Guess the missing slope s = y′(a), solve the initial value problem, and see how far y(b) misses β. Then adjust s, usually with the secant method, until the shot hits the target.

Before this lesson: Boundary Value Problems, Secant Method and Heun’s Method

The idea: aim, fire, adjust

A boundary value problem gives one condition at each end, so we cannot start a step-by-step solver at x = a: the slope y′(a) is unknown. If we knew it, any initial value solver could march from a to b.

The shooting method treats the unknown slope like the angle of a cannon. Pick a slope s, “fire” by solving the initial value problem y(a) = α, y′(a) = s, and read where the shot lands, y(b; s). Too high? Lower s. Too low? Raise it.

In other words, we solve one equation in one unknown, F(s) = y(b; s) − β = 0, where each evaluation of F means solving an initial value problem. Any root-finding method works; the secant method is the usual choice because it needs no derivative of F.

Graph of three shots for y double prime = y with y(0) = 1, for x from 0 to 1. With slope s = 0 the curve ends at y(1) about 1.54. With s = 1 it ends at about 2.72. With s about 1.2397 it ends exactly at the target point (1, 3).
Shots for y″ = y, y(0) = 1: slopes 0 and 1 miss the target y(1) = 3, and interpolating between them gives s ≈ 1.2397, which hits it.

Shooting method formula

For y″ = f(x, y, y′) with y(a) = α and y(b) = β, write y(x; s) for the solution of the initial value problem y(a) = α, y′(a) = s. The shooting method solves

F(s) = y(b; s) - \beta = 0

With two shots s₀ and s₁, the secant update is

s_{k+1} = s_k - F(s_k)\,\frac{s_k - s_{k-1}}{F(s_k) - F(s_{k-1})}

If the differential equation is linear, y(b; s) is a linear function of s, so the secant step gives the exact slope after just two shots (up to the error of the initial value solver). For a nonlinear equation, repeat the update until F(s) is small.

How to use the shooting method

  1. Write y″ = f(x, y, y′) as the first-order system y′ = v, v′ = f(x, y, v) (see systems of differential equations).
  2. Choose two guesses s₀ and s₁ for y′(a).
  3. For each guess, solve the initial value problem from x = a to x = b with a reliable solver (Heun, RK4 or an exact formula) and record F(s) = y(b; s) − β.
  4. Update s with the secant formula and fire again.
  5. Stop when |F(s)| is below the tolerance; the last shot is the solution.

Shooting method examples

Example 1: Two shots for a linear equation

Solve y″ = 6x, y(0) = 0, y(1) = 3 by shooting. The initial value problem has the exact solution y(x; s) = x³ + sx.

y(1; 0) = 1 + 0 = 1,\quad F(0) = 1 - 3 = -2

First shot, s₀ = 0.

y(1; 4) = 1 + 4 = 5,\quad F(4) = 5 - 3 = 2

Second shot, s₁ = 4.

s_2 = 4 - 2 \cdot \dfrac{4 - 0}{2 - (-2)} = 4 - 2 = 2

Secant update.

y(1; 2) = 1 + 2 = 3

Third shot hits the target.

Answer: y′(0) = 2, so y = x³ + 2x. Because the equation is linear, the secant step found the exact slope immediately.

Example 2: Shooting with y″ = y

Solve y″ = y, y(0) = 1, y(1) = 3. The initial value problem with y′(0) = s has solution y(x; s) = cosh x + s sinh x (see hyperbolic functions).

y(1; 0) = \cosh 1 \approx 1.543081

First shot, s₀ = 0.

y(1; 1) = \cosh 1 + \sinh 1 = e \approx 2.718282

Second shot, s₁ = 1.

F(0) = 1.543081 - 3 = -1.456919,\quad F(1) = 2.718282 - 3 = -0.281718

Misses at x = 1.

s_2 = 1 - (-0.281718) \cdot \dfrac{1 - 0}{-0.281718 - (-1.456919)} = 1 + \dfrac{0.281718}{1.175201}

Secant update.

s_2 \approx 1 + 0.239719 = 1.239719

Divide and add.

y(1; 1.239719) \approx 1.543081 + 1.239719(1.175201) \approx 3.000000

Check the third shot.

Answer: y′(0) ≈ 1.239719, and the solution is y = cosh x + 1.239719 sinh x. For example, y(0.5) ≈ 1.773638. The graph above shows the three shots.

Example 3: Shots computed with Heun’s method

Solve y″ = y, y(0) = 0, y(1) = 1, using Heun’s method with h = 0.5 as the initial value solver. Let u = y and v = y′, so u′ = v and v′ = u.

s = 0 \Rightarrow u \equiv 0,\quad y(1; 0) = 0

First shot: the zero solution.

\mathbf{k}_1 = (1, 0),\quad (\tilde{u}, \tilde{v}) = (0.5, 1),\quad \mathbf{k}_2 = (1, 0.5)

Second shot, s = 1: first step from (0, 1).

(u_1, v_1) = (0 + 0.25(1 + 1),\ 1 + 0.25(0 + 0.5)) = (0.5, 1.125)

Heun corrector with h/2 = 0.25.

\mathbf{k}_1 = (1.125, 0.5),\quad (\tilde{u}, \tilde{v}) = (1.0625, 1.375),\quad \mathbf{k}_2 = (1.375, 1.0625)

Second step from (0.5, 1.125).

u_2 = 0.5 + 0.25(1.125 + 1.375) = 0.5 + 0.625 = 1.125

Corrector for u, so y(1; 1) ≈ 1.125.

s = 0 + (1 - 0) \cdot \dfrac{1 - 0}{1.125 - 0} \approx 0.888889

Secant (here, linear interpolation) with target 1.

Answer: y′(0) ≈ 0.889. The exact value is 1/sinh 1 ≈ 0.850918; the difference comes from the coarse step h = 0.5 in Heun’s method, not from shooting. A smaller h or RK4 would shrink it.

Example 4: A nonlinear problem with the secant method

Solve y″ = 1.5y², y(0) = 4, y(1) = 1. Each shot is computed with RK4 using h = 0.001 (values to 6 decimals). Start with s₀ = −7 and s₁ = −9.

ksₖy(1; sₖ)F(sₖ) = y(1; sₖ) − 1
0−73.6442372.644237
1−9−0.958143−1.958143
2−8.1490740.669374−0.330626
3−7.9762101.0541440.054144
4−8.0005360.998786−0.001214
5−8.0000020.999996−0.000004
s_2 = -9 - (-1.958143) \cdot \dfrac{-9 - (-7)}{-1.958143 - 2.644237}

Secant update from the first two shots.

s_2 = -9 - \dfrac{3.916286}{-4.602380} \approx -9 + 0.850926 = -8.149074

Simplify.

Answer: y′(0) ≈ −8. The exact solution is y = 4/(1 + x)², whose slope at 0 is −8. This equation has a second solution with y′(0) ≈ −35.86; a different starting pair of guesses can lead the secant method there.

Example 5: Temperature in a cooling fin (word problem)

A metal fin 1 m long loses heat to 20°C air. Its temperature satisfies T″ = 4(T − 20), with T(0) = 100°C at the wall and T(1) = 40°C at the tip. For a slope s = T′(0), the initial value solution is T(x) = 20 + 80 cosh 2x + (s/2) sinh 2x. Find T′(0), which measures the heat flowing in from the wall.

T(1; 0) = 20 + 80\cosh 2 \approx 20 + 300.975655 = 320.975655

First shot, s₀ = 0 (cosh 2 ≈ 3.762196).

T(1; -100) = 320.975655 - 50\sinh 2 \approx 320.975655 - 181.343020 = 139.632635

Second shot, s₁ = −100 (sinh 2 ≈ 3.626860).

F(0) = 280.975655,\quad F(-100) = 99.632635

Subtract the target 40.

s_2 = -100 - 99.632635 \cdot \dfrac{-100 - 0}{99.632635 - 280.975655}

Secant update.

s_2 = -100 - 99.632635 \cdot \dfrac{-100}{-181.343020} \approx -100 - 54.941533 = -154.941533

Simplify.

Answer: T′(0) ≈ −154.94°C per meter. The temperature drops steeply near the wall, and the third shot lands exactly on 40°C because the equation is linear.

Common mistakes

MistakeExample of the errorFix
Guessing y(a) instead of y′(a)Changing y(0) = 1 in Example 2y(a) = α is given; the unknown you shoot with is the slope s = y′(a).
Using a crude solver for each shotOne Euler step per shotThe shooting answer is only as accurate as the initial value solver; use a small h or RK4.
Interpolating toward the wrong targetSolving y(b; s) = 0 instead of y(b; s) = βDefine F(s) = y(b; s) − β and find its root.
Expecting two shots to finish a nonlinear problemStopping after one secant step in Example 4Only linear equations are exact after two shots; iterate until |F| is small.
Assuming the solution is uniqueReporting s ≈ −35.86 in Example 4 without noticing the other root s = −8A nonlinear problem can have several solutions; try several starting pairs and keep the one that fits the situation.

Related methods

Finite difference method

Instead of marching from one end, the finite difference method replaces y″ with a difference quotient at every grid point and solves all the values at once; see Finite Difference Method for Boundary Value Problems. It is often more stable when shots grow rapidly.

Newton’s method for the slope

Newton’s method can update s using dF/ds, which comes from solving a second initial value problem (the variational equation) alongside each shot. It converges quadratically, but the secant method needs no extra equation.

Multiple shooting

For long intervals or sensitive equations, multiple shooting splits [a, b] into pieces, shoots on each piece from guessed values, and matches the pieces with Newton’s method for systems.

Practice problems

  1. Use shots s = 0 and s = 1 to solve y″ = 0, y(0) = 2, y(4) = 10. The initial value solution is y = 2 + sx.
  2. Solve y″ = 12x², y(0) = 0, y(1) = 4 by shooting. The initial value solution is y = x⁴ + sx.
  3. Solve y″ = −y, y(0) = 0, y(π/2) = 2. The initial value solution is y = s sin x.
  4. Shots s₀ = 1 and s₁ = 2 give y(b) = 3.2 and 5.0. The target is y(b) = 4. Find the next secant guess.
  5. Explain why two shots are enough for any linear boundary value problem.
  6. Find the exact slope y′(0) for y″ = y, y(0) = 0, y(1) = 1, and compare with Example 3.
  7. A ball is thrown straight up from the ground and lands 2 seconds later, so y″ = −9.8, y(0) = 0, y(2) = 0. Use shooting to find the launch speed and the maximum height.
  8. Redo the s = 1 shot of Example 3 with Euler’s method and h = 0.5. What slope does shooting give?
  9. Why can a nonlinear boundary value problem have more than one solution, and how does that affect shooting?
  10. Solve y″ = y, y(0) = 1, y′(1) = 0 by shooting on the condition at x = 1. Use y = cosh x + s sinh x.
Show answers

1.

y(4; 0) = 2,\quad y(4; 1) = 2 + 4 = 6

Two shots.

s = 1 + (10 - 6) \cdot \dfrac{1 - 0}{6 - 2} = 1 + 1 = 2

Secant step with F = y(4) − 10.

Answer: y′(0) = 2, so y = 2 + 2x

2.

y(1; s) = 1 + s = 4

Set the shot equal to the target.

s = 3

Subtract 1.

Answer: y′(0) = 3, so y = x⁴ + 3x

3.

y\left(\tfrac{\pi}{2}; s\right) = s\sin\tfrac{\pi}{2} = s

The shot lands at s.

s = 2

Set equal to the target 2.

Answer: y′(0) = 2, so y = 2 sin x

4.

F(1) = 3.2 - 4 = -0.8,\quad F(2) = 5.0 - 4 = 1

Misses.

s_2 = 2 - 1 \cdot \dfrac{2 - 1}{1 - (-0.8)} = 2 - \dfrac{1}{1.8} \approx 1.444444

Secant update.

Answer: s₂ ≈ 1.4444

5.

y(x; s) = y(x; 0) + s\,w(x)

For a linear equation, the difference of two solutions solves the homogeneous equation, so y depends linearly on s.

Answer: y(b; s) is a straight-line function of s, so the secant line through two shots is the function itself and its root is the exact slope (apart from solver error)

6.

y(1; s) = s\sinh 1 = 1

For y(0) = 0, the solution is y = s sinh x.

s = \dfrac{1}{\sinh 1} \approx \dfrac{1}{1.175201} \approx 0.850918

Divide.

Answer: 0.850918; Example 3’s 0.888889 is about 0.038 too high because of Heun’s coarse step

7.

y(t; s) = st - 4.9t^2,\quad y(2; s) = 2s - 19.6

Solve the initial value problem by integrating twice.

2s - 19.6 = 0 \Rightarrow s = 9.8

Hit the target y(2) = 0.

y(1) = 9.8(1) - 4.9(1)^2 = 4.9

Maximum height at t = 1, halfway through the flight.

Answer: launch speed 9.8 m/s and maximum height 4.9 m

8.

(u_1, v_1) = (0 + 0.5(1),\ 1 + 0.5(0)) = (0.5, 1)

Euler step from (0, 1).

(u_2, v_2) = (0.5 + 0.5(1),\ 1 + 0.5(0.5)) = (1, 1.25)

Second Euler step.

s = \dfrac{1}{1} = 1

y(1; 1) ≈ 1 already hits the target.

Answer: s = 1, further from the exact 0.850918 than Heun’s 0.888889

9.

Answer: F(s) = y(b; s) − β is then a nonlinear function of s and can have several roots, each giving a different solution; the root the secant method finds depends on the starting guesses

10.

y'(x; s) = \sinh x + s\cosh x

Differentiate the shot.

\sinh 1 + s\cosh 1 = 0 \Rightarrow s = -\tanh 1 \approx -0.761594

Set y′(1) = 0 and solve.

Answer: y′(0) ≈ −0.7616, so y = cosh x − 0.761594 sinh x

Shooting method FAQ

What is the shooting method?

It is a way to solve a boundary value problem by guessing the missing initial slope, solving the resulting initial value problem, and adjusting the guess until the solution meets the condition at the far end.

Why is it called the shooting method?

Choosing the slope is like aiming a cannon: each “shot” is a solution curve, and you adjust the aim until the curve hits the target value at x = b.

How many shots does the shooting method need?

For a linear equation, two shots and one secant step give the exact slope, up to the error of the initial value solver. A nonlinear equation needs several secant or Newton iterations.

When does the shooting method fail?

It can fail when the initial value problem is very sensitive to s, for example when solutions grow like e^(λx) with large λ, so small changes in s overflow or lose all accuracy. Multiple shooting or the finite difference method is then a better choice.

Summary

  • The shooting method turns a boundary value problem into initial value problems by guessing the slope s = y′(a).
  • It solves F(s) = y(b; s) − β = 0, usually with the secant method.
  • Linear equations need only two shots; nonlinear ones need several iterations.
  • The accuracy depends on the initial value solver used for each shot.
  • Sensitive problems may need multiple shooting or the finite difference method.

Previous lesson: Stiff Differential Equations

Next lesson: Finite Difference Method for Boundary Value Problems

Back to the Numerical Methods Index