Chapter. Ordnar Dfferental Equaton Boundar Value (BV) Problems In ths chapter we wll learn how to solve ODE boundar value problem. BV ODE s usuall gven wth x beng the ndependent space varable. p( x) q( x) f ( x) a x b (a) and the boundar condtons (BC) are gven at both end of the doman e.g. (a) = and (b) =. The are generall fxed boundar condtons or Drchlet Boundar Condton but can also be subject to other tpes of BC e.g. Neumann BC or Robn BC. 4. LINEAR FINITE DIFFERENCE (FD) METHOD Fnte dfference method converts an ODE problem from calculus problem nto algebrac problem. In FD, and are expressed as the dfference between adjacent values, for example, (x h) (x h) (x) h () whch are derved from the Talor seres expanson, (x+h) = (x) + h (x) + (h /) (x) + () (x h) = (x) h (x) + (h /) (x) + (3) Kosash Chapter ODE Boundar Value Problems
If () s added to (3) and neglectng the hgher order term (O (h 3 )), we wll get (x h) (x) (x h) (x) (4) h The dfference Eqs. () and (4) can be mplemented n [x = a, x n = b] (see Fgure) f few fnte ponts n are defned and dvdng doman [a,b] nto n ntervals of h whch s defned xn x h x x (5) n - [x,x n ] doman dvded nto n ntervals. FD method gves dervatve of values at pont, as follow (x ) (x) (x-) h (6) (x ) (x ) (x ) (x ) h (7) Substtutng (6) & (7) nto (a), we get - h q(x ) (x ) h p(x ) (x ) h f(x ) h p(x ) (x ) (8) or can be smplfed to, - h q(x ) h p(x ) h f(x ) h p(x ) (9) Eq. (9) s then appled to each of the nternal nodes, =,,n. Ths wll produce a sstem of lnear equatons of tr dagonal form. The sstem of lnear equatons can then be solved usng the Thomas algorthm (but we wll solve usng sparse matrx technque). Kosash Chapter ODE Boundar Value Problems
Example Solve the followng nd order ODE, 7 3 for [,] wth Drchlet boundar condton, () = and () =, usng FD wth h =. (Note n ths example p(x) = 7, q(x) = 3 and f(x) = ). The dfference equaton (9) for ths problem s, ( 3.5h) ( - 3h ) ( 3.5h) h for h =.,.65.97 +.35 + =. (C ) The dfference equaton s appled to the nternal nodes ( = ), Applng (C ) at =, we obtan the followng sstem of lnear equatons Note that nodes = & are end nodes, whch have specfed values and the do not appear n the sstem. The above sstem of lnear equatons can be wrtten n tr Kosash Chapter ODE Boundar Value Problems 3
dagonal matrx form, whch can be solved usng Thomas algorthm but we wll solve usng sparse technque..97.65.35.97.65.35.97.65.35.97.65.35.97.65.35.97.65.35.97.65.35.97.65.35.97 3 4 5 6 7 8 9......... 34 The soluton of the above sstem s T = [, 3, 4, 5, 6, 7, 8, 9, ] = [.64,.9443,.76,.33,.84,.3,.885,.598,.99] Note that the dfference equatons at nodes = and = n = are slghtl modfed b the end nodes, () = - h q(x ) h p(x ) 3 h f(x ) - h p(x ) = h p(x ) 9 - h q(x ) h f(x ) - h p(x ) 9 () The sample MATLAB code (Example.m) I developed to solve ths problem s shown below. %*************************************************************************** % Program to solve lnear ODE boundar value problems wth FD % Both ends are subjected to Drchlet boundar condtons % nputs : % a,b are startng and endng ponts % alfa,beta are the values at the startng and endng ponts % n s the number of nterval Kosash Chapter ODE Boundar Value Problems 4
% outputs : % are the values of at node ponts %*************************************************************************** clear;clf; %********** INPUT ******************************************************* a = nput(ʹenter the startng x >ʹ); b = nput(ʹenter the endng x >ʹ); alfa = nput(ʹenter the value at startng x >ʹ); beta = nput(ʹenter the value at endng x >ʹ); n = nput(ʹenter the number of dvsons >ʹ); pfunc = nput(ʹenter the functon p(x) please: ʹ,ʹsʹ); qfunc = nput(ʹenter the functon q(x) please: ʹ,ʹsʹ); ffunc = nput(ʹenter the functon f(x) please: ʹ,ʹsʹ); p = nlne(pfunc); q = nlne(qfunc); f = nlne(ffunc); %*********** Constants ************ h = (b a)/n; % the nterval sze x = lnspace(a,b,n+); %************ Elements of the matrx A A(:n,:n ) =.; % ntalze matrx A for = :n % ths loop calculate element for nodes to n % n the dagram but n the % matrx t s from = to n f == A(,)= (. q(x(+)) * h*h); A(,+) = +.5 * p(x(+)) * h; ff() = f(x(+)) * h*h (. p(x(+)) *.5 * h) * alfa; elsef == n A(, ) =. p(x(+)) *.5 * h; A(,) = (. q(x(+)) * h*h); ff() = f(x(+)) * h*h ( +.5 * p(x(+)) * h) * beta; else A(, ) =. p(x(+)) *.5 * h; A(,) = (. q(x(+)) * h*h); A(,+) = +.5 * p(x(+)) * h; Kosash Chapter ODE Boundar Value Problems 5
ff() = f(x(+)) * h*h; end end %************ Solve the sstem of lnear equatons usng sparse matrx ASparse = sparse(a); = ASparse\ffʹ; %*********** PLOT OF RESULT ******** plot(x,[alfa;;beta],ʹb ʹ) xlabel(ʹxʹ),label(ʹʹ); legend(ʹnumercal resultsʹ) Enter the startng x > Enter the endng x > Enter the value at startng x > Enter the value at endng x > Enter the number of dvsons > Enter the functon fle of p(x) please: 7. Enter the functon fle of q(x) please: 3. Enter the functon fle of f(x) please:..4. numercal results.8.6.4....3.4.5.6.7.8.9 x Now suppose the ODE Eq. () Kosash Chapter ODE Boundar Value Problems 6
p( x) q( x) f ( x) a x b () s now subject to boundar condtons (a) = and (b) =. The boundar at b s a dervatve boundar condton or Neumann Boundar Condton. For the problem the value of (b) must be calculated (part of the soluton) so dfference equatons must be wrtten for =,,,n. For =,,,,,n accordng to the FD equaton (9) s but for = n t s dfferent as (b) needs (x n +h) as shown below. (xn h) (xn ) (xn h) n n n- (xn ) h h () It s clear from () that (b+h) s needed, and ths s outsde the doman as shown n the fgure below. To calculate n+, we wll make use of the gven (xn ) and followng (6), n n n (3) h So, n n h n (4) If (4) s substtuted nto () hn - n n n (5) h and substtutng (5) and n- h q(x ) h f(xn ) n n n nto (), we get h h p(x n ) (6) Kosash Chapter ODE Boundar Value Problems 7
Eq. (6) s the FD equaton appled at node = n. Example Solve the followng nd order ODE, 5 4 For [,] and boundar condtons () = and (). Use h =., n ths problem p(x) = 5, q(x) = 4 and f(x) =.. The FD equatons are gven b (9), (.5h) ( - 4h ) (.5h) h For h =.,.75.96 +.5 + =. (C ) (C ) s applcable for =, but for =, (6) s used 9.96. (C ) The sstem of lnear equatons to be solved s.96 3.75 4 5 6 7 8 9.5 3.96 3.75 3.5 4.96 4.75 4.5 5.96 5.75 5.5 6.96 6.75 6.5 7.96 7.75 7.5 8.96 8.75 8.5 9.96 9.75 9.5.96..75.........5..96 In matrx form, Kosash Chapter ODE Boundar Value Problems 8
.96.75.5.96.75.5.96.75.5.96.75.5.96.75.5.96.75.5.96.75.5.96.75.5.96.5.96 3 4 5 6 7 8 9.74......... The soluton vector s T = [.75,.536,.393,.38,.68,.39,.55,.6,.,.] As a practce, modf the code used n Example to solve ths one. Another possble boundar condton s Robn Boundar Condton. In ths case the BC s expressed as an expresson, A n + B n = (7) Usng backward dfference to express n, A n + B n n = (8) h Or, n βh Bn (A h B ) (9) Example 3 Solve the followng nd order ODE, 5 4 Kosash Chapter ODE Boundar Value Problems 9
For [,] and boundar condtons: ()= and ().5ʹ()=.5. Use FD method wth h =.. For = the FD equatons are the same as prevous example, but for = the FD equaton s calculated (9) wth A =, B =.5 dan =.5. =.5 + =.5 The formed sstem of lnear equatons s.96.75.5.96.75.5.96.75.5.96.75.5.96.75.5.96.75.5.96.75.5.96.75.5.96.5.5 3 4 5 6 7 8 9..........5 The soluton s T = [.98,.3446,.465,.4543,.474,.473,.4675,.457,.4444,.435] As a practce, modf the code used n Example to solve ths one. 4. NON LINEAR FINITE DIFFERENCE (FD) METHOD The soluton of non lnear ODE usng FD method s smlar to the lnear FD except for non lnear ODE the solutons s obtaned teratvel. In non lnear problem p(x,) and q(x,) are functon of x and or dervatves of, so at each teraton k th, p(x,) and q(x,) are calculated usng the values at (k ) th teraton. In other words we lnearze the ODE nto, ( k ) (k ) p(x, ) q(x, ) f(x) () As n an teratve technques, we must start from an ntal estmate (). The values of the ntal estmate can affect the rate of convergence, so we must prudentl guess (). The smplest technque s to assume lnear (x) as shown n the followng fgure. Kosash Chapter ODE Boundar Value Problems
Then teratons are done untl the left sde dffer wthn a certan tolerance from the rght sde. The above method nvolves solvng lnear FD equatons agan and agan. A more explct technque can also be obtaned, we start b wrtng the ODE agan, f(x) - p(x, ) q(x, ) () After expressng and usng (6) and (7) and substtutng them nto (), h h f(x ) p(x, ) q(x, ) () Rearrangng (), can be explctl expressed as h f(x ) h p(x, ) h q(x, ) (3) Note that can be calculated teratvel f all s on the rght hand sde are the known from the prevous calculaton or ntall assumed at the begnnng of the teraton. Kosash Chapter ODE Boundar Value Problems
4 (k ) - h f(x ) h p(x, )( - ) h q(x, ) (4) Fausett suggested that convergence can be accelerated f we add to both sde of (3), 4( ω) 4ω h f(x ) h p(x, )( ) h q(x, ) (5) And s calculated teratvel, 4( ω) 4ω - h f(x ) hp(x, )( - ) h q(x, The teraton process s stopped when a specfed convergence crtera has been reached. An acceptable convergence crtera s (6) ) k k (7) Example 4 Solve the followng non lnear ODE, ( ) ( ) For [,] and boundar condtons () = and () =. p(x,) = q(x,) = + and f(x) =. Use the explct method wth h =. and ntal estmate for = whch assumed lnear () = [.,.,.3,.4,.5,.6,.7,.8,.9]. The explct form of (Eq. 6) for ths example s, 4( ω) 4ω - h h( )( - ) h ( ) 4( ω) 4ω -..( )( - ).( ) The result s shown n Fgure below. () Kosash Chapter ODE Boundar Value Problems
4. 3 Tutoral Questons. Fnd the temperature profle nsde the tube wall. Hot flud flows nsde the tube such that the nsde temperature s C. The dfferental equaton for the temperature dstrbuton s gven b d T dt dr r dr The boundar condtons are T() = C and T(5) = C. Ths s a lnear nd order lnear ODE wth Drchlet boundar condtons, so use lnear FD technque wth h =. Hot flud flowng nsde a tube.. Deflecton of prsmatc smpl supported beam shown below Kosash Chapter ODE Boundar Value Problems 3
s gven b the followng equaton. d qlx qx EI dx Where V s unforml dstrbuted load, L s the length of the beam, I s the moment of nerta of the beam cross secton (I = wh 3 /, w s wdth and h s heght of the beam) and E s the modulus of elastct of the beam. For the case n hand E = GPa, L =.m, w = 5.cm, h =.cm, V = 5N/m and I = 4.66x 6 m 4, Fnd (x). It s clear from the problem that the boundar condtons are Drchlet.e., () = () =., Rewrte the governng equaton Vx EI x - L.8x(x ) From the above, p(x) =, q(x) = and f(x) =.8 x (x.). Dvde the beam nto nterval gvng h =. and generate plot of the beam deflecton. 3. Use lnear shootng method and lnear Fnte Dfference Method to fnd the soluton of Kosash Chapter ODE Boundar Value Problems 4
ODE Range Boundar condtons Analtcal soluton h = 4 ( x) [,] () = () = (x) = e x x.5 ( e e ) x 4 e 4. Use FD method (Neumann Boundar condtons) to fnd the soluton of ODE Range Boundar condtons h = -5 4 + [,] () =.5 () = 5. Use FD method (Robn Boundar condtons) to fnd the soluton of ODE Range Boundar condtons h = -4 6.5 + e x [,] () =.5 ().5 () =.5 6. Use non lnear FD method to fnd the soluton of ODE Range Boundar condtons Analtcal soluton h = 3 [,] () = () = 3 (x) = x.5 Comment on the use of dfferent sa from.5.5. Adopt the followng convergence crtera k k Kosash Chapter ODE Boundar Value Problems 5