(6.2) - The Shooting Method for Nonlinear Problems Consider the boundary value problems (BVPs) for the second order differential equation of the form (*) y ′′ fx, y, y ′ , a ≤ x ≤ b, ya and yb . When fx, 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 yx of the boundary value problem (*) is of the form − y 1 b y 2 x yx 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 fx, y, y ′ is not linear in y and y ′ . Assume a given boundary value problem has a unique solution yx. We will approximate the solution yx by solving a sequence of initial value problems (**) y ′′ fx, y, y ′ , a ≤ x ≤ b, ya , y ′ a s k where s k are real numbers. Let yx, s k be solution of the initial value problem (**). We want to have a sequence s k so that lim yx, s k yx. k→ One of choices for s 0 is − yb − ya . b−a b−a How to choose s k for k ≥ 1? Consider choose s such that (***) yb, s − 0, that is s is a solution of the equation. Observe that the equation yb, 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 gs 0. For given s 0 and s 1 , the Secant Method computes s k for k ≥ 2 as follows gs k−1 s k−1 − s k . s k s k−1 − gs k−1 − gs k−2 For given s 0 , the Newton Method computes s k for k ≥ 1 as follows gs 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 yb, 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 yb, 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 yx explicitly, how can dy b, s k−1 ? Let yx, s be the solution of the initial value problem (**). Then from we determine ds (**), we have 1 y ′′ x, s fx, yx, s, y ′ x, s, a ≤ x ≤ b, ya, s , y ′ a, s s. By differentiating both sides of the differential equation with respect to s, we have ∂fx, yx, s, y ′ x, s ∂y ′′ x, s ∂s ∂s ∂yx, s ∂y ′ x, s fx xs fy f y′ . ∂s ∂s Since x and s are independent, x s 0. Hence, ∂yx, s ∂y ′ x, s ∂y ′′ x, s fy f y′ (****) ∂s ∂s ∂s for a ≤ x ≤ b. The initial conditions are: ∂ya, s ∂y ′ a, s d 0, d s 1. ds ds ∂s ∂s ∂yx, s Define zx, s . Since ∂s 2 ∂ 3 yx, s ∂ ∂ yx, 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 zx, s f y ′ z ′ x, s, a ≤ x ≤ b, za, s 0, z ′ a, s 1. We can update s k using the information from zx, 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 ′′ fx, y, y ′ , a ≤ x ≤ b, ya and yb . − . For k ≥ 1, Compute s 0 b−a (i) Solve the system of two initial value problems: y ′′ fx, y, y ′ , a ≤ x ≤ b, ya , y ′ a s k−1 z ′′ f y z f y ′ z ′ , a ≤ x ≤ b, za, s k−1 0, z ′ a, s k−1 1 for yx and zx. (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, y1 17, y3 43 . 3 8 fx, 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, y1 17, y ′ 1 s k z ′′ f y z f y ′ z ′ − 18 y ′ z yz ′ , 1 ≤ x ≤ 3, z1 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 alpha17; beta43/3; a1; b3; % % 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 % nlength(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: % nlength(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"(322x^3-yy)/8, [1,3], y(1)17, y(3)43/3 (Secant)’) ysolX.^216./X; plot(X,ysol) text(1.2,20,’- solution yx^216/x’) hold off MatLab program: funsys1.m function yvfunsys1(x,y); yv(1,1)y(2,1); yv(2,1)1/8*(322*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 alpha17; beta43/3; a1; b3; epsiloninput(’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: % flag0; nlength(Y(:,1)); diffabs(Y(n,1)-beta); if diffepsilon flag1; end k1; while flag0, s(k1)s(k)(beta-Y(n,1))/Y(n,3); clear X; clear Y; [X,Y]ode45(’funsys1’,[a,b],[alpha;s(k1);0;1]); plot(X,Y(:,1),’–’) nlength(Y(:,1)); diffabs(Y(n,1)-beta); if diffepsilon flag1; end kk1; end title(’y"(322x^3-yy)/8, [1,3], y(1)17, y(3)43/3 (Secant)’) ysolX.^216./X; plot(X,ysol) text(1.2,20,’- solution yx^216/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, y1 0, y2 ln 2 to within 10 −5 . Compare your results to the actual solution y lnx 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, y1 12 , y2 13 The true solution: yx x 1 −1 . b. y ′′ y ′ 2y − ln x 3 − 1x , 2 ≤ x ≤ 3, y2 12 ln2, f3 13 ln 3 The true solution: yx x −1 lnx. c. y ′′ 2y 3 − 6y − 2x 3 , 1 ≤ x ≤ 2, y1 2. y2 52 The true solution: yx 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 − 1y ′ y 0, 0, governs the flow of current in a vacuum tube with three internal elements. Let y2 1. Approximate yx for 0 ≤ x ≤ 2 to within 10 −4 . 6 1 2 , y0 0, and