Linear and Nonlinear Shooting Method
Linear and Nonlinear Shooting Method
•
Pro ems or Or Ina
•
I erentia uations
• • •
r--..... ,/
S S
f;::.
I x
0
w(x)
tfw S qx .
dx 2 (x) = Elw(x) + 2E/x - f),
where w(x) is the deflection a distance x from the left end of the beam,
and l, q, E, S, and I represent, respectively, the length of the beam, the
intensity of the uniform load, the modulus of elasticity, the stress at the
endpoints, and the central moment of inertia. Since no detlection occurs
at the ends of the beam, we also have the two boundary conditions
w(O) = w(l) = O.
646 C HAP T E R 11 • Boundary-Value Problems jor Ordinary Differential Equations
The differential equations in Chapter 5 are of first order and have one initial condi-
tion to satisfy. Later in the chapter we saw that the techniques could be extended to sys-
tems of equations and then to higher-order equations, but all the specified conditions are
on the same endpoint. These are initial-value problems. In this chapter we show how to
approximate the solution to boundary-value problems, differential equations with condi-
tions imposed at different points. For first-order differential equations, only one condition
is specified, so there is no distinction between initial-value and boundary-value.problems.
We will be considering second-order equations with two boundary values.
Physical problems that are position-dependent rather than time-dependent are often
described in telms of differential equations with conditions imposed at more than one point.
The two-point boundary-value problems in this chapter involve a second-order differential
equation of the form
D = {(x, y, y') I a <x < b, -00 < y < 00, -00 < y' < oo},
and that the partial derivatives fy and f y' are also continuous on D. If
(i) fy (x, y, y') > 0, for all (x, y, y') E D, and
(ii) a constant M exists, with
Since
fy(x, y, y') = xe- XY > 0 and fy'(X, y, y') = 1 - cos y'l < 1.
is linear. Problems of this type frequently occur, and in this situation, Theorem 11.1 can
be simplified.
satisfies
(i) p(x), q(x), and rex) are continuous on [a, b],
(ii) q(x) > 0 on [a, b],
and
Theorem 5.16 in Section 5.9 ensures that under the hypotheses in Corollary 11.2, both
problems have a unique solution. Let Yl (x) denote the solution to (11.3), Y2 (x) denote the
solution to (11.4), and let
(11.5)
648 C HAP T E R 11 • Boundary-Value Problems for Ordinary Differential Equations
Then
"( ) _ I/()
Y X - YI X
+ fJ - YI (b) !/( )
Yo x .
Y2(b) ~
So
fJ - YI (b) ( ( ) I
1/ (
Y =p X YI +q
) I ()
X YI +r(x
)
+ yz(b) px h+q(X)Y2
)
I fJ-YI(b) I fJ - YI (b)
= P (X) YI + Y2(b) Y2 + q(x) YI + Y2(b) Y2 + rex)
Hence, y(x) is the unique solution to the linear boundary-value problem, provided, of
course, that Y2 (b) "I O. (That Y2 (b) = 0 is in conflict with the hypotheses of Corollary 11.2
is considered in Exercise 8.)
The Shooting method for linear equations is based on the replacement of the linear
boundary-value problem by the two initial-value problems (11.3) and (11.4). Numerous
methods are available from Chapter 5 for approximating the solutions YI (x) and Y2 (x),
and once these approximations are available, the solution to the boundary-value problem
is approximated using Eq. (11.5). Graphically, the method has the appearance shown in
Figure 11.1.
Figure 11.1
Y
f3
f3 - y](b)
y(x) = Yl(X) + yz(b) Yz(x)
Yl(X)
a b x
11.1 The Linear Shooting Method 649
Algorithm 11.1 uses the fourth-order Runge-Kutta technique to find the approxima-
tions to YI (x) and Y2(X), but another technique for approximating the solutions to initial-
value problems can be substituted into Step 4.
The algorithm has the additional feature of obtaining approximations for the derivative
of the solution to the boundary-value problem as well as to the solution of the problem
itself. The use of the algorithm is not restricted to those problems for which the hypotheses
of Corollary 11.2 can be verified; it will work for many problems that do not satisfy these
hypotheses.
Linear Shooting
To approximate the solution of the boundary-value problem
(Note: Equations (11.3) and 01.4) are written as first-order systems and solved.)
INPUT endpoints a, b; boundary conditions ex, (3; number of subintervals N.
OUTPUT approximations w].i to y(Xi); W2.i to y'(Xi) for each i = 0, I, .. , , N.
Step 7 Seth=(b-a)/N;
UIO=ex;
,
U2,O = 0;
Vl,O = 0;
V2,O = 1.
Step 2 For i = 0, ... , N - 1 do Steps 3 and 4.
(The Runge-Kutta methodfor systems is used in Steps 3 and 4.)
Step 3 Set x = a + ih.
Step 4 Set kl , 1 = hU2 , i;
k1,2 = h [p(x )U2,i + q (x )ul,i + r(x)];
k 2,1 = h [U2,i + ~k1,2];
k2,2 = h [p(x + h/2) (U2,i + ~kl,2)
+q(x + h/2) (U].i + ~kl,l) + rex + h/2)];
k 3,1 = h [U2,i + ~k2,2];
k 3 ,2 = h [p(x+ h/2) (U2,i + ~k2,2)
+q(x + h/2)(u].i + ~k2,1) + rex + h/2)];
+ k 3 ,2];
k 4 ,1 = h [U2,i
k4 ,2 = h [p(x + h)(U2,i + k 3 ,2) + q(x + h)(ul,i + k 3 ,1) + rex + h)];
Ul,i+l = UI,i + ~ [kl,l + 2k2,1 + 2k3 ,1 + k4 ,1];
2 /
/I 2 sin(lnx)
y = --y + -2y + --::-- 1< X < 2, y(1) = 1, y(2) = 2,
X x x2 '
and
2, 2 0
Y2
/I
= --Y2 + -Y2,
x X2
1 <x ~ 2, Y2(l) = , 1
Y2(l) = 1.
The results of the calculations, using Algorithm 11.1 with N = 10 and h = 0.1, are
given in Table 11.1. The value listed as U l.i approximates YI (Xi), the value vl,i approxi-
mates Y2 (Xi), and Wi approximates
•
Table 11.1 x, ,
U I,. ,
VI , . Wi y(x;) Iy(x;) - wd
1.0 1.00000000 0.00000000 1.00000000 1.00000000
1.1 1.00896058 0.09117986 1.09262917 1.09262930 1.43 x 10-7
1.2 1.03245472 0.16851175 1.18708471 1.18708484 1.34 x 10- 7
1.3 1.06674375 0.23608704 1.28338227 1.28338236 9.78 x 10- 8
1.4 1.10928795 0.29659067 1.38144589 1.38144595 6.02 x 10- 8
1.5 1.15830000 0.35184379 1.48115939 1.48115942 3.06 x 10- 8
1.6 1.21248372 0.40311695 1.58239245 1.58239246 1.08 x 10- 8
1.7 1.27087454 0.45131840 1.68501396 1.68501396 5.43 x lO- JO
1.8 1.33273851 0.49711137 1.78889854 1.78889853 5.05 x 10- 9
1.9 1.39750618 0.54098928 1.89392951 1.89392951 4.41 x 10- 9
2.0 1.46472815 0.58332538 2.00000000 2.00000000
The accurate results in this example are due to the fact that the fourth-order Runge-
Kutta method gives O(h4) approximations to the solutions of the initial-value problems.
Unfortunately, because of roundoff errors, there can be problems hidden in this technique.
If ydx) rapidly increases as x goes from a to b, then U I,N ~ YI (b) will be large. If f3 is
small in magnitude compared to UI,N. the teIm W2,O = (f3 - UI,N )/VI,N will be approxi-
mately -UI.N/VI,N. The computations in Step 6 then become
UI,N
WI=uI ,I +W20VI'~UI'-
,,' ,I VI , i,
VI,N
Ul,N
W2 = U2 ,I + W2 OV2 . ~ U2
• ,l ,l. - V2,i,
Vl,N
which allows a possibility of a loss of significant digits due to cancellation. However, since
UI,i is an approximation to YI (Xi), the behavior of Yl can easily be monitored, and if Ul,i
increases rapidly from a to b, the shooting technique can be employed backward from
Xo = b to XN = a; that is, solving instead the initial-value problems
and
If this reverse shooting technique still gives cancellation of significant digits and if
increased precision does not yield greater accuracy, other techniques must be used, such
as those presented later in this chapter. In general, however, if Ul,i and VI,i are O(h n )
approximations to YI (Xi) and Y2 (Xi), respectively, for each i = 0, 1, ... , N, then Wl,i will
be an O(h n ) approximation to Y(Xi). In particular,
VI .
Iwl,i - y(xi)1 < Kh n
1+ ,t,
VI,N
has the solution y(x) = e 2 (e 4 - l)-l(e2< - e-2<) + x. Use the Linear Shooting method to
approximate the solution, and compare the results to the actual solution.
1
a. With h = !.
2'
b. With h = 4 •
has the solution y(x) = - 1~ (sin x + 3 cos x). Use the Linear Shooting method to approximate
the solution, and compare the results to the actual solution.
a. With h = ;; b. With h = ;.
3. Use the LinearShooting method to approximate the solution to the following boundary-value
problems.
a. y"=-3y'+2y+2x+3, O<x<l, y(O) =2, y(I)=I; useh=O.1.
b. yll=-;y'+~y-~lnx, 1 <x <2, y(1)=-~, y(2)=ln2; useh=0.05.
c. y"=-(x+I)y'+2y+(1-x 2 )e- x , O<x<l, y(O)=-I, y(1)=O; useh=O.1.
d. yll=~+!>y+l:X_I, l<x<2,y(1)=y(2)=O;useh=0.1.
4. Although q(x) < 0 in the following boundary-value problems, unique solutions exist and
are given. Use the Linear Shooting Algorithm to approximate the solutions to the following
problems, and compare the results to the actual solutions.
a. y" + y = 0, O::'S x < ;, yeO) = I, y(;) = 1; use h = ;0;
actual solution
y(x) = cosx + (.J2 - I) sinx.
b. y" + 4y = cosx, 0 < x < ;, yeO) = 0, y(;) = 0; use h = ~; actual solution
y(x) = -~ cos2x -1 sin2x + ~ cosx.
c. y" = -;y' - ~y+ -!r lnx, 1 <x< 2, y(1) = ;, y(2) = In2; useh = 0.05; actual
solution y(x) = x4 - !r
x
+ lnx - 3
2•
d. y" = 2y' - Y + xe x - x, 0 < x < 2, yeO) = 0, y(2) = -4; use h = 0.2; actual
solution y(x) = ~x3eX - ~xex + 2ex - x - 2.
11.2 The Shooting Method for Nonlinear Problems 653
S. Use the Linear Shooting Algorithm to approximate the solution y = e- lOx to the boundary-
value problem
d 2u 2 du
__
dr2
+-
r dr
=0, R I <r<R 2, u(R I ) = VI, U(R2) =0.
8. Show that, under the hypothesis of Corollary 11.2, if Y2 is the solution to y" = p(x) y' + q (x) y
and Y2(a) = Y2(b) = 0, then Y2 = O.
9. Consider the boundary-value problem
y" = f(x, y, y'), a::::: x < b, yea) = 0', y(b) = {3, (1l.6)
is similar to the linear technique, except that the solution to a nonlinear problem cannot be .
expressed as a linear combination of the solutions to two initial-value problems. Instead,
we approximate the solution to the boundary-value problem by using the solutions to a
654 C HAP T E R 11 • Boundary-Value Problems jar Ordinary Differential Equations
sequence of initial-value problems involving a parameter t. These problems have the fonn
Figure 11.2
y
f3
y(b, to) (b, y(b, to»
y(x, to)
Slope to
a (a, a)
a b x
y(b, t) - fJ = O. ( 11.8)
Figure 113
Y
y(b, t 2) Y(X, t 2)
- f3 ------------------- -
y(b, t 3) Y(X, t 3 )
y(b, t I) y(X, t I)
y(b, to) y(X, to)
a (a, a)
a b x
To use the more powerful Newton's method to generate the sequence {tk}, only one
initial approximation, to, is needed. However, the iteration has the form
y(b, tk-d - f3
tk = tk-I - d ' (11.9)
¥,(b, tk-I)
and it requires the knowledge of (dyjdt)(b, tk-I). This presents a difficulty since an ex-
plicit representation for y(b, t) is not known; we know only the values y(b, to), y(b, tl)'
... , y(b, tt-I).
Suppose we rewrite the initial-value problem (11.7), emphasizing that the solution
depends on both x and the parameter t:
y"(X, t) = f(x, y(x, t), y'(x, t», a::5 x ::5 b, yea, t) = a, y'(a, t) = t. (11.10)
We have retained the prime notation to indicate differentiation with respect to x. Since
we need to determine (dyjdt)(b, t) when t = tk-I, we first take the partial derivative of
(11.10) with respect to t. This implies that
ay" af ,
a (x,t)= (x,y(x,t),y(x,t»
t at
af ,ax af ,ay
= ax (x, y(x, t), y (x, t» at + ay (x, y(x, t), y (x, t» at (x, t)
af ,ay'
+ (x,y(x,t),Y(X,t» (X,t).
oy' at
Since x and t are independent, ax j at = 0 and
ay" af ,ay af ,ay'
a (X,t) = a (x,y(x,t),y(x,t»a (X,t)+ a (x,y(x,t),y(x,t» (x,t),
t y t y' at
(11.11)
656 C HAP T E R 11 • Boundary-Value Problems for Ordinary Differential Equations
ay ay'
-(a, t) =0 and -(a, t) = 1.
at at
If we simplify the notation by using z(x, t) to denote (ay / at) (x , t) and assume that
the order of differentiation of x and t can be reversed, (11.11) with the initial conditions
becomes the initial-value problem
/I af , af , ,
Z (x,t)= (x,y,y)z(x,t)+ (x,y,y)z(x,t), (1l.l2)
ay ay'
a::: x <b, z(a, t) = 0, z'(a, t) = 1.
Newton's method therefore requires that two initial-value problems be solved for each
iteration, (1l.l0) and (11.12). Then from Eq. (11.9),
y(b, tk-I) - fJ
tk = tk-I - . (1l.l3)
z(b, tk-I)
Of course, none of these initial-value problems is solved exactly; the solutions are ap-
proximated by one of the methods discussed in Chapter 5. Algorithm 11.2 uses the Runge-
Kutta method of order four to approximate both solutions required by Newton's method.
A similar procedure for the Secant method is considered in Exercise 4.
(Note: Equations (11.10) and (11.12) are written as first-order systems and solved.)
INPUT endpoints a, b; boundary conditions IX, fJ; number of subintervals N > 2; toler-
ance TOL; maximum number of iterations M.
OUTPUT approximations WI,; to y(x;); WZ,; to y'(x;) for each i = 0,1,.,. , N or a
message that the maximum number of iterations was exceeded.
k; I
, = huz;
k;,z = h[fy(x, WI,i-l, WZ,i-I)UI
1 3' 43
Y = 8 (32 + 2x - yy ),
1/
I :::: x < 3, y(1) = 17, y(3) = 3 '
and
Z
" = ay
at Z + ay'Z
at, = - 81"
(y Z + yz), 1:::: x <3, z(1
) = 0, Z
' (1) = 1,
then we need four iterations and t4 = -14.000203. The results obtained for this value of t
are shown in Table 11.2. •
Although Newton's method used with the shooting technique requires the solution
of an additional initial-value problem, it will generally give faster convergence than the
Secant method. Both me~ods are only locally convergent since they require good initial
approximations. For a general discussion of the convergence of the shooting techniques
for nonlinear problems, the reader is referred to the excellent book by Keller [Keller. H).
In that reference, more general boundary conditions are discussed. It is also noted that the
shooting technique for nonlinear problems is sensitive to roundoff errors, especially if the
solution y(x) and z(x, t) are rapidly increasing functions of x on [a, b).
1 1
Y" = 2y,3 -1 < x :::: 0, y(-I)=2' yeO) = 3'
= 1/(x + 3).
Compare your results to the actual solution y(x)
3. Use the Nonlinear Shooting method with TOL = 10-4 to approximate the solution to the fol-
lowing boundary-value problems. The actual solution is given for comparison to your results.
a. y" = y3 - yy', 1 < x < 2, y(1) = ~, y(2) = t; use h = 0.1; actual solution
y(x) = (x + I)-I.
b. y" = 2 y 3 - 6y - 2x 3 , 1:::: x < 2, y(l) = 2, y(2) = ~; use h = 0.1; actual solution
y(x) = x + X-I
c. y" = y' + 2(y -lnx)3 - X-I, 2 <x < 3, y(2) = ; + In2, y(3) = ~ + In3; use
h = 0.1; actual solution y(x) = X-I + lnx.
d. y" = [x2(y')2 - 9y2 + 4x 6 J1x 5 , 1 < x < 2, y(l) = 0, y(2) = In256; use h = 0.05;
actual solution y(x) = x 3 1nx.
4. Change Algorithm 11.2 to incorporate the Secant method instead of Newton's method. Use
to = (f3 - a)/(b - a) and tl = to + (f3 - y(b, to»/(b - a).
5. Repeat Exercise 3(a) and 3(c) using the Secant algorithm derived in Exercise 4, and compare
the number of iterations required for the two methods.
660 C HAP T E R 11 • Boundary-Value Problems for Ordinary Differential Equations
governs the flow of current in a vacuum tube with three internal elements. Let f..t = ~, yeO) =
0, and y(2) = 1. Approximate the solution yet) for t = 0.2i, where I < i ::5 9.
y" = p(x)y' + q(x)y + rex), a <X < b, yea) = a, y(b) = {3, (11.14)
requires that difference-quotient approximations be used to approximate both y' and y".
First, we select an integer N > 0 and divide the interval [a, b] into (N + 1) equal subin-
tervals whose endpoints are the mesh points Xi = a + ih, for i = 0, 1, ... , N + 1, where
h = (b - a)j(N + 1). Choosing the step size h in this manner facilitates the application
of a matrix algorithm from Chapter 6, which solves a linear system involving an N x N
matrix.
At the interior mesh points, Xi, for i = 1, 2, ... , N, the differential equation to be
approximated is
Expanding y in a third Taylor polynomial about Xi evaluated at Xi+1 and Xi-I, we have,
assuming that y E C 4 [Xi_l, xi+d,