The Shooting Method for Nonlinear Problems, Assignments of Mathematics

This is solution to one of problems in Numerical Analysis. This is matlab code. Its helpful to students of Computer Science, Electrical and Mechanical Engineering. This code also help to understand algorithm and logic behind the problem. This code includes: Linear, Shooting, Algorithm, Function, Approximate, Solution, Boundary, Value, Problem, Subintervals, Endpoints Show more

Typology: Assignments

2019/2020

Uploaded on 04/07/2020

vvvdfvsfdb
vvvdfvsfdb 🇪🇬

5

(2)

1 document

1 / 6

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
(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,axb,yaand yb.
When fx,y,yis linear in yand y, the Shooting Method introduced in Section 6.1 solves a system of two
initial value problems and the solution yxof the boundary value problem (*) is of the form
yxy1xy1b
y2by2x
where y1xand y2xare solutions of two initial value problems, respectively. Now we consider the cases
where fx,y,yis not linear in yand y. Assume a given boundary value problem has a unique solution
yx. We will approximate the solution yxby solving a sequence of initial value problems
(**) y′′ fx,y,y,axb,ya,yask
where skare real numbers. Let yx,skbe solution of the initial value problem (**). We want to have a
sequence skso that
lim
kyx,skyx.
One of choices for s0is
s0yaybya
ba
ba.
How to choose skfor k1? Consider choose ssuch that
(***) yb,s0,
that is sis a solution of the equation. Observe that the equation yb,s0 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 gs0. For given s0and
s1, the Secant Method computes skfor k2 as follows
sksk1gsk1sk1sk
gsk1gsk2.
For given s0, the Newton Method computes skfor k1 as follows
sksk1gsk1
gsk1.
These methods can be used here to solve the nonlinear equation (***).
1. Use the Secant Method to approximate the solution of yb,s0.
sksk1y b,sk1sk1sk2
yb,sk1y b,sk2
Note that y b,sk1is the last element in the array y. Note also that we will need two initial choices
s0and s1to compute s2in order to continue the iterations.
2. Use Newton’s Method to approximate the solution of yb,s0.
sksk1yb,sk1
dy
ds b,sk1
Again, y b,sk1is the last element in the array y. Since we do not know yxexplicitly, how can
we determine dy
ds b,sk1?Letyx,sbe the solution of the initial value problem (**). Then from
(**), we have
1
pf3
pf4
pf5

Partial preview of the text

Download The Shooting Method for Nonlinear Problems and more Assignments Mathematics in PDF only on Docsity!

( 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 ′^ , axb , 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

yx   y 1  x   y 1  by 2  b

y 2  x

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 ′^ , axb , 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 k → yx , s (^) k   yx .

One of choices for s 0 is

s 0  y ′ a  ≈

yb  − yaba

ba

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

s (^) ks (^) k − 1 − gs (^) k − 1  s (^) k − 1 − s (^) kgs (^) k − 1  − gs (^) k − 2 

For given s 0 , the Newton Method computes s (^) k for k ≥ 1 as follows

s (^) ks (^) k − 1 −

gs (^) 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.

s (^) ks (^) k − 1 −

y b , s (^) k − 1 − (^)  s (^) k − 1 − s (^) k − 2  y b , s (^) k − 1 − y b , s (^) k − 2 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.

s (^) ks (^) k − 1 −

y b , s (^) k − 1 −  dy ds b , s (^) k − 1

Again, y b , s (^) k − 1 is the last element in the array y. Since we do not know yx  explicitly, how can we determine dy ds

b , s (^) k − 1? Let yx , s  be the solution of the initial value problem (). Then from (), we have

y ′′ x , s   fx , yx , s , y ′ x , s , axb , ya , s   , y ′ a , s   s. By differentiating both sides of the differential equation with respect to s , we have ∂ y ′′ x , s  ∂ s

fx , yx , s , y ′ x , s  ∂ s

f (^) x x (^) sf (^) y

yx , s  ∂ sf (^) y

y ′ x , s  ∂ s

Since x and s are independent, x (^) s  0. Hence,

(****) ∂ y ′′ x , s  ∂ s

f (^) yyx , s  ∂ s

f (^) y ′ ∂ y ′ x , s  ∂ s for axb. The initial conditions are: ∂ ya , s  ∂ sd ds

y ′ a , s  ∂ sd dss   1.

Define zx , s   ∂ yx , s  ∂ s

. Since ∂^3 yx , s  ∂ x^2 ∂ s

s

∂^2 yx , s  ∂ x^2

sy ′′ x , s ,

we denote z ′′ x , s   ∂ ∂ sy ′′ x ,^ s .

Then the initial value problem (****) becomes the initial value problem (*****) z ′′ x , s   f (^) y zx , s   f (^) yz ′ x , s , axb , za , s   0, z ′ a , s   1. We can update s (^) k using the information from zx , s  as follows:

s (^) ks (^) k − 1 −

y b , s (^) k − 1 −  z b , s (^) k − 1 Shooting Method for nonlinear boundary value problems : y ′′^  fx , y , y ′^ , axb , ya   and yb   .

Compute s 0 

ba

. For k ≥ 1, (i) Solve the system of two initial value problems:

y ′′^  fx , y , y ′^ , axb , ya   , y ′ a   s (^) k − 1 z ′′^  f (^) y zf (^) yz ′, axb , za , s (^) k − 1   0, z ′ a , s (^) k − 1   1

for yx  and zx .

(ii) Update s (^) ks (^) 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 8

 32  2 x^3 − yy ′^ , 1 ≤ x ≤ 3, y  1   17, y  3   43 3

fx , y , y ′^   18  32  2 x^3 − yy ′^ . f (^) y  − y ′, f (^) y ′  − y Solve a system of 2 second-order initial value problems:

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2x^3-y(1,1)y(2,1)); yv(3,1)y(4,1); yv(4,1)-y(2,1)/8y(3,1)-y(1,1)/8*y(4,1);

MatLab program: lect6_2_ex2.m % % lect6_2_ex % clear clf alpha17; beta43/3; a1; b3; epsiloninput(’epsilon ’); % % First shooting: % s(1)(beta-alpha)/(b-a);

[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: yx   (^)  x  (^1) −^1. b. y ′′^  y ′^  2  y − ln x ^3 − (^1) x , 2 ≤ x ≤ 3, y  2   12  ln 2 , f  3   13  ln 3 The true solution: yx   x −^1  ln x . c. y ′′^  2 y^3 − 6 y − 2 x^3 , 1 ≤ x ≤ 2, y  1   2. y  2   (^52) The true solution: yx   x −^1  x.