The Shooting Method for a Boundary-Value Problem
Turn a two-point boundary-value problem into a root-finding problem on the unknown initial slope.
The problem
A boundary-value problem fixes the solution at both ends, e.g. y'' = f(x,y,y') with y(0)=A and y(1)=B. An initial-value integrator needs both y(0) and y'(0), but we only know y(0). The shooting method guesses the missing slope and corrects it.
The strategy
- Guess y'(0) = s.
- Integrate the ODE from x=0 to x=1 as an initial-value problem.
- Compare the computed y(1) to the target B; define the miss F(s) = y(1;s) - B.
- Use a root finder on F(s) to hit the far boundary.
Worked example
Solve y'' = 6x with y(0)=0, y(1)=1. The exact answer is y = x^3 with y'(0)=0; the shooting method should recover s = 0.
import numpy as np
from scipy.integrate import solve_ivp
from scipy.optimize import brentq
def shoot(s):
sol=solve_ivp(lambda x,y:[y[1],6*x],[0,1],[0,s],t_eval=[1])
return sol.y[0,-1]-1.0 # y(1) - target
s=brentq(shoot,-5,5)
print('initial slope:',round(s,6)) # ~0.0
When it struggles
For linear problems one or two shots plus linear interpolation nail it. For nonlinear or unstable ODEs, small changes in s can blow up over the interval, making F(s) wildly sensitive; there, multiple shooting (splitting the interval and matching internally) or a direct finite-difference discretization of the BVP is more robust.