![Page 1: The Shooting Method for Boundary-value Problems Douglas Wilhelm Harder, M.Math. LEL Department of Electrical and Computer Engineering University of Waterloo](https://reader036.vdocuments.us/reader036/viewer/2022062421/56649e0f5503460f94afa5af/html5/thumbnails/1.jpg)
The Shooting Method forBoundary-value Problems
Douglas Wilhelm Harder, M.Math. LELDepartment of Electrical and Computer Engineering
University of Waterloo
Waterloo, Ontario, Canada
ece.uwaterloo.ca
© 2012 by Douglas Wilhelm Harder. Some rights reserved.
![Page 2: The Shooting Method for Boundary-value Problems Douglas Wilhelm Harder, M.Math. LEL Department of Electrical and Computer Engineering University of Waterloo](https://reader036.vdocuments.us/reader036/viewer/2022062421/56649e0f5503460f94afa5af/html5/thumbnails/2.jpg)
2
Outline
This topic to approximating boundary-value problems– We will describe boundary-value problems (BVPs)– We will look at solutions with linear ordinary differential
equations (ODEs)– We will consider solutions for non-linear ODEs
• This will require successive approximations using the secant method
The Shooting Method for Boundary-value Problems
![Page 3: The Shooting Method for Boundary-value Problems Douglas Wilhelm Harder, M.Math. LEL Department of Electrical and Computer Engineering University of Waterloo](https://reader036.vdocuments.us/reader036/viewer/2022062421/56649e0f5503460f94afa5af/html5/thumbnails/3.jpg)
3
Outcomes Based Learning Objectives
By the end of this laboratory, you will understand:– Boundary-value problems (BVPs)– How to use an initial-value problem (IVP) solver to approximate
solutions to BVPs– The solution to linear BVPs– The application of the secant method to solve non-linear BVPs
The Shooting Method for Boundary-value Problems
![Page 4: The Shooting Method for Boundary-value Problems Douglas Wilhelm Harder, M.Math. LEL Department of Electrical and Computer Engineering University of Waterloo](https://reader036.vdocuments.us/reader036/viewer/2022062421/56649e0f5503460f94afa5af/html5/thumbnails/4.jpg)
4
Using Matlab
These methods assume that the student has written the initial-value problem solver pd45 with the signature
dp45( f, x_rng, u0, h, eps_abs ) which uses the Dormand-Prince method
If this routine is not available, you are welcome to use the built-in Matlab routine ode45 which has the similar signature
ode45( f, x_rng, u0 )
The Shooting Method for Boundary-value Problems
![Page 5: The Shooting Method for Boundary-value Problems Douglas Wilhelm Harder, M.Math. LEL Department of Electrical and Computer Engineering University of Waterloo](https://reader036.vdocuments.us/reader036/viewer/2022062421/56649e0f5503460f94afa5af/html5/thumbnails/5.jpg)
5
2nd-order ODEs
A boundary-value problem in one dimension is any 2nd-order ODE
F(x, u(x), u(1)(x), u(2)(x)) = 0
with two constraints
u(a) = ua
u(b) = ub
In general, we will look at functions of the form
u(2)(x) = f(x, u(x), u(1)(x))
The Shooting Method for Boundary-value Problems
![Page 6: The Shooting Method for Boundary-value Problems Douglas Wilhelm Harder, M.Math. LEL Department of Electrical and Computer Engineering University of Waterloo](https://reader036.vdocuments.us/reader036/viewer/2022062421/56649e0f5503460f94afa5af/html5/thumbnails/6.jpg)
6
2nd-order ODEs
Consider the corresponding initial-value problem for this 2nd-order ODE
F(x, u(x), u(1)(x), u(2)(x)) = 0
with two constraints
u(a) = ua
u(1)(a) = ua(1)
Here we specify the slope at the left-hand point x = a
The Shooting Method for Boundary-value Problems
![Page 7: The Shooting Method for Boundary-value Problems Douglas Wilhelm Harder, M.Math. LEL Department of Electrical and Computer Engineering University of Waterloo](https://reader036.vdocuments.us/reader036/viewer/2022062421/56649e0f5503460f94afa5af/html5/thumbnails/7.jpg)
7
2nd-order ODEs
Thus, a boundary-value problem could be restated as:– Given one initial condition u(a) = ua, what slope is required at that
initial point so that the solution to that initial condition passes through the point (b, ub)?
(b, ub)
(a, ua)
The Shooting Method for Boundary-value Problems
![Page 8: The Shooting Method for Boundary-value Problems Douglas Wilhelm Harder, M.Math. LEL Department of Electrical and Computer Engineering University of Waterloo](https://reader036.vdocuments.us/reader036/viewer/2022062421/56649e0f5503460f94afa5af/html5/thumbnails/8.jpg)
8
2nd-order ODEs
We will consider two possible cases:– When the ODE is linear, and– When it is not
(b, ub)
(a, ua)
The Shooting Method for Boundary-value Problems
![Page 9: The Shooting Method for Boundary-value Problems Douglas Wilhelm Harder, M.Math. LEL Department of Electrical and Computer Engineering University of Waterloo](https://reader036.vdocuments.us/reader036/viewer/2022062421/56649e0f5503460f94afa5af/html5/thumbnails/9.jpg)
9
2nd-order Linear ODEs
A 2nd-order ODE is said to be linear if it can be written as
u(2)(x) + q(x) u(1)(x) + r(x) u(x) = g(x)
or
u(2)(x) = g(x) – q(x) u(1)(x) – r(x) u(x)
We will also consider the corresponding homogenous LODE:
u(2)(x) + q(x) u(1)(x) + r(x) u(x) = 0
or
u(2)(x) = –q(x) u(1)(x) – r(x) u(x)
The Shooting Method for Boundary-value Problems
![Page 10: The Shooting Method for Boundary-value Problems Douglas Wilhelm Harder, M.Math. LEL Department of Electrical and Computer Engineering University of Waterloo](https://reader036.vdocuments.us/reader036/viewer/2022062421/56649e0f5503460f94afa5af/html5/thumbnails/10.jpg)
10
2nd-order Linear ODEs
To demonstrate 2nd-order LODEs, we will consider the example
The corresponding homogeneous LODE is the
2 1sin 1
2 1.5
3 2.5
u x x u x u x
u
u
2 1sin 0u x x u x u x
The Shooting Method for Boundary-value Problems
![Page 11: The Shooting Method for Boundary-value Problems Douglas Wilhelm Harder, M.Math. LEL Department of Electrical and Computer Engineering University of Waterloo](https://reader036.vdocuments.us/reader036/viewer/2022062421/56649e0f5503460f94afa5af/html5/thumbnails/11.jpg)
11
2nd-order Linear ODEs
Recall that if ug(x) is a solution to a 2nd-order LODE and u0(x) is a solution to the corresponding homogenous LODE, then
ug(x) + c·u0(x)
is also a solution the LODE
The Shooting Method for Boundary-value Problems
2
0 0 02 g g g
d du x cu x q x u x cu x r x u x cu x
dx dx
2 2 1 10 0 0g g gu x c u x q x u x cq x u x r x u x cr x u x
2 1 2 10 0 0g g gu x q x u x r x u x c u x q x u x r x u x
0g x c
g x
g(x) 0
![Page 12: The Shooting Method for Boundary-value Problems Douglas Wilhelm Harder, M.Math. LEL Department of Electrical and Computer Engineering University of Waterloo](https://reader036.vdocuments.us/reader036/viewer/2022062421/56649e0f5503460f94afa5af/html5/thumbnails/12.jpg)
12
2nd-order Linear ODEs
Suppose we have redefine a boundary-value problem in terms of two IVPs, the first on the LODE with constraints
and the second on the homogenous LODE with constraints
Let ug(x) and u0(x) be the solutions, respectively
1 0
au a u
u a
1
0
1
u a
u a
The Shooting Method for Boundary-value Problems
![Page 13: The Shooting Method for Boundary-value Problems Douglas Wilhelm Harder, M.Math. LEL Department of Electrical and Computer Engineering University of Waterloo](https://reader036.vdocuments.us/reader036/viewer/2022062421/56649e0f5503460f94afa5af/html5/thumbnails/13.jpg)
13
2nd-order Linear ODEs
For example, given the LODE from before, we create the two IVPs
The plots of the solutions:
2 1
1
sin 1
2 1.5
2 0
u x x u x u x
u
u
2 1
1
sin 0
2 0
2 1
u x x u x u x
u
u
ug(x)
u0(x)
(a, ua)
(b, ub)
The Shooting Method for Boundary-value Problems
![Page 14: The Shooting Method for Boundary-value Problems Douglas Wilhelm Harder, M.Math. LEL Department of Electrical and Computer Engineering University of Waterloo](https://reader036.vdocuments.us/reader036/viewer/2022062421/56649e0f5503460f94afa5af/html5/thumbnails/14.jpg)
14
2nd-order Linear ODEs
Having found these two solutions, ug(x) and u0(x), we now want to find a linear combination
of these two such that it satisfies the second boundary value– For example, here we see
ug(x), ug(x) + u0(x), and ug(x) – u0(x)
It seems ug(x) + 2u0(x) will passclose to the second boundary point
0gu x cu x
ug(x)
ug(x) + u0(x)
ug(x) – u0(x)
(a, ua)
(b, ub)
The Shooting Method for Boundary-value Problems
![Page 15: The Shooting Method for Boundary-value Problems Douglas Wilhelm Harder, M.Math. LEL Department of Electrical and Computer Engineering University of Waterloo](https://reader036.vdocuments.us/reader036/viewer/2022062421/56649e0f5503460f94afa5af/html5/thumbnails/15.jpg)
15
2nd-order Linear ODEs
We want to find the appropriate linear combination
to match our second boundary condition
First, we note
We want
Solving this for c yields
0gu x cu x
0 0g a au a cu a u c u
0g bu b cu b u
0
b gu u bc
u b
1 0
g a
g
u a u
u a
0
10
0
1
u a
u a
The Shooting Method for Boundary-value Problems
![Page 16: The Shooting Method for Boundary-value Problems Douglas Wilhelm Harder, M.Math. LEL Department of Electrical and Computer Engineering University of Waterloo](https://reader036.vdocuments.us/reader036/viewer/2022062421/56649e0f5503460f94afa5af/html5/thumbnails/16.jpg)
16
2nd-order Linear ODEs
Easy enough; however, recall that we must find ug(x) and u0(x) but if we use dp45, the step sizes may be different…
Solution: define a system of two uncoupled equations and unknowns and solve them simultaneously
u(2)(x) = g(x) – q(x) u(1)(x) – r(x) u(x)
u(2)(x) = 0 – q(x) u(1)(x) – r(x) u(x)
The Shooting Method for Boundary-value Problems
![Page 17: The Shooting Method for Boundary-value Problems Douglas Wilhelm Harder, M.Math. LEL Department of Electrical and Computer Engineering University of Waterloo](https://reader036.vdocuments.us/reader036/viewer/2022062421/56649e0f5503460f94afa5af/html5/thumbnails/17.jpg)
17
2nd-order Linear ODEs
Using our techniques from Laboratory 5, we can write this as a system of IVPs:
w1(1)(x) = w2
(x)
w2(1)(x) = g(x) – q(x) w2(x) – r(x) w1(x)
w3(1)(x) = w4
(x)
w4(1)(x) = 0 – q(x) w4(x) – r(x) w3(x)
w1(a) = ua
w2(a) = 0
w3(a) = 0
w4(a) = 1
The Shooting Method for Boundary-value Problems
ug(x) = w1(x)ug
(1)(x) = w2(x) u0(x) = w3(x)u0
(1)(x) = w4(x)
![Page 18: The Shooting Method for Boundary-value Problems Douglas Wilhelm Harder, M.Math. LEL Department of Electrical and Computer Engineering University of Waterloo](https://reader036.vdocuments.us/reader036/viewer/2022062421/56649e0f5503460f94afa5af/html5/thumbnails/18.jpg)
18
2nd-order Linear ODEs
For example, consider the boundary-value problem
The Matlab function would be:function [dw] = f6a( x, w ) dw = [w(2); 1 - sin(x)*w(2) - w(1); w(4); 0 - sin(x)*w(4) - w(3)];end
with the initial conditions [u_a, 0, 0, 1]'
2 1sin 1
2 1.5
3 2.5
u x x u x u x
u
u
The Shooting Method for Boundary-value Problems
![Page 19: The Shooting Method for Boundary-value Problems Douglas Wilhelm Harder, M.Math. LEL Department of Electrical and Computer Engineering University of Waterloo](https://reader036.vdocuments.us/reader036/viewer/2022062421/56649e0f5503460f94afa5af/html5/thumbnails/19.jpg)
19
2nd-order Linear ODEs
For our example, we would run the following code:a = 2; b = 3; u_a = 1.5; u_b = 2.5;[x6a, u6a] = dp45( @f6a, [a, b], [u_a 0 0 1]', 0.01, 1e-8 );
c6a = (u_b - u6a(1, end))/u6a(3, end) c6a = 1.991628911663175
u6a_soln = u6a(1, :) + c6a*u6a(3, :);plot( x6a, u6a_soln, 'r' )ylim( [0, 2.5] )u6a_soln(1) ans = 1.500000000000000
u6a_soln(end) ans = 2.500000000000000
The Shooting Method for Boundary-value Problems
![Page 20: The Shooting Method for Boundary-value Problems Douglas Wilhelm Harder, M.Math. LEL Department of Electrical and Computer Engineering University of Waterloo](https://reader036.vdocuments.us/reader036/viewer/2022062421/56649e0f5503460f94afa5af/html5/thumbnails/20.jpg)
20
2nd-order Linear ODEs
Maple can find an answer, but it’s not nice…> a := 2; b := 3; u_a := 1.5; u_b := 2.5;> dsolve( {(D@@2)(u)(x) + sin(x)*D(u)(x) + u(x) = 1, u(a)=u_a, u(b)=u_b} );
The Shooting Method for Boundary-value Problems
![Page 21: The Shooting Method for Boundary-value Problems Douglas Wilhelm Harder, M.Math. LEL Department of Electrical and Computer Engineering University of Waterloo](https://reader036.vdocuments.us/reader036/viewer/2022062421/56649e0f5503460f94afa5af/html5/thumbnails/21.jpg)
21
2nd-order Linear ODEs
It takes Maple about two minute to plot the same figure– Note: this is not an issue with Maple—it is giving you the exact
solution and not a numeric approximation
The Shooting Method for Boundary-value Problems
![Page 22: The Shooting Method for Boundary-value Problems Douglas Wilhelm Harder, M.Math. LEL Department of Electrical and Computer Engineering University of Waterloo](https://reader036.vdocuments.us/reader036/viewer/2022062421/56649e0f5503460f94afa5af/html5/thumbnails/22.jpg)
22
2nd-order Linear ODEs: Example
For example, consider the boundary-value problem
u(2)(x) + 4 u(1)(x) + 7x u(x) = sin(x)
u(2) = 1.5
u(3) = 2.5
The Matlab function would be:function [dw] = f6b( x, w ) dw = [w(2); sin(x) - 4*w(2) - 7*x*w(1); w(4); 0 - 4*w(4) - 7*x*w(3)];end
The Shooting Method for Boundary-value Problems
![Page 23: The Shooting Method for Boundary-value Problems Douglas Wilhelm Harder, M.Math. LEL Department of Electrical and Computer Engineering University of Waterloo](https://reader036.vdocuments.us/reader036/viewer/2022062421/56649e0f5503460f94afa5af/html5/thumbnails/23.jpg)
23
2nd-order Linear ODEs: Example
For example, considera = 2; b = 3; u_a = 1.5; u_b = 2.5;[x6b, u6b] = dp45( @f6b, [a, b], [u_a 0 0 1]', 0.01, 1e-4 );u6b_soln = u6b(1,:) + (u_b - u6b(1,end))/u6b(3,end)*u6b(3,:);plot( x6b, u6b_soln, 'o-' );grid
The Shooting Method for Boundary-value Problems
![Page 24: The Shooting Method for Boundary-value Problems Douglas Wilhelm Harder, M.Math. LEL Department of Electrical and Computer Engineering University of Waterloo](https://reader036.vdocuments.us/reader036/viewer/2022062421/56649e0f5503460f94afa5af/html5/thumbnails/24.jpg)
24
2nd-order Linear ODEs: Example
Maple can find an answer, but it’s not nice…> a := 2; b := 3; u_a := 1.5; u_b := 2.5;> dsolve( {(D@@2)(u)(x) + 4*D(u)(x) + 7*x*u(x) = sin(x), u(a) = u_a, u(b) = u_b}, u(x) );
The Shooting Method for Boundary-value Problems
![Page 25: The Shooting Method for Boundary-value Problems Douglas Wilhelm Harder, M.Math. LEL Department of Electrical and Computer Engineering University of Waterloo](https://reader036.vdocuments.us/reader036/viewer/2022062421/56649e0f5503460f94afa5af/html5/thumbnails/25.jpg)
25
2nd-order Linear ODEs: Example
Comparing the results with Maple’s plot, we see they are similar
The Shooting Method for Boundary-value Problems
![Page 26: The Shooting Method for Boundary-value Problems Douglas Wilhelm Harder, M.Math. LEL Department of Electrical and Computer Engineering University of Waterloo](https://reader036.vdocuments.us/reader036/viewer/2022062421/56649e0f5503460f94afa5af/html5/thumbnails/26.jpg)
26
2nd-order Linear ODEs: Example
If we repeat using b = 4, we get significantly more varying, but still similar, graphs
The Shooting Method for Boundary-value Problems
![Page 27: The Shooting Method for Boundary-value Problems Douglas Wilhelm Harder, M.Math. LEL Department of Electrical and Computer Engineering University of Waterloo](https://reader036.vdocuments.us/reader036/viewer/2022062421/56649e0f5503460f94afa5af/html5/thumbnails/27.jpg)
27
2nd-order Non-linear ODEs
What happens if the ODE is not linear?– In this case, there is no guarantee that we can find a solution
using this simple technique– Instead, we will use
u(2)(x) = f(x, u(x), u(1)(x))
and let us(x) be the solution to the IVP
u(a) = ua
u(1) (a) = s
Now, define a new function
err(s) = us(b) – ub
The Shooting Method for Boundary-value Problems
![Page 28: The Shooting Method for Boundary-value Problems Douglas Wilhelm Harder, M.Math. LEL Department of Electrical and Computer Engineering University of Waterloo](https://reader036.vdocuments.us/reader036/viewer/2022062421/56649e0f5503460f94afa5af/html5/thumbnails/28.jpg)
28
2nd-order Non-linear ODEs
When this function has a zero, we have a solution to the boundary-value problem
err(s) = us(b) – ub
What is err(s) in Matlab?function [du_b] = err_shot( s ) [t_out, u_out] = ... dp45( @f, [a, b], [u_a, s], h, eps_abs );
du_b = u_out(1, end) - u_b;end
The Shooting Method for Boundary-value Problems
![Page 29: The Shooting Method for Boundary-value Problems Douglas Wilhelm Harder, M.Math. LEL Department of Electrical and Computer Engineering University of Waterloo](https://reader036.vdocuments.us/reader036/viewer/2022062421/56649e0f5503460f94afa5af/html5/thumbnails/29.jpg)
29
2nd-order Non-linear ODEs
When this function has a zero, we have a solution tothe boundary-value problem
err(s) = us(b) – ub
In reality, however, it will require a number of other parameters:
function [du_b] = err_shot(s, f, x_rng, u_bndry, h, eps_abs)
u_a = u_bndry(1); u_b = u_bndry(2);
[~, u_out] = dp45( f, x_rng, [u_a, s]', h, eps_abs );
du_b = u_out(1, end) - u_b;end
The Shooting Method for Boundary-value Problems
![Page 30: The Shooting Method for Boundary-value Problems Douglas Wilhelm Harder, M.Math. LEL Department of Electrical and Computer Engineering University of Waterloo](https://reader036.vdocuments.us/reader036/viewer/2022062421/56649e0f5503460f94afa5af/html5/thumbnails/30.jpg)
30
Secant Method
We will use the secant method for fining this root:– Suppose we are trying to find a root of a real-valued function of a
real variable err(s)
– Suppose s1 and s2 are two initial approximations of the root
s1s2
err(s)
The Shooting Method for Boundary-value Problems
![Page 31: The Shooting Method for Boundary-value Problems Douglas Wilhelm Harder, M.Math. LEL Department of Electrical and Computer Engineering University of Waterloo](https://reader036.vdocuments.us/reader036/viewer/2022062421/56649e0f5503460f94afa5af/html5/thumbnails/31.jpg)
31
Secant Method
We can find a better approximation of the root by finding the interpolating straight line that passes through these points
s1s2
err(s)
The Shooting Method for Boundary-value Problems
![Page 32: The Shooting Method for Boundary-value Problems Douglas Wilhelm Harder, M.Math. LEL Department of Electrical and Computer Engineering University of Waterloo](https://reader036.vdocuments.us/reader036/viewer/2022062421/56649e0f5503460f94afa5af/html5/thumbnails/32.jpg)
32
Secant Method
The formula for this new point is
s1s2
1 2 2 13
2 1
err err
err err
s s s ss
s s
err(s)
The Shooting Method for Boundary-value Problems
s3
![Page 33: The Shooting Method for Boundary-value Problems Douglas Wilhelm Harder, M.Math. LEL Department of Electrical and Computer Engineering University of Waterloo](https://reader036.vdocuments.us/reader036/viewer/2022062421/56649e0f5503460f94afa5af/html5/thumbnails/33.jpg)
33
Secant Method
In the first case, we considered linear ODEs– Essentially, what we are doing here is asking:
Given these two approximations,
what would our next approximation be if the ODE was linear?
s1s2
err(s)
The Shooting Method for Boundary-value Problems
s3
![Page 34: The Shooting Method for Boundary-value Problems Douglas Wilhelm Harder, M.Math. LEL Department of Electrical and Computer Engineering University of Waterloo](https://reader036.vdocuments.us/reader036/viewer/2022062421/56649e0f5503460f94afa5af/html5/thumbnails/34.jpg)
34
Secant Method
Now, suppose we have s2 and s3, the next step is to use these approximations to find the next approximation, s4, and so on...
s1s2
2 3 3 24
3 2
err err
err err
s s s ss
s s
err(s)
The Shooting Method for Boundary-value Problems
s3
![Page 35: The Shooting Method for Boundary-value Problems Douglas Wilhelm Harder, M.Math. LEL Department of Electrical and Computer Engineering University of Waterloo](https://reader036.vdocuments.us/reader036/viewer/2022062421/56649e0f5503460f94afa5af/html5/thumbnails/35.jpg)
35
Secant Method
Thus, we will continue to iterate, using the secant method at each step...
With any iterative numerical method, we must know under what conditions we will:– Halt with success, and– Indicate a failure to find a solution
After all, not all iterative numerical methods converge...
The Shooting Method for Boundary-value Problems
![Page 36: The Shooting Method for Boundary-value Problems Douglas Wilhelm Harder, M.Math. LEL Department of Electrical and Computer Engineering University of Waterloo](https://reader036.vdocuments.us/reader036/viewer/2022062421/56649e0f5503460f94afa5af/html5/thumbnails/36.jpg)
36
Secant Method
For the secant method, we must have two approximations, s1 and s2
First, if |err(s1)| < |err(s2)|, we will swap s1 and s2
– We’re assuming that s2 is more accurate
The Shooting Method for Boundary-value Problems
![Page 37: The Shooting Method for Boundary-value Problems Douglas Wilhelm Harder, M.Math. LEL Department of Electrical and Computer Engineering University of Waterloo](https://reader036.vdocuments.us/reader036/viewer/2022062421/56649e0f5503460f94afa5af/html5/thumbnails/37.jpg)
37
Secant Method
We will iterate at most Nmax times:– With each iteration, we will approximate a new point s
– If |s2 – s| < estep and |err(s)| < eabs, we will assume we are finished and we will return the value s (shooting, however, will take one more step)
– Otherwise, we will set s1 = s2 and s2 = s
If we have iterated Nmax times and not found a solution, we will throw an exception with an appropriate message
The Shooting Method for Boundary-value Problems
![Page 38: The Shooting Method for Boundary-value Problems Douglas Wilhelm Harder, M.Math. LEL Department of Electrical and Computer Engineering University of Waterloo](https://reader036.vdocuments.us/reader036/viewer/2022062421/56649e0f5503460f94afa5af/html5/thumbnails/38.jpg)
38
The Shooting Method
Normally, the secant method simply returns the slope
Your function, shooting, however, will have to return the x- and u-values corresponding to that optimal slope– Thus, your last steps before you successfully return will be:
[x_out, u_out] = dp45( f, x_rng, [u_bndry(1), s]', h, eps_abs );
return;
The Shooting Method for Boundary-value Problems
![Page 39: The Shooting Method for Boundary-value Problems Douglas Wilhelm Harder, M.Math. LEL Department of Electrical and Computer Engineering University of Waterloo](https://reader036.vdocuments.us/reader036/viewer/2022062421/56649e0f5503460f94afa5af/html5/thumbnails/39.jpg)
39
The Shooting Method
The arguments offunction [x_out, u_out] = shooting( s1, s2, f, x_rng, u_bndry, ... h, eps_abs, eps_step, N_max )
are as follows:s1 and s2 are the two approximations of the slopes
f is a function handle for the differential equation: u(2)(x) = f(x, u(x), u(1)(x))
[a, b] is a row vector defining the range on which we are approximating the boundary-value problem
[ua, ub] is a row vector defining the boundary conditions:
u(a) = ua and u(b) = ub
h is the initial step size for the function dp45eabs is the parameter passed to dp45 and is also the parameter
used by the secant method
estep is the parameter used by the secant method for the step size
Nmax is the parameter used by the secant method to define themaximum number of iterations
The Shooting Method for Boundary-value Problems
![Page 40: The Shooting Method for Boundary-value Problems Douglas Wilhelm Harder, M.Math. LEL Department of Electrical and Computer Engineering University of Waterloo](https://reader036.vdocuments.us/reader036/viewer/2022062421/56649e0f5503460f94afa5af/html5/thumbnails/40.jpg)
40
The Shooting Method
Question: what do we use as initial conditions?
Answer: as an engineer, you will understand your problem; you should know the expected behaviour around the point x = a– In these laboratories, you will be given the initial points– In reality, you will understand what they should be when you get
there
The Shooting Method for Boundary-value Problems
![Page 41: The Shooting Method for Boundary-value Problems Douglas Wilhelm Harder, M.Math. LEL Department of Electrical and Computer Engineering University of Waterloo](https://reader036.vdocuments.us/reader036/viewer/2022062421/56649e0f5503460f94afa5af/html5/thumbnails/41.jpg)
41
The Shooting Method
Consider the following non-linear boundary-value problem:
The corresponding function isfunction [dw] = f6c( x, w ) dw = [w(2); sin(x) - 4*w(2)*w(1) + 2*x*w(1)^2];end
22 14 2 sin
2 1.5
3 2.5
u x u x u x x u x x
u
u
The Shooting Method for Boundary-value Problems
![Page 42: The Shooting Method for Boundary-value Problems Douglas Wilhelm Harder, M.Math. LEL Department of Electrical and Computer Engineering University of Waterloo](https://reader036.vdocuments.us/reader036/viewer/2022062421/56649e0f5503460f94afa5af/html5/thumbnails/42.jpg)
42
The Shooting Method
When I run the function [x6c, u6c] = shooting( -3, -3.1, @f6c, [2, 3], [1.5, 2.5]', ... 0.01, 1e-6, 1e-6, 20 );
I get a solution after four iterations where the approximations of the initial slopes are:
–3.326745004558498
–3.323136496135223
–3.323176635129875
–3.323176642445732
These last two slopes are sufficiently close enough and the u6c(1, end) = 2.499999999999991 close enough to 2.5
The Shooting Method for Boundary-value Problems
![Page 43: The Shooting Method for Boundary-value Problems Douglas Wilhelm Harder, M.Math. LEL Department of Electrical and Computer Engineering University of Waterloo](https://reader036.vdocuments.us/reader036/viewer/2022062421/56649e0f5503460f94afa5af/html5/thumbnails/43.jpg)
43
The Shooting Method
We can look at the plot and the result:plot( xs, us(1,:) )
us(1,end) ans = 2.499999999999991
length( xs ) ans = 36
The Shooting Method for Boundary-value Problems
![Page 44: The Shooting Method for Boundary-value Problems Douglas Wilhelm Harder, M.Math. LEL Department of Electrical and Computer Engineering University of Waterloo](https://reader036.vdocuments.us/reader036/viewer/2022062421/56649e0f5503460f94afa5af/html5/thumbnails/44.jpg)
44
The Shooting Method
You might get slightly different values depending on your implementation of the secant method; however, the final result should bereasonably close
The Shooting Method for Boundary-value Problems
![Page 45: The Shooting Method for Boundary-value Problems Douglas Wilhelm Harder, M.Math. LEL Department of Electrical and Computer Engineering University of Waterloo](https://reader036.vdocuments.us/reader036/viewer/2022062421/56649e0f5503460f94afa5af/html5/thumbnails/45.jpg)
45
The Shooting Method
Plotting approximations with the various slopes:slopes = [-3 -3.1 -3.326745004558498 -3.323136496135223 ... -3.323176635129875 -3.323176642445732];for s = slopes [x6s, u6s] = dp45( @f6c, [2, 3], [1.5, s]', 0.01, 1e-6 ); plot( x6s, u6s(1,:) )
u6s(1,end)end
s1 = 3
s2 = 3.1
All others...
The Shooting Method for Boundary-value Problems
![Page 46: The Shooting Method for Boundary-value Problems Douglas Wilhelm Harder, M.Math. LEL Department of Electrical and Computer Engineering University of Waterloo](https://reader036.vdocuments.us/reader036/viewer/2022062421/56649e0f5503460f94afa5af/html5/thumbnails/46.jpg)
46
The Shooting Method
If you plot the relative errors of the approximation of u6s(1,end) as an approximation of ub = 2.5, we observe the fast (i.e., O(hf)) convergence of the secant method
s u6s(1,end) AbsoluteError
–3 2.668638013935938 1.686 × 10–1
–3.1 2.617026509067240 1.170 × 10–1
–3.326745004558498 2.498107476136670 1.893 × 10–3
–3.323136496135223 2.500021288156047 2.129 × 10–5
–3.323176635129875 2.500000003879338 3.879 × 10–9
–3.323176642445732 2.499999999999991 7.105 × 10–15
The Shooting Method for Boundary-value Problems
![Page 47: The Shooting Method for Boundary-value Problems Douglas Wilhelm Harder, M.Math. LEL Department of Electrical and Computer Engineering University of Waterloo](https://reader036.vdocuments.us/reader036/viewer/2022062421/56649e0f5503460f94afa5af/html5/thumbnails/47.jpg)
47
Hints
You will work with various values of s and err(s) – Instead of continually recalculating value err(s), just calculate
err1 = err_shot( s1 ); err2 = err_shot( s2 );
and when you calculate a new value of s, just use a simpler expression with the variables s1, s2, err1 and err2 and then immediately calculate
errs = err( s );
– When you update s1 and s2, update err1 and err2
The Shooting Method for Boundary-value Problems
![Page 48: The Shooting Method for Boundary-value Problems Douglas Wilhelm Harder, M.Math. LEL Department of Electrical and Computer Engineering University of Waterloo](https://reader036.vdocuments.us/reader036/viewer/2022062421/56649e0f5503460f94afa5af/html5/thumbnails/48.jpg)
48
Summary
We have looked at using the function dp45 to approximate a boundary-value problem– The shooting method converts a BVP into an IVP– For linear IVPs, we use the ODE and the homogeneous ODE
and find a linear combination of the two solutions– For non-linear IVPs, we use dp45 and the secant method to
guide us to an approximation
The Shooting Method for Boundary-value Problems
![Page 49: The Shooting Method for Boundary-value Problems Douglas Wilhelm Harder, M.Math. LEL Department of Electrical and Computer Engineering University of Waterloo](https://reader036.vdocuments.us/reader036/viewer/2022062421/56649e0f5503460f94afa5af/html5/thumbnails/49.jpg)
49
References
[1] Glyn James, Modern Engineering Mathematics, 4th Ed., Prentice Hall, 2007.
[2] Glyn James, Advanced Modern Engineering Mathematics, 4th Ed., Prentice Hall, 2011.
[3] John H. Mathews and Kurtis D. Fink, Numerical Methods using Matlab, 4th Ed., Prentice Hall, 2004, pp. 529-534.
[4] Shooting Method, http://en.wikipedia.org/wiki/Shooting_method.
The Shooting Method for Boundary-value Problems