Survey
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
Ordinary Differential Equations Boundary Value Problems Copyleft 2005 by Media Lab 1 14.1 Shooting Method for Solving Linear BVPs • We investigate the second-order, two-point boundary-value problem of the form y f ( x, y, y) ,a x b with Dirichlet boundary conditions y (b) y (a) , Or Neuman boundary conditions y(a ) , y(b) Or mixed boundary condition y(a) c1 y (a) , Copyleft 2005 by Media Lab y(b) c 2 y (b) 2 14.1 Shooting Method for Solving Linear BVPs • Simple Boundary Conditions y p( x) y q( x) y r ( x), a x b, y (a) ya, y (b) yb The approach is to solve the two IVPs u p ( x)u q( x)u r ( x), v p( x)v q ( x)u, u ( a ) ya , v ( a ) 0, u (a ) 0, v( a ) 1. If v (b) 0, the solution of the original two-point BVP is given by y(x) = u(x) + Av(x) is found from the requirement that y(b) = u(b) + Av(b) = yb A yb u (b) v(b) Copyleft 2005 by Media Lab y ( x) u ( x) yb u (b) v( x). v(b) 3 14.3 Shooting Method for Solving Linear BVPs • EX14.1 y 2 y, y (1) 10, x y (2) 0, • convert to the pair of initial-value problems 2 u , x 2 v v x u w1 w2, wx y ( x) w1x Copyleft 2005 by Media Lab u (1) 10, u (1) 0, v (1) 0, v(1) 0, 2 w 2, x w3 w4, w4 2 w 4, x 0 w1(b) w3( x). w3(b) 4 14.1 Shooting Method for Solving Linear BVPs • General Boundary Condition at x = b y p( x) y q( x) y r ( x) The condition at x=b involves a linear combination of y(b) and y’(b) y (a) ya, y(b) cy (b) yb The approach is to solve the two IVPs u p ( x)u q( x)u r ( x), v p( x)v q ( x)u, u ( a ) ya , v ( a ) 0, u (a ) 0, v( a ) 1. If v(b) cv (b) 0 there is a unique solution, given by yb u(b) cu (b) y ( x) u ( x) v( x). v(b) cv(b) Copyleft 2005 by Media Lab 5 14.3 Shooting Method for Solving Linear BVPs • General Boundary Condition at Both Ends of the Interval y p( x) y q( x) y r ( x) y(a) c1 y (a) ya, y(b) c 2 y (b) yb. the approach is to solve two IVPs u p ( x)u q( x)u r ( x), v p( x)v q ( x)u, u (a ) 0, v( a ) 1, u ( a ) ya, v( a ) c1. If v(b) c 2v(b) 0 , there is a unique solution, given by yb u(b) c 2u (b) y ( x) u ( x) v( x). v(b) c 2v(b) Copyleft 2005 by Media Lab 6 14.3 Shooting Method for Solving Linear BVPs • Ex 14.4 2x 2 2 y y x 1, x2 1 x2 1 y y (0) 1, y(1) y (1) 0. y ( x 4 3x 2 x 6) / 6 • Ex 14.5 y 2x 2 2 y y x 1, 2 2 x 1 x 1 y(0) y (0) 0, y(1) y (1) 3. y x 4 / 6 3x 2 / 2 x 1 Copyleft 2005 by Media Lab 7 14.2 Shooting Method for Solving NonLinear BVPs • Nonlinear Shooting Based on the Secant Method use an iterative process based on the secant method presented in Chapter 2 y f ( x, y, y), y(a) ya , h( y (b), y(b)) 0, the initial slope ‘t’, begin with u’(a) = t(1) = 0, error is m(1) Unless the absolute value of m(1) is less than the tolerance, we continue by solving eq. t (i) t (i 1) Copyleft 2005 by Media Lab t (i 1) t (i 2) m(i 1). m(i 1) m(i 2) 8 14.2 Shooting Method for Solving NonLinear BVPs • EX 14.6 y 2 yy, y (0) 1, y (1) y(1) 0.25 0. y = 1/(x+1) Copyleft 2005 by Media Lab 9 14.2 Shooting Method for Solving NonLinear BVPs • Nonlinear Shooting Using Newton’s Method y f ( x, y, y), y(a) ya , y (b) yb . begin by solving the initial-value problem u f ( x, u, u ), v' ' vfu ( x, u, u ) vf u ( x, u, u), u (a ) ya , v(a) 0, u (a) tk , v(a) 1. Check for convergence: m u (b, tk ) yb ; if |m| < tol, stop; Otherwise, update t: Copyleft 2005 by Media Lab tk 1 tk m / v(b, tk ); 10 14.2 Shooting Method for Solving NonLinear BVPs • EX 14.8 [ y]2 y , y u [u]2 u 1 , y (1) 2, y (0) 1, u (0) 1, u(0) tk . f u ( x, u, u) [u]2 (1)u 2 , f u ( x, u, u) 2[u]u1. v v[u]2 u 2 v2[u]u1 , Copyleft 2005 by Media Lab v (0) 0, v(0) 1. 11 14.3 Finite Difference Method for Solving Linear BVPs • Replace the derivatives in the differential equation by finite-difference approximations (discussed in Chapter 11). • We now consider the general linear two-point boundary-value problem y p( x) y q( x) y r ( x), a x b, • with boundary conditions y (a) , y (b) , • To solve this problem using finite-differences, we divide the interval [a, b] into n subintervals, so that h=(b-a)/n. To approximate the function y(x) at the points x1 a h, xn1 a (n 1)h, we use the central difference formulas from Chapter 11: y( xi ) Copyleft 2005 by Media Lab yi 1 2 yi yi 1 yi 1 yi 1 , y ( x ) i h2 2h 12 Finite Difference Method for Solving Linear BVPs • Substituting these expressions into the BVP and writing p( xi ) as pi , q( xi ) as qi , and r ( xi ) as ri gives ____ yi 1 2 yi yi 1 yi 1 yi 1 pi qi yi ri 2 h 2h • Further algebraic simplification leads to a tridiagonal system for the unknowns y1 ,, yn1 , viz. h h 2 2 1 p y ( 2 h q ) y 1 p y h ri , i 1, , n 1, i i 1 i i i i 1 2 2 • where y0 y(a) and yn y(b) . Copyleft 2005 by Media Lab 13 Finite Difference Method for Solving Linear BVPs • Expanding this expression into the full system gives h (2 h 2 q1 ) y1 1 p1 y2 2 h 2 1 p1 y1 (2 h q2 ) y2 1 p2 2 h h 2 r1 1 p1 , 2 h y3 2 h h 2 1 pi yi 1 (2 h qi ) yi 1 pi yi 1 2 2 h 2 r2 , h 2 ri , h h 2 2 1 p1n 2 yn 3 (2 h qn 2 ) yn 2 1 pn 2 yn 1 h rn 2 , 2 2 h h 2 2 1 pn 1 yn 2 (2 h qn 1 ) yn 1 h rn 1 1 pn 1 , 2 2 Copyleft 2005 by Media Lab 14 Example 14.9 A Finite-Difference Problem • Use the finite-difference method to solve the problem y y x( x 4), 0 x 4, • with y(0)=y(4)=0 and n=4 subintervals. • Using the central difference formula for the second derivative, we find that the differential equation becomes the system. y( xi ) yi 1 2 yi yi 1 yi xi ( xi 4), 2 h i 1,2,3. • For this example, h = 1 ,i =1, y = 0, and i = 3, y = 0. Substituting this values, we obtain y2 2 y1 0 y1 1(1 4), y3 2 y2 y1 y2 2(2 4), 0 2 y3 y2 y3 3(3 4). Copyleft 2005 by Media Lab 15 Example 14.9 A Finite-Difference Problem • Combining like terms and simplifying gives 3 y1 y2 3, y1 3 y2 y3 4, y2 3 y3 3, • Solving, we find that y_1=13/7, y_2 = 18/7, and y_3 = 13/7. • We note for comparison that the exact solution of this problem is 2(1 e 4 ) x 2(1 e 4 ) x y 4 4 e 4 4 e x 2 4 x 2. e e e e Copyleft 2005 by Media Lab 16 Example 14.9 A Finite-Difference Problem Copyleft 2005 by Media Lab 17 Example 14.10 A Matlab Script for a Linear FDP. • The Matlab script that follows solves the BVP. y 2 y 2 y, y(0) 0.1, y(3) 0.1e3cos(3). function S_linear_FD aa = 0; bb = 3; n = 300; p = 2*ones(1, n-1); q = -2*ones(1, n-1); r = zeros(1, n-1); ya = 0.1; yb = 0.1*exp(3)*cos(3); h = (bb-aa)/n; h2 = h/2; hh= h*h; x = linspace(aa+h, bb, n); a = zeros(1, n-1); b = a; a(1:n-2) = 1 - p(1, 1:n-2)*h2; d = -(2 + hh*q); b(2:n-1) = 1 + p(1, 2:n-1)*h2; c(1) = hh*r(1) - (1+p(1)*h2)*ya; c(2:n-2) = hh*r(2:n-2); c(n-1) = hh*r(n-1) - (1 - p(n-1)*h2)*yb; y = Thomas(a, d, b, c) xx = [aa x]; yy = [ya y yb]; out = [xx' yy']; disp(out) plot(xx, yy), grid on, hold on plot(xx, 0.1*exp(xx).*cos(xx)) hold off Copyleft 2005 by Media Lab 18 Example 14.10 A Matlab Script for a Linear FDP. Copyleft 2005 by Media Lab 19 14.4 FDM for Solving Nonlinear BVPs • We consider the nonlinear ODE-BVP of the form y 2 y 2 y, y(0) 0.1, y(3) 0.1e3cos(3). • Assume that there are constants Q* , Q* and P * such that 0 Q* f y ( x, y, y) Q* and | f y ( x, y, y) | P* • Use a finite-difference grid with spacing h 2 / P* ,and let f i denote the result of evaluating f at xi using ( yi 1 yi 1 ) /( 2h) for yi . • The ODE then becomes the system yi 1 2 yi yi 1 f i 0. 2 h • An explicit iteration scheme, analogous to the SOR method 1 yi yi 1 2yi yi 1 h 2 f i , 2(1 ) • where y0 and yn . The process will converge for w h 2Q* / 2. Copyleft 2005 by Media Lab 20 Example 14.12 Solving a Nonlinear BVP by Using FDM • Consider again the nonlinear BVP 2 y y , y(0) 1, y (1) 2. y • We illustrate the use of the iterative procedure just outlined by taking a grid with h = ¼. The general form of the difference equation is yi 1 yi 1 2yi yi 1 h 2 f i , 2(1 ) • where fi 2 ( yi 1 yi 1 ) /( 2h) Copyleft 2005 by Media Lab yi yi21 2 yi 1 yi 1 yi21 . 2 4h yi (1 ) 21 Example 14.12 Solving a Nonlinear BVP by Using FDM • Substituting the rightmost expression for f_i into the equation for y_i, we obtain yi21 2 yi 1 yi 1 yi21 1 yi yi 1 2yi yi 1 . 2(1 ) 4 yi • The computed solution after 10 iterations agrees very closely with the exact solution. function S_nonlinear_FD ya = 1; yb = 2; a = 0; b = 1; max_it = 10; n = 4; w = 0.1; ww = 1/(2*(1+w)); h = (b-a)/n y(1:n-1) = 1 for k = 1:max_it y(1) = ww*(ya+2*w*y(1)+y(2)+(ya^2-2*ya*y(2)+y(2)^2)/(4*y(1))); y(2) = ww*(y(1)+2*w*y(2)+y(3)+(y(1)^2-2*y(1)*y(3)+y(3)^2)/(4*y(2))); y(3) = ww*(y(2)+2*w*y(3)+yb+(y(2)^2-2*y(2)*yb+yb^2)/(4*y(3))); end x = [ a a+h a+2*h a+3*h b ]; z = [ ya y yb ]; plot(x, z), hold on, zz = sqrt(3*x+1); plot(x, zz), hold off Copyleft 2005 by Media Lab 22 Example 14.12 Solving a Nonlinear BVP by Using FDM Copyleft 2005 by Media Lab 23