0% found this document useful (0 votes)
122 views6 pages

4.1. Shooting Method - Mechanical Engineering Methods Notes

The shooting method is used to solve boundary value problems (BVPs), which are ordinary differential equations (ODEs) with boundary conditions specified at both endpoints of the domain. It works by guessing the unknown initial condition, integrating the ODE using numerical methods, and adjusting the guess iteratively if the solution does not satisfy the boundary conditions. The method is demonstrated on a linear and nonlinear BVP, showing it finds the correct solution after only a few iterations for the linear case, but may require more iterations for nonlinear problems.

Uploaded by

ahmed
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
122 views6 pages

4.1. Shooting Method - Mechanical Engineering Methods Notes

The shooting method is used to solve boundary value problems (BVPs), which are ordinary differential equations (ODEs) with boundary conditions specified at both endpoints of the domain. It works by guessing the unknown initial condition, integrating the ODE using numerical methods, and adjusting the guess iteratively if the solution does not satisfy the boundary conditions. The method is demonstrated on a linear and nonlinear BVP, showing it finds the correct solution after only a few iterations for the linear case, but may require more iterations for nonlinear problems.

Uploaded by

ahmed
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

11/25/22, 3:39 PM 4.1.

Shooting Method — Mechanical Engineering Methods notes

 Contents

4.1. Shooting Method 4.1.1. Example: linear Print


ODE to PDF
4.1.2. Example: nonlinear ODE
Boundary-value problems are also ordinary differential equations—the difference is that our two constraints are
at boundaries of the domain, rather than both being at the starting point.

For example, consider the ODE

y
′′
+ xy

− xy = 2x (4.1)

with the boundary conditions y(0) = 1 and y(2) = 8 .

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.

The shooting method algorithm is:

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:

guess 3 = guess 2 + m (target − solution 2)

guess 1 − guess 2 (4.2)


m =
solution 1 − solution 2

where “target” is the target boundary condition—in this case, y(L) .

4.1.1. Example: linear ODE


Let’s try solving the given ODE using the shooting method:

y
′′
+ xy

− xy = 2x (4.3)

with the boundary conditions y(0) = 1 and y(2) = 8 .

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

function dydx = shooting_rhs(x, y)

dydx = zeros(2,1);

dydx(1) = y(2);

dydx(2) = 2*x - x*y(2) + x*y(1);

Created file '/Users/niemeyek/projects/ME373-book/content/bvps/shooting_rhs.m'.

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

clear all; clc

% target boundary condition

target = 8;

% Pick a guess for y'(0) of 1

guess1 = 1;

[X, Y] = ode45('shooting_rhs', [0 2], [1 guess1]);

solution1= Y(end,1);

fprintf('Solution 1: %5.2f\n', solution1);

% Pick a second guess for y'(0) of 4

guess2 = 4;

[X, Y] = ode45('shooting_rhs', [0 2], [1 guess2]);

solution2 = Y(end,1);

fprintf('Solution 2: %5.2f\n', solution2);

% now use linear interpolation to find a new guess

m = (guess1 - guess2)/(solution1 - solution2);

guess3 = guess2 + m*(target-solution2);

fprintf('Guess 3: %5.2f\n', guess3);

[X, Y] = ode45('shooting_rhs', [0 2], [1 guess3]);

solution3 = Y(end,1);

fprintf('Solution 3: %5.2f\n', solution3);

fprintf('Target: %5.2f\n', target);

plot(X, Y(:,1)); axis([0 2 0 9])

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.

4.1.2. Example: nonlinear ODE


We can use the shooting method to solve a famous fluids problem: the Blasius boundary layer.

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

Fig. 4.1 Laminar boundary layer, taken from


https://commons.wikimedia.org/wiki/File:Laminar_boundary_layer_scheme.svg

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

and the conservation of mass equation:

∂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) ∼ √

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

Let’s check this, using SymPy:

%%python

import sympy as sym

sym.init_printing()

x, y, u, v = sym.symbols('x y u v')

# Streamfunction

psi = sym.Function(r'psi')(x,y)

# Define u and v based on the streamfunction

u = psi.diff(y)

v = -psi.diff(x)

# Check the continuity equation:

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

which relates directly to the velocity components:

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)

with the boundary conditions f = f



= 0 at η = 0 , and f ′ = 1 as η → ∞ .

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

Let’s create a function to evaluate the derivatives:

%%file blasius_rhs.m

function dydx = blasius_rhs(eta, y)

dydx = zeros(3,1);

dydx(1) = y(2);

dydx(2) = y(3);

dydx(3) = -y(1) * y(3);

Created file '/Users/niemeyek/projects/ME373-book/content/bvps/blasius_rhs.m'.

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:

clear all; clc

target = 1.0;

guesses = zeros(3,1);

solutions = zeros(3,1);

guesses(1) = 1;

[eta, F] = ode45('blasius_rhs', [0 10], [0 0 guesses(1)]);

solutions(1) = F(end, 2);

guesses(2) = 0.1;

[eta, F] = ode45('blasius_rhs', [0 10], [0 0 guesses(2)]);

solutions(2) = F(end, 2);

m = (guesses(1) - guesses(2))/(solutions(1) - solutions(2));

guesses(3) = guesses(2) + m*(target - solutions(2));

[eta, F] = ode45('blasius_rhs', [0 10], [0 0 guesses(3)]);

solutions(3) = F(end, 2);

tries = [1; 2; 3];

table(tries, guesses, solutions)

fprintf('Target: %5.2f\n', target);

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

tries guesses solutions

_____ _______ _________

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:

clear all; clc

target = 1.0;

% get these arrays of stored values started.

% note: I'm only doing this to make it easier to show a table of values

% at the end; otherwise, there's no need to store these values.

tries = [1; 2; 3];

guesses = zeros(3,1);

solutions = zeros(3,1);

guesses(1) = 1;

[eta, F] = ode45('blasius_rhs', [0 10], [0 0 guesses(1)]);

solutions(1) = F(end, 2);

guesses(2) = 0.1;

[eta, F] = ode45('blasius_rhs', [0 10], [0 0 guesses(2)]);

solutions(2) = F(end, 2);

num = 2;

solutions(3) = -1000.; % doing this to kick off the while loop


while abs(target - solutions(num)) > 1.e-9

num = num + 1;

m = (guesses(num-2) - guesses(num-1))/(solutions(num-2) - solutions(num-1));

guesses(num) = guesses(num-1) + m*(target - solutions(num-1));

[eta, F] = ode45('blasius_rhs', [0 1e3], [0 0 guesses(num)]);

solutions(num) = F(end, 2);

tries(num) = num;

% we should probably set a maximum number of iterations, just to prevent

% an infinite while loop in case something goes wrong

if num >= 1e4

break

end

end

table(tries, guesses, solutions)

fprintf('Number of iterations required: %d', num)

ans =

7x3 table

tries guesses solutions

_____ _______ _________

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

Number of iterations required: 7

%plot -r 200

plot(F(:, 2), eta); ylim([0 5])

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

You might also like