(6.2) - The Shooting Method for Nonlinear Problems Consider the

advertisement
(6.2) - The Shooting Method for Nonlinear Problems
Consider the boundary value problems (BVPs) for the second order differential equation of the form
(*) y ′′  fx, y, y ′ , a ≤ x ≤ b, ya   and yb  .
When fx, y, y ′  is linear in y and y ′ , the Shooting Method introduced in Section 6.1 solves a system of two
initial value problems and the solution yx of the boundary value problem (*) is of the form
 − y 1 b
y 2 x
yx  y 1 x 
y 2 b
where y 1 x and y 2 x are solutions of two initial value problems, respectively. Now we consider the cases
where fx, y, y ′  is not linear in y and y ′ . Assume a given boundary value problem has a unique solution
yx. We will approximate the solution yx by solving a sequence of initial value problems
(**) y ′′  fx, y, y ′ , a ≤ x ≤ b, ya  , y ′ a  s k
where s k are real numbers. Let yx, s k  be solution of the initial value problem (**). We want to have a
sequence s k  so that
lim yx, s k   yx.
k→
One of choices for s 0 is
−
yb − ya

.
b−a
b−a
How to choose s k for k ≥ 1? Consider choose s such that
(***) yb, s −   0,
that is s is a solution of the equation. Observe that the equation yb, s −   0 is a nonlinear equation in
one variable. In Chapter 2, we have studied numerical methods: Bisection Method, Newton Method,
Secant Method, Fixed-Point Method, for nonlinear equations of the form gs  0. For given s 0 and
s 1 , the Secant Method computes s k for k ≥ 2 as follows
gs k−1 s k−1 − s k 
.
s k  s k−1 −
gs k−1  − gs k−2 
For given s 0 , the Newton Method computes s k for k ≥ 1 as follows
gs 
s k  s k−1 − ′ k−1 .
g s k−1 
These methods can be used here to solve the nonlinear equation (***).
1. Use the Secant Method to approximate the solution of yb, s −   0.
y b, s k−1 −  s k−1 − s k−2 
s k  s k−1 −
y b, s k−1 − y b, s k−2
s 0  y ′ a ≈
Note that y b, s k−1 is the last element in the array y. Note also that we will need two initial choices
s 0 and s 1 to compute s 2 in order to continue the iterations.
2. Use Newton’s Method to approximate the solution of yb, s −   0.
y b, s k−1 − 
s k  s k−1 −
dy
b, s k−1
ds
Again, y b, s k−1 is the last element in the array y. Since we do not know yx explicitly, how can
dy
b, s k−1 ? Let yx, s be the solution of the initial value problem (**). Then from
we determine
ds
(**), we have
1
y ′′ x, s  fx, yx, s, y ′ x, s, a ≤ x ≤ b, ya, s  , y ′ a, s  s.
By differentiating both sides of the differential equation with respect to s, we have
∂fx, yx, s, y ′ x, s
∂y ′′ x, s

∂s
∂s
∂yx, s
∂y ′ x, s
 fx xs  fy
 f y′
.
∂s
∂s
Since x and s are independent, x s  0. Hence,
∂yx, s
∂y ′ x, s
∂y ′′ x, s
 fy
 f y′
(****)
∂s
∂s
∂s
for a ≤ x ≤ b. The initial conditions are:
∂ya, s
∂y ′ a, s
 d   0,
 d s  1.
ds
ds
∂s
∂s
∂yx, s
Define zx, s 
. Since
∂s
2
∂ 3 yx, s
∂ ∂ yx, s  ∂ y ′′ x, s,

∂s
∂s
∂x 2 ∂s
∂x 2
we denote
z ′′ x, s  ∂ y ′′ x, s.
∂s
Then the initial value problem (****) becomes the initial value problem
(*****) z ′′ x, s  f y zx, s  f y ′ z ′ x, s, a ≤ x ≤ b, za, s  0, z ′ a, s  1.
We can update s k using the information from zx, s as follows:
y b, s k−1 − 
s k  s k−1 −
z b, s k−1
Shooting Method for nonlinear boundary value problems:
y ′′  fx, y, y ′ , a ≤ x ≤ b, ya   and yb  .
−
. For k ≥ 1,
Compute s 0 
b−a
(i) Solve the system of two initial value problems:
y ′′  fx, y, y ′ , a ≤ x ≤ b, ya  , y ′ a  s k−1
z ′′  f y z  f y ′ z ′ , a ≤ x ≤ b, za, s k−1   0, z ′ a, s k−1   1
for yx and zx.
(ii) Update s k  s k−1 −
y b, s k−1 − 
.
z b, s k−1
For a given accuracy requirement , the algorithm is terminated if y b, s k−1 −   .
Example Solve the BVP:
y ′′  1 32  2x 3 − yy ′ , 1 ≤ x ≤ 3, y1  17, y3  43 .
3
8
fx, y, y ′   18 32  2x 3 − yy ′ .
f y  −y ′ , f y ′  −y
Solve a system of 2 second-order initial value problems:
2
y ′′ 
1
8
32  2x 3 − yy ′ , 1 ≤ x ≤ 3, y1  17, y ′ 1  s k
z ′′  f y z  f y ′ z ′  − 18 y ′ z  yz ′ , 1 ≤ x ≤ 3, z1  0, z ′ 1  1
Let u 1  y, u 2  y ′ , u 3  z, u 4  z ′ . Solve a system of 4 first-order initial value problems:
u ′1  u 2
u ′2

u ′4
1
8
u 1 1  17
32  2x − u 1 u 2 
3
u ′3  u 4
1
u 2 u 3 
8
−
u 2 1  s k
,
u 3 1  0
u 4 1  1
u1u4 
using MatLab function ode45.m.
y"=(32+2x
3
-yy)/8, [1,3], y(1)=17, y(3)=43/3 (Secant)
22
20
- solution y=x
2
+16/x
y(x,s
0
)
18
16
14
y(x,s
2
)
12
y(x,s
10
1
1.2
1.4
1.6
1.8
MatLab program: lect6_2_ex1.m
% Shooting Method for Nonlinear BVP
%
clear
clf
alpha17;
beta43/3;
a1;
b3;
%
% the first shoot:
%
s(1)(beta-alpha)/(b-a);
[X,Y]ode45(’funsys1’,[a b],[alpha;s(1);0;1]);
plot(X,Y(:,1),’-.’)
hold
text(2.6,19.8,’y(x,s_0)’)
%
% the second shoot:
3
2
2.2
2.4
2.6
1
)
2.8
3
%
nlength(Y(:,1));
s(2)s(1)(beta-Y(n,1))/Y(n,3);
clear X;
clear Y;
[X,Y]ode45(’funsys1’,[a,b],[alpha;s(2);0;1]);
plot(X,Y(:,1),’–’)
text(2.6,11.0,’y(x,s_1)’)
%
% the third shoot:
%
nlength(Y(:,1));
s(3)s(2)(beta-Y(n,1))/Y(n,3);
clear X;
clear Y;
[X,Y]ode45(’funsys1’,[a,b],[alpha;s(3);0;1]);
plot(X,Y(:,1),’:’)
text(2.6,12.5,’y(x,s_3)’)
%
% Comparisons
%
title(’y"(322x^3-yy)/8, [1,3], y(1)17, y(3)43/3 (Secant)’)
ysolX.^216./X;
plot(X,ysol)
text(1.2,20,’- solution yx^216/x’)
hold off
MatLab program: funsys1.m
function yvfunsys1(x,y);
yv(1,1)y(2,1);
yv(2,1)1/8*(322*x^3-y(1,1)*y(2,1));
yv(3,1)y(4,1);
yv(4,1)-y(2,1)/8*y(3,1)-y(1,1)/8*y(4,1);
MatLab program: lect6_2_ex2.m
%
% lect6_2_ex2
%
clear
clf
alpha17;
beta43/3;
a1;
b3;
epsiloninput(’epsilon ’);
%
% First shooting:
%
s(1)(beta-alpha)/(b-a);
4
[X,Y]ode45(’funsys1’,[a b],[alpha;s(1);0;1]);
plot(X,Y(:,1),’-.’)
hold
%
% iterations:
%
flag0;
nlength(Y(:,1));
diffabs(Y(n,1)-beta);
if diffepsilon
flag1;
end
k1;
while flag0,
s(k1)s(k)(beta-Y(n,1))/Y(n,3);
clear X;
clear Y;
[X,Y]ode45(’funsys1’,[a,b],[alpha;s(k1);0;1]);
plot(X,Y(:,1),’–’)
nlength(Y(:,1));
diffabs(Y(n,1)-beta);
if diffepsilon
flag1;
end
kk1;
end
title(’y"(322x^3-yy)/8, [1,3], y(1)17, y(3)43/3 (Secant)’)
ysolX.^216./X;
plot(X,ysol)
text(1.2,20,’- solution yx^216/x’)
hold off
Exercises:
1. Use the Shooting Method to approximate the solution to the boundary value problem
y ′′  −y ′  2 − y  ln x, 1 ≤ x ≤ 2, y1  0, y2  ln 2
to within 10 −5 . Compare your results to the actual solution y  lnx by plotting the absolute values of
the differences.
2. Use the Shooting Method to approximate the solution to each of the following boundary value
problems to within 10 −4 . Compare your results with given true solution by plotting the absolute values
of the differences.
a. y ′′  y 3 − yy ′ , 1 ≤ x ≤ 2, y1  12 , y2  13
The true solution: yx  x  1 −1 .
b. y ′′  y ′  2y − ln x 3 − 1x , 2 ≤ x ≤ 3, y2  12  ln2, f3  13  ln 3
The true solution: yx  x −1  lnx.
c. y ′′  2y 3 − 6y − 2x 3 , 1 ≤ x ≤ 2, y1  2. y2  52
The true solution: yx  x −1  x.
5
3. Write an MatLab program to implement the Shooting Method for nonlinear boundary value problems
using the Newton Method to compute s 1 and then use the Secant Method to update s k for k  2, 3, . . . .
4. The Van der Pol equation
y ′′ − y 2 − 1y ′  y  0,   0,
governs the flow of current in a vacuum tube with three internal elements. Let  
y2  1. Approximate yx for 0 ≤ x ≤ 2 to within 10 −4 .
6
1
2
, y0  0, and
Download