Section 9.11 Shooting Method
Assuming that there is a solution to
ยจx=f(t,x,หx),x(t0)=x0,x(tf)=xf,
the shooting method's idea is using IVP to find better and better approximations of the value of หx(t0) that produces a solution x(t) s.t. x(tf)=xf.

Subsection 9.11.1 The Linear Case
A particularly simple case it the linear one. Recall the following theorem:Theorem 9.11.1.
The space of solutions of a linear ODE
หx=Ax,x(t0)=x0,xโRn
is itself a linear space. Moreover, the map that sends an initial condition x0 to the corresponding solution is a linear map.
x0โฆx(t)=eA(tโt0)x0.
In particular, this means that for linear BVP
ยจx=a(t)หx+b(t)x+c(t),x(t0)=x0,x(tf)=xf,
the function F(v) is itself linear, namely
F(v)=ฮฑv+ฮฒ.
Hence it is enough to solve numerically two IVP in order to solve the BVP. For instance, say that F(0)=q0 and F(1)=q1. Then ฮฒ=q0 and ฮฑ=q1โq0, so that the solution to
F(v)=xf is v=xfโq0q1โq0.
Example. Consider the IVP
หx=โxcost,x(0)=1,
whose solution is x(t)=eโsint. Since we need a 2nd order ODE, we will rather consider the BVP given by its "first prolongation"
ยจx=โหxcost+xsint,x(0)=1,x(15ฯ/2)=e.
The code below applies the method illustrade above to solve this BVP. xxxxxxxxxx
from numpy import linspace, zeros, cos, sin, pi
import matplotlib.pyplot as plt
โ
N = 100; ti = 0.; tf = 15*pi/2; xi = 1; xf = exp(1); h = tf/N;
โ
#Solving a first time the ODE with explicit Euler's method...
q0=xi; p0=0; T=linspace(ti,tf,N+1)
for i in range(N):
a = q0
q0 = q0 + h*p0
p0 = p0 + h*(-p0*cos(T[i])+a*sin(T[i]))
โ
qf0 = q0
pf0 = p0
โ
#Solving a second time the ODE with explicit Euler's method...
q1=xi
p1=1
for i in range(N):
a = q1
q1 = q1 + h*p1
p1 = p1 + h*(-p1*cos(T[i])+a*sin(T[i]))
โ
qf1 = q1
pf1 = p1
โ
#Solving last time the ODE with explicit Euler's method...
Q = zeros(N+1)
P = zeros(N+1)
Q[0]=xi
P[0]=(xf-qf0)/(qf1-qf0)
for i in range(N):
Q[i+1] = Q[i] + h*P[i];
P[i+1] = P[i] + h*(-P[i]*cos(T[i])+Q[i]*sin(T[i]));
โ
exactSolution = lambda t: exp(-sin(t))
โ
plt.clf()
plt.plot(T,Q,'ro-',T,exactSolution(T),'b-');
plt.legend(["Numerical solution, h = {}".format(h),"Exact solution"])
plt.show()