umercal Solutons of oundary-value Problems n Os ovember 7, 7 umercal Solutons of oundary- Value Problems n Os Larry aretto Mechancal ngneerng 5 Semnar n ngneerng nalyss ovember 7, 7 Outlne Revew stff equaton systems efnton of boundary-value problems (VPs) n Os umercal soluton of VPs by shootand-try method Use of fnte-dfference equatons to solve VPs Thomas algorthms for solvng fntedfference equatons from second-order VPs Stff Systems of quatons Some problems have multple eponental terms wth dfferng coeffcents, a, n ep(-at) oeffcents wth large values of a wll requre a small tme step for stablty, but wll not be essentally ero after a short tme after the start of the soluton eed specal algorthms for such systems 3 Solvng Stff Os If you try to solve a stff problem wth a conventonal solver you wll fnd that the soluton s takng ecessve tme Stff solvers do more work per step, but allow larger steps Gear s Method and MTL stff solvers ode5s, ode3s, ode3t, ode3tb Users may have to provde code to complete Jacoban matr, 4 oundary-value Problems ll Os solved so far have ntal condtons only ondtons for all varables and dervatves set at t = only In a boundary-value problem, we have condtons set at two dfferent locatons second-order O d y/d = g(, y, y ), needs two boundary condtons () Smplest are y() = a and y(l) = b Med : ady/d+by = c at =, L 5 oundary-value Problems II Solvng boundary-value problems nte dfferences (consdered later) Shoot-and-try Take an ntal guess of dervatve boundary condtons at = and use an ntal-value routne to get y (comp) (L) at the other boundary ompare the value of y (comp) (L) found from the prevous step to the boundary condton on y(l) Use the dfference between y (comp) (L) and y(l) to terate the ntal value of = dy/d = and contnue untl y (comp) (L) y(l) 6 M 5 Semnar n ngneerng nalyss Page
umercal Solutons of oundary-value Problems n Os ovember 7, 7 Shoot-and-Try ample I Look at sngle, second order equaton: y = g(, y, y ), y() = a and y(l) = b efne = y (y = ) to get two frst order equatons: = g(, y, ) and y = Steps n the shoot and try method Guess ntal condton for () = y (); typcally guess () () = [y(l) y()]/l Solve equatons for y computed (L) and compare to specfed boundary condton, y(l) 7 Shoot-and-Try otaton otaton for shoot and try O: d y/d = g(, y, dy/d) = g(, y, ) System of two frst order OS: = dy/d and d/d = g(, y, ) Varables for teraton m (m) () guess for ntal condton of dy/d at = y (m) (L) result at = L from solvng system of two Os usng (m) () y(l) requred boundary condton at = L rror at teraton m: (m) = y (m) (L) y(l) 8 Shoot-and-Try Iteraton djust (m) () untl (m) = y (m) (L) y(l) s less than the allowed error fter frst try wth () () = [y(l) y()]/l try () () = [y(l) y () (L) y()]/l or subsequent tres use lnear nterpolaton to gve ero error () () () () Set ths to ero () () ( ) () 9 Shoot-and-Try ample II Solve d y/d +6sn(y ) = wth y = at = and y = at = L = Must fnd par of frst order equatons Set dy/d = as one O Orgnal O becomes d/d = 6sn(y) We know y() =, but we need () guess () () = [y(l) y()]/l = ( )/ = Ths gves y () () = 3.887 (RK4, h =.5) Try () () = [y() y () () y()]/l = [() ( 3.887) ] =.887 () = y () (L) y(l) = 3.887 = -3.887 Shoot-and-Try ample III RK4 wth () () =.887 gves y () (L) = 8.68 so () = y () (L) y(l) = 8.68 = 8.68 pply general error formula to get () () () () () ( ) ().887 () 8.68.7993 8.68 3.887 ontnue to apply Runge-Kutta to get y (m) (L=), (m) = y (m) (L) y(l), and (m+) () for (m+) Repeat calculatons wth new value of (m+) () from general error formula untl y (m) (L) y(l) M 5 Semnar n ngneerng nalyss Page
umercal Solutons of oundary-value Problems n Os ovember 7, 7 nte-fference Introducton nte-dfference approach s alternatve to shoot-and-try onstruct grd of step se h (varable h possble) between boundares Smlar to grd used for numercal ntegraton = (), = (L), h = L /, k = + kh Replace dfferental equaton at each nteror node by fnte dfference equaton Solve resultng set of algebrac equatons for nteror ponts usng Thomas algorthm nte fference Grd Grd may be unform or non-unform, but unform s easer and has hgher order truncaton error; note: h = ( )/ ----- -------- ------------- ~ ~ ------- --- 3 - - t each node wrte fnte-dfference equvalent to dfferental equaton Handle boundary condtons at and (smplest f y = y() and y = y(l), but can have gradent or med boundares) 3 4 ample Problem Solve d T/d + a T = nte dfference equaton at node [d T/d + a T] = (T + + T - T )/h + a T + O(h ) = Ignore truncaton error Ignore truncaton error and get fntedfference equaton system T + + T - T + h a T = Have + nodes numbered from to wth boundary condtons at and 5 General oundary ondtons Must be able to handle three knds rchlet specfy varables at boundary eumann specfy boundary gradents Med or thrd knd specfy relatonshp between value and gradent at boundary General format a dt/d + bt = c (med) ed T: a =, b =, c = boundary T Gradent: b =, a =, c = value for dt/d Use drectonal fnte-dfference equaton for boundary gradents, dt/d 6 ample ontnued quaton s T - + ( + h a )T + T + = Specfy boundary values T and T T = T(=) = T and T = T(=L) = T Wth specfed boundary values equatons at = and = - become ( + h a )T + T = T T - + ( + h a )T - = T Resultng system of equatons forms trdagonal matr 7 ample Matr quatons nte-dfference equatons n matr form wth = a h have trdagonal form solved by Thomas lgorthm used wth cubc splne (see end sldes) T T T3 T T 8 T T M 5 Semnar n ngneerng nalyss Page 3
umercal Solutons of oundary-value Problems n Os ovember 7, 7 nalytcal Soluton omparson Look at results for h =. ( = ) wth T =, T =, a = and L = ompare to eact soluton below act gradents also used n comparson T T cos( al) T sn( a) T cos( a) sn( al) dt T T cos( al) q k ka d sn( al) q L k dt d L ka T T cos( al) sn( al) 9 Results of nte-fference alculatons T act T rror...98.849.7..496.486.34 3.3.684.697.87 4.4.795.7889.4 5.5.9783.954.4 6.6.739.5.38 7.7.8585.8375. 8.8.88.998.6 9.9.788.799.89. rror and rror Order Get overall measure of error (lke norm of a vector) Typcally use mamum error (n absolute value) or root-mean-squared (RMS) error = has ma =.4-3 and RMS =.83-3. or =, ma =.4-5 and RMS =.73-5 Second-order error n soluton RMS ( T eact T ) numercal oundary Gradents Use second-order dervatve epressons dt 3T 4T T q k k d h dt 3T 4T T q k k d h -q eact /k h -q/k rror.995..357.368.995..999.36 -.953. -.933.786 -.953. -.955. MTL oundary-value Os MTL has two solvers bvp4c and bvp5c for solvng boundary-value Os bvp5c: fnte dfference code mplements four-stage Lobatto IIIa formula, a collocaton formula that provdes a - contnuous soluton that s ffth-order accurate unformly n [a,b] bvp5c solves algebrac equatons drectly; bvp4c uses analytcal condensaton bvp4c handles unknown parameters drectly Solve Trdagonal quatons nte-dfference equatons n matr for eample problem wth = a h Use Thomas lgorthm for Soluton T T T3 T T 3 4 T T M 5 Semnar n ngneerng nalyss Page 4
umercal Solutons of oundary-value Problems n Os ovember 7, 7 M 5 Semnar n ngneerng nalyss Page 5 5 Thomas lgorthm 3 3 General set of trdagonal equatons 6 Thomas lgorthm II Gauss elmnaton upper trangular form Have to fnd and 7 Thomas lgorthm III orward computatons Intal: = / = / pply equatons below for =, -: t fnal pont ack substtute: = + + 8 Result: h =., a =, T =, T = Input orward alculatons ack substtute Spreadsheet ormulas 9 ormulas here solve only for nteror ponts when fed boundary condtons are specfed 3 Other oundary ondtons General condton a dt/d + bt = c a =, b = for eumann (gradent gven) a =, b = for rchlet (value gven) Wrte gradent usng second order forward ( = ) or backward dfference ( = ) ombne wth equaton for frst node n from the boundary to elmnate term wth second node from boundary Result conforms to trdagonal system
umercal Solutons of oundary-value Problems n Os ovember 7, 7 General oundary ample Look at = boundary; results for = follow smlar dervaton dy 3y 4y y a b y a b y c d h 3a 4a a b y y y c dd these h h h two equatons a y ( ) y y elmnatng y h a ( ) a b y y c h h 3 General oundary ample II quaton just derved s seen to gve correct rchlet result for a =, b = a ( ) a b y y c h h Smlar dervaton at = gves a ( ) a b y y c h h quatons shown here wll work for a = or b =, but at least one must be nonero 3 onlnear Problems Shoot-and-try requres no specal procedures for nonlnear problems or fnte dfference or fnte elements, solve a lneared equaton ample s pendulum equaton d /dt = (-g/l) sn (usually solved wth sn ) Taylor seres: sn = sn + [d(sn )/d] ( ) = sn + cos ( ) Replace sn by lnear result to terate 33 onlnear ample Start wth d /dt = (-g/l) sn Replace sn by lneared seres Wrte n teratve form wth (m+) as new teraton and use (m) n nonlnear terms d (m+) /dt = (-g/l) [sn (m) + cos (m) ( (m+) (m) ) efne = g/l and rearrange d (m+) /dt + (m+) cos (m) = [sn (m) (m) cos (m) ] = r 34 onlnear ample II onvert d (m+) /dt + (m+) cos (m) = r to (lnear) fnte-dfference form n (m+) h r cos Have trdagonal system sn r h h r 35 onlnear ample III Make ntal guesses for () Lnear profle () (t) = () + [(L) ()]t/t nd all nodal values for () usng () to compute the nonlnear terms Repeat the process untl the dfferences between teratons s good enough ompute resduals to test convergence R h h r 36 M 5 Semnar n ngneerng nalyss Page 6
umercal Solutons of oundary-value Problems n Os ovember 7, 7 Summary oundary value problems requre specal treatment Shoot-and-try nte dfferences or fnte elements Shoot-and-try s usually better for nonlnear problems and fnte dfferences are better for lnear ones nte elements are more applcable to comple geometry and 3 problems 37 M 5 Semnar n ngneerng nalyss Page 7