6 TheShootingMethod
6 TheShootingMethod
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
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 )
2nd-order ODEs
A boundary-value problem in one dimension is any 2ndorder 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))
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
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)?
2nd-order ODEs
We will consider two possible cases:
When the ODE is linear, and When it is not
10
11
g(x)
g x c 0 g x
12
13
(b, ub)
ug(x)
u0(x)
14
of these two such that it satisfies the second boundary value (b, u )
For example, here we see ug(x), ug(x) + u0(x), and ug(x) u0(x)
b
It seems ug(x) + 2u0(x) will pass close to the second boundary point
ug(x) u0(x)
15
u g a ua
1
ug a 0
u0 a 0
u0 a 1
1
ub u g b u0 b
16
17
18
19
20
21
22
23
24
25
26
27
28
29
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
err(s)
s2
s1
31
Secant Method
We can find a better approximation of the root by finding the interpolating straight line that passes through these points
err(s)
s2
s1
32
Secant Method
The formula for this new point is
s3 s1 err s2 s2 err s1 err s2 err s1
err(s)
s3
s2
s1
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?
err(s)
s3
s2
s1
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... s2 err s3 s3 err s2
s4 err s3 err s2
err(s)
s3
s2
s1
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
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
Were assuming that s2 is more accurate
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
38
39
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 dp45 eabs 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 the maximum number of iterations
40
41
42
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
43
44
45
46
u6s(1,end)
Absolute Error
2.668638013935938 1.686 101 2.617026509067240 1.170 101 2.498107476136670 2.500021288156047 2.500000003879338 2.499999999999991 1.893 103 2.129 105 3.879 109 7.105 1015
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
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
49
References
[1] Glyn James, Modern Engineering Mathematics, 4th Ed., Prentice Hall, 2007. Glyn James, Advanced Modern Engineering Mathematics, 4th Ed., Prentice Hall, 2011.
[2]
[3]
John H. Mathews and Kurtis D. Fink, Numerical Methods using Matlab, 4th Ed., Prentice Hall, 2004, pp. 529-534.
Shooting Method, http://en.wikipedia.org/wiki/Shooting_method.
[4]