4.1. Shooting Method - Mechanical Engineering Methods Notes
4.1. Shooting Method - Mechanical Engineering Methods Notes
Contents
y
′′
+ xy
′
− xy = 2x (4.1)
The numerical methods we have already discussed (e.g., Forward Euler, Runge-Kutta) require values of y and y ′
at the starting point, x = 0 . So we can’t use these directly because we are missing y ′ (0).
But, what if we could guess a value for the missing initial condition, then integrate towards the second boundary
condition using one of our familiar numerical methods, and then adjust our guess if necessary and repeat? This
concept is the shooting method.
1. Guess a value of the missing initial condition; in this case, that is y ′ (0).
2. Integrate the ODE like an initial-value problem, using our existing numerical methods, to get the given
boundary condition(s); in this case, that is y(L) .
3. Assuming your trial solution for y(L) does not match the given boundary condition, adjust your guess for
′
y (0) and repeat.
Now, this algorithm will not work particularly well if all your guesses are random/uninformed. Fortunately, we can
use linear interpolation to inform a third guess based on two initial attempts:
y
′′
+ xy
′
− xy = 2x (4.3)
First, we need to convert this 2nd-order ODE into a system of two 1st-order ODEs, where we can define u = y
′
:
′
y = u
′
(4.4)
u = 2x + xy − xu
%%file shooting_rhs.m
dydx = zeros(2,1);
dydx(1) = y(2);
https://kyleniemeyer.github.io/ME373-book/content/bvps/shooting-method.html 1/6
11/25/22, 3:39 PM 4.1. Shooting Method — Mechanical Engineering Methods notes
target = 8;
guess1 = 1;
solution1= Y(end,1);
guess2 = 4;
solution2 = Y(end,1);
solution3 = Y(end,1);
Solution 1: 6.00
Solution 2: 11.96
Guess 3: 2.01
Solution 3: 8.00
Target: 8.00
As you can see, using linear interpolation, we are able to find the correct guess for the missing initial condition
′
y (0) with in just three steps. This works so well because this is a linear ODE. If we had a nonlinear ODE, it would
take more tries, as we’ll see shortly.
https://kyleniemeyer.github.io/ME373-book/content/bvps/shooting-method.html 2/6
11/25/22, 3:39 PM 4.1. Shooting Method — Mechanical Engineering Methods notes
To get to a solveable ODE, we start with the conservation of momentum equation (i.e., Navier–Stokes equation) in
the x-direction:
2
∂u ∂u ∂ u
u + v = ν
2
(4.5)
∂x ∂y ∂y
∂u ∂v
+ = 0 , (4.6)
∂x ∂y
where u is the velocity component in the x-direction, v is the velocity component in the y -direction, and ν is the
fluid’s kinematic viscosity. The boundary conditions are that u = v = 0 at y = 0 , and that u = U∞ as y → ∞ ,
where U∞ is the free-stream velocity.
Blasius solved this problem by converting the PDE into an ODE, by recognizing that the boundary layer thickness
−−
−
is given by δ(x) ∼ √
xν
U∞
, and then nondimensionalizing the position coordinates using a similarity variable
−−− −
U∞
η = y√ (4.7)
2ν x
By introducing the stream function, ψ(x, y), we can ensure the continuity equation is satisfied:
∂ψ ∂ψ
u = , v = − (4.8)
∂y ∂x
%%python
sym.init_printing()
x, y, u, v = sym.symbols('x y u v')
# Streamfunction
psi = sym.Function(r'psi')(x,y)
u = psi.diff(y)
v = -psi.diff(x)
print(u.diff(x) + v.diff(y) == 0)
True
Using the boundary layer thickness and free-stream velocity, we can define the dimensionlesss stream function
f (η) :
−−− −
ψ U∞
f (η) = √ (4.9)
U∞ 2ν x
https://kyleniemeyer.github.io/ME373-book/content/bvps/shooting-method.html 3/6
11/25/22, 3:39 PM 4.1. Shooting Method — Mechanical Engineering Methods notes
(4.10)
∂ψ ∂ψ ∂f ∂η
u = =
∂y ∂f ∂η ∂y
−−− − −−− −
2ν x U∞
′
= U∞ √ ⋅ f (η) ⋅ √
U∞ 2ν x
′
u = U∞ f (η)
∂ψ ∂ψ ∂ψ ∂η
v = − = −( + )
∂x ∂x ∂η ∂x
−− −−−
ν U∞
′
= √ (ηf − f )
2x
We can insert these into the x-momentum equation, which leads to an ODE for the dimensionless stream
function f (η):
f
′′′
+ ff
′′
= 0 , (4.11)
This is a 3rd-order ODE, which we can solve by converting it into three 1st-order ODEs:
′
y1 = f y = y2
1
y2 = f
′
y
′
2
= y3 (4.12)
′′ ′
y3 = f y = −y 1 y 3
3
and we can use the shooting method to solve by recognizing that we have two initial conditions,
y 1 (0) = y 2 (0) = 0 , and are missing y 3 (0). We also have a target boundary condition: y 2 (∞) = 1 .
(Note: obviously we cannot truly integrate over 0 ≤ η < ∞ . Instead, we just need to choose a large enough
number. In this case, using 10 is sufficient.)
%%file blasius_rhs.m
dydx = zeros(3,1);
dydx(1) = y(2);
dydx(2) = y(3);
First, let’s try the same three-step approach we used for the simpler example, taking two guesses and then using
linear interpolation to find a third guess:
target = 1.0;
guesses = zeros(3,1);
solutions = zeros(3,1);
guesses(1) = 1;
guesses(2) = 0.1;
https://kyleniemeyer.github.io/ME373-book/content/bvps/shooting-method.html 4/6
11/25/22, 3:39 PM 4.1. Shooting Method — Mechanical Engineering Methods notes
ans =
3x3 table
1 1 1.6553
2 0.1 0.3566
3 0.54587 1.1056
Target: 1.00
So, for this problem, using linear interpolation did not get us the correct solution on the third try. This is because
the ODE is nonlinear. But, you can see that we are converging towards the correct solution—it will just take more
tries.
Rather than manually take an unknown (and potentially large) number of guesses, let’s automate this with a
while loop:
target = 1.0;
% note: I'm only doing this to make it easier to show a table of values
guesses = zeros(3,1);
solutions = zeros(3,1);
guesses(1) = 1;
guesses(2) = 0.1;
num = 2;
num = num + 1;
tries(num) = num;
break
end
end
ans =
7x3 table
1 1 1.6553
2 0.1 0.3566
3 0.54587 1.1056
4 0.48301 1.019
5 0.46922 0.99951
6 0.46957 1
7 0.46957 1
%plot -r 200
xlabel("f^{\prime}(\eta) = u/U_{\infty}")
ylabel('\eta')
https://kyleniemeyer.github.io/ME373-book/content/bvps/shooting-method.html 5/6
11/25/22, 3:39 PM 4.1. Shooting Method — Mechanical Engineering Methods notes
We can see that this plot of η , the y position normalized by the boundary-layer thickness, vs. nondimensional
velocity matches the original figure.
By Kyle Niemeyer
Mechanical Engineering Methods notes by Kyle Niemeyer is licensed under CC BY-SA 4.0
https://kyleniemeyer.github.io/ME373-book/content/bvps/shooting-method.html 6/6