204 C H A P T E R 5 Numerical Solution ofInitial -Value Problems 5.c.y'=— (y+l)(.y+3),for0(titwithi),fori=0,1,...,N-1, forsome function 0.Anideal difference -equation method would have theproperty that given atolerance e>0,theminimal number ofmesh points would beused toensure thattheglobal error,|y(/,)— w,|,would notexceed eforanyi=0,1,....N.Having a minimal number ofmesh points andalsocontrolling theglobal error ofadifference method is,notsurprisingly ,inconsistent with thepoints being equally spaced intheinterval .Inthis section weexamine techniques used tocontrol theerror ofadifference -equation method in anefficient manner bytheappropriate choice ofmesh points . Although wecannot generally determine theglobal error ofamethod ,there isoften a close connection between thelocal error andtheglobal error.Ifamethod haslocal error 0(hn+]),then theglobal error ofthemethod is0(hn).Byusing methods ofdiffering order wecanpredict thelocal error and,using thisprediction ,choose astep size thatwillkeep theglobal error incheck. Toillustrate thetechnique ,suppose thatwehave twoapproximation techniques .The firstisannth-order method obtained from annth-order Taylor method oftheform y(»i+i)=y«i)+ ,yfo).h)+0(h"+i). Copyright 2012 Cenfajc Learn in*.AIRight*Reversed Mayr*xbecopied.KiMcd.o*iSaplicmed .inwhole orinpar.Doctoejevtronie itghu.some third pur.ycontent may besuppressed rrom theeBook aml/oreChaptcnal .Editorial review h*. deemed Cutanysuppressed content docs notnutetlaly afTcot theoverall Ieamir .itexperience .Cenitape [.camon reserves theright n>remove additional conceal atanytime i!suhvcqjcM right*restrictions require it5.6 Adaptive Techniques 205 This method produces approximations w0=a w,+i=w,+h(ti,with)fori>0, which satisfy ,forsomekandallrelevant handi, Ingeneral ,themethod isgenerated byapplying aRungc -Kutta modification totheTaylor method ,butthespecific derivation isunimportant . Thesecond method issimilar butofhigher order .Forexample ,letussuppose itcomes from an(n4-l)st-order Taylor method oftheform y(tl+1)=y(t,)+Aftfe,yfe).h)+0(h"+2), producing approximations wo=cr w,+1=vv,+ wnh )for i>0, which satisfy ,forsome Randallrelevant hand i. Weassume now thatatthepoint tjwehave w,=W i=z(/,), where z(r)isthesolution tothedifferential equation thatdoes notsatisfy theoriginal initial condition butinstead satisfies thecondition z(r,)=w,.Thetypical difference between y(t) andz(t)isshown inFigure 5.3. Figure 5.3 y, i)- Global>/error zCO-1 -w, aVLocal error a U*i+1t Applying thetwomethods tothedifferential equation with thefixed stepsizehproduces twoapproximations ,w,-+jandw,-+i,whose differences from y(f,+/i)represent global errors butwhose differences from +h)represent local errors . Copyright 2012 Cengagc Learning .AIRights Reversed May notbecopied .scanned .orduplicated .inwhole orinport .Doc toelectronic rlghtv .>onic third pur.ycontent may bevuppreved rrom theeBook aml/orcCh deemed Cutany vuppic-cdcontent does nottnaxrUXy alTcei theioera .1learning experience .('engage [.cammereserves theright 10remove additional conteat atanytime ifvutoeqjcni nghtv restrictions require It206 C H A P T E R 5 Numerical Solution ofInitial -Value Problems Now consider z(ti+h)-wl+1=(w,-+1-wM )+(z(/4+h)-wi+l). Theterm ontheleftsideofthisequation is0(h n+l),thelocal error ofthenthorder method , butthesecond term ontheright sideisO(h n Jr l ),thelocal error ofthe(n+l)storder method . This implies thatthedominant portion ontheright sidecomes from thefirst term;thatis, zifi+h)-W|+I%wl+1-wi+i=0(hn~]). So,aconstant Kexists with Kh n~{=|z(h+h)-wi+\|%|w,+i-wi+i|# and Kcanbeapproximated by „ IVv.+i-wi+i| A^:hn+\(5.3) Letusnow return totheglobal error associated with theproblem wereally want to solve , y'=/(f,y),ioxa deemed Cutanysuppressed content does nottnaxrUXy alTcct theoverall leamir*experience .Ceng age[.camonreserves theright 10remove additional conteatatanytime ifsubsequent rights restrictions require It.5.6 Adaptive Techniques 207 toestimate thelocal error inaRunge -Kutta method oforder 4, 25, 1408, 2197 , 1, Wl+'=Wi+2i6k'+X65ki+4mk*-5ks' where thecoefficient equations are *i=hf(thWj ), k2=hf k3=hf kA=hf kS=hf ki=hf(n+ ^.w,+!**), / 3/i 3, 9,\ Vi+T’H’'+32il+32*2J’ (\2h+IT’ ( ( h 8 V 2’Wi_ 271932 , 7200 , 7296 , W,+2197*‘2197*2+2197*3) , 439, o, 3680 , 845 , *+* "'+216*"S*2* , 3544, 1859 ,*1H-2*2—__._*3+77777*44104) -SM - Anadvantage ofthismethod isthatonly sixevaluations of/arerequired perstep, whereas arbitrary Runge -Kutta methods oforder 4and5used together would require (see Table 5.9onpage 188)atleast four evaluations of/forthefourth -order method andan additional sixforthefifth-order method . Inthetheory oferror control ,aninitial value ofhattheithstepwas used tofind the first values ofwi+\and wl+1,which ledtothedetermination ofqforthatstep.Then the calculations were repeated with thestep sizehreplaced byqh.This procedure requires twice thenumber offunctional evaluations perstepaswithout error control .Inpractice , thevalue ofqtobeused ischosen somewhat differently inorder tomake theincreased functional -evaluation costworthwhile .Thevalue ofqdetermined attheithstepisused for twopurposes :  When q<1,toreject theinitial choice ofhattheithstep andrepeat thecalculations using qh,and  When q>1,toaccept thecomputed value attheithstep using thestep sizehandto increase thestepsizetoqhforthe(i+l)ststep. Because ofthepenalty interms offunctional evaluations that must bepaid ifmany steps arerepeated ,qtends tobechosen conservatively .Infact,fortheRunge -Kutta -Fehlberg method withn=4,theusual choice is q=(«»Y/4»OM(«r.\2|wi+i-wi+\\J \|w,+i-wj+il/ Theprogram RKFVSM 55 implements the Runge -Kutta-Fehlberg method .Program RKFVSM 55incorporates atechnique toeliminate large modifications instep size.This isdone toavoid spending toomuch time with very small step sizes inregions with irregularities inthederivatives ofy,andtoavoid large stepsizes ,which might result inskipping sensitive regions nearby .Insome instances thestep-size-increase procedure isomitted completely andthestep-size-decrease procedure ismodified tobeincorporated only when needed tobring theerror under control . Copyright 2012 Cengagc Learn in*.AIRight*Reversed May rotbecopied.wanned .ocimplicated ,inwhole orinpar.Doctocjectronie rightv.some third pur.ycontent may besupplied rican theeBook and/orcChaptcnM .Editorial review h*> deemed Cutanysupprewed content does notmaterial yalTcct theoverall learn ireexperience .Cenit apeI.cm/inreserves theright Mremove additional conteatatanytime i!subsequent right*restriction*require It.208 C H A P T E R 5 Numerical Solution ofInitial-Value Problems Example 1UsetheRunge -Kutta-Fehlberg method withatolerance TOL=10-5,amaximum stepsize hmax =0.25,andaminimum step sizehmin=0.01 toapproximate thesolution tothe initial -value problem y=y-t2+l,0 439, 3680, 845,*5=hf(«,+ft.WO+— -8*2+_*3-— ( 439 3680 845=0.25/(0.25,0.5+— 0.375-8(0.3974609 )+— 0.4095383 -— 0.4584971 il =0.4658452 ; 1859 / 1 8 3544k6=h f(t o+-h,wo--ft,+2k2-— k}+^*4-JM =0.25/(0.125 ,0.5-^;0.375 +2(0.3974609 )-^0.4095383\ 27 2565 1859 11 \+ 0.4584971 0.46584524104 40 J =0.4204789 . Thetwoapproximations toy(0.25)arethen found tobe 16, 6656 , 28561 , 9, 2,*'=w o+j35*.+12825*3+56430^-50*5+55** 16 6656 28561 9=0.5+T^O.375+ 0.4095383 +- 0.4584971 - 0.4658452135 12825 56430 50 +^0.4204789 */ / =0.9204870 , Copyright 2012 Cengagc Learning .AIRight*Reversed May ncabecopied ,canned ,orduplicated .inwhole orinpar.Doctoelectronic rightv.xvtic third pur.ycontent may bevuppreved riom*ceBook amtar cCh deemed Cutanysuppicwcd content docs notmaterial yafTcct theoverall teamireexperience .Ccitit apeLearning reserve*theright Mremove additional conceal atanytime i!vubveqjcnt right*restriction*require it5.6 Adaptive Techniques 209 and 25, 1408 , 2197 , 1, W,=W0+2l6*1+2565*3+4l04b"5te 25 1408 2197 1=0.5+— 0.375 +^7^0.4095383 +— — 0.4584971 --0.4658452216 2565 4104 5 =0.9204886 . Theapproximations with h=0.25 ande=10"5give q=(-~7)'=0.9462100 .\2lvv,-Wily Since q<1,weneed torecompute thevalues ofwjandwiwith thenewstepsize h=0.9462100 (0.05 )=0.2365525 . Recalculating with thisstepsizegives usq=0.9986023 which isagain lessthan1.Redoing thecalculations with thestepsize h=(0.9986023 )(0.2365525 )=0.2362221 . gives avalue ofq=0.9999643 which isstilllessthan one.This requires achange instep sizeto h=(0.9999643 )(0.236222 )=0.2362137 . Forthisstepsizewegetq=1.000002 >1.So,weaccept that,with thestepsize0.2362137 , theapproximation w\issufficiently accurate approximation toy(0.2362137 ). Theresults from program RKFVSM 55areshown inTable 5.13.Notice thatthestep sizeonthelastlinehasbeen adjusted sothatanapproximation isgiven fory(2).Keep in mind thattheerrors listed areglobal errors ,andtheRunge -Kutta -Fehlberg method controls local errors . Table 5.13 ti yW hiRKF-4 w, ly(f«)-wi\RKF-5 Wi 1 0.2362137 0.8950018 0.2362137 0.8950028 1.0x10'60.8950016 2.0xlO'1 0.4724278 1.3661020 0.2362142 1.3661042 2.2x10"61.3661031 1.1x10"6 0.7147675 1.9185718 0.2423397 1.9185755 3.7x10"61.9185745 2.7x10"6 0.9647675 2.5482226 0.2500000 2.5482282 5.6xlO62.5482272 4.6x10"6 1.2147675 3.2204398 0.2500000 3.2204475 7.7xlO"63.2204469 7.1x10"6 1.4647675 3.9118102 0.2500000 3.9118204 1.02x10“ 53.9118202 1.00 x10"s 1.7147675 4.5922707 0.2500000 4.5922836 1.29 x10“ 54.5922839 1.32 x105 1.9647675 5.2232194 0.2500000 5.2232351 1.57 xlO55.2232362 1.68 x10-5 2.0000000 5.3054720 0.0352325 5.3054883 1.63x10'55.3054883 1.63x10s Anadaptive Runge -Kutta method isavailable inMATLAB using thecommand ode45. Tousethiscommand foroursample initial value problem ,wefirst need todefine the function /(/,y)using anM-filewhich wename odefunction 2.m. Copyright 2012 Cengagc Learn in*.AIRighto Reversed Mayr*xbecopied.wanned .orimplicated ,inwhole ormpart.Doctocjectronie ilghtv.some third pur.ycontent may besupplied ftem theeBook and/orcChaptcnM .Editorial review h*> deemed Cutanysupprewed content docs notnuxtlaly afTcct theoverall Ieamir .itexperience .Cenitape Learn rcsenn theright n>remove additional conceal atanytime i!vuhvcqjcM nghtv restrictions require It.210 C H A P T E R 5 Numerical Solution ofInitial-Value Problems function YY=odefunction 2(t,y) YY=y-t“ 2+l Wethen need tomake thefunction known toMATLAB using f=Qodefunction 2 Wedefine arange oftvalues forwhich wewant toapproximate they(f)values beginning attheinitial value a=0andending atthevalue b— 2.Therange oftvalues areplaced in thestructure called tspan tspan =[0.00.20.4 0.60.81.01.21.41.61.8 2.0] andwedefine theinitial value y(0)=0.5with y0=0.5 Weinvoke thefunction ode45using thefollowing command [T,YY]=ode45(f,tspan ,yO) which produces thevalues oftandcorresponding approximations to>(/)inthetwol l x l arrays 0 0.500000000000000 0.200000000000000 0.829298806102213 0.400000000000000 1.214087852350423 0.600000000000000 1.648940818452941 0.800000000000000 2.127229773242783 1.000000000000000 and YY= 2.640859343211129 1.200000000000000 3.179941816703143 1.400000000000000 3.732400315281681 1.600000000000000 4.283484106130412 1.800000000000000 4.815176603278762 2.000000000000000 5.305472351203669 Variable Step -Size Predictor -Corrector Methods The Runge -Kutta -Fehlberg method ispopular forerror control because ateach step it provides ,atlittle additional cost,twoapproximations thatcanbecompared andrelated to thelocal error.Predictor -corrector techniques always generate twoapproximations ateach step,sotheyarenatural candidates forerror-control adaptation . Todemonstrate theprocedure ,weconstruct avariable -step-sizepredictor -corrector method using theexplicit Adams -Bashforth Four-Step method aspredictor andtheimplicit Adams -Moulton Three -Step method ascorrector . TheAdams -Bashforth Four-Step method comes from theequation yft+i)=ytt)+zr[55/fe,yft))-59/tt_ i,y(fi»i))24 251+37/ft_ 2,yfc-j))-9/ft_j,y(f,-3»]+^/5)(A.)*5 forsome in f,+i).Suppose weassume thattheapproximations wo,w j,...,w,are allexact and,asinthecase oftheone-step methods ,weletzrepresent thesolution tothe differential equation satisfying theinitial condition z(f,)=w,.Then thedifference between theactual solution andthepredicted solution w,+itPis 251z(f>+i)-W/+1.P= Z<5)(£;)/>5forsome A;in(r,_ 3,r,). (5.4) Copyright 2012 Cengagc Learning .AIRights Reserved May n«becopied .scanned .orduplicated.»whole o tmpnn .Doc ioelectronic rights .some third pur.ycontent may besuppreved riom theeBook and/orcClupccriM .Editorial toiew h*> deemed Cutany suppic-cdcontent dees notmaterial yaffect theioera .1learning experience .Ceng age[.camon reserves theright 10remote additional contort atanytime ifsubsequent rights restrictions require IL5.6 Adaptive Techniques 211 Asimilar analysis oftheAdams -Moulton Three -Step corrector method leads tothelocal error 19zft+t)-W/41= z(5)(Ai)*5forsome A,in(r,_ 2,tM). (5.5) Toproceed further ,wemust make theassumption thatforsmall values ofh, Z(5,(A-)*z(5,(A/), andtheeffectiveness oftheerror-control technique depends directly onthisassumption . Ifwesubtract Eq.(5.5)from Eq.(5.4),andassume thatz(5,(£,)«z(5)(£, )*wehave W,+1-Wj+t.p=^[251 Z<5)(AI)+19Z(5)(A,)]»|/»5z<5)(Af), SO Z(5,(A.)**^(wi+i-w'+i.p)- Using thisresult toeliminate theterm involving /I5Z(5)(£,)from Eq.(5.5)gives the approximation totheerror Izfo+i)“ w.+il^19h5 7208— |wl+,-w,+ltP|19|w,+i-Wj+\tp\ 270 This expression was derived assuming thatwo,w\,...,w,-aretheexact values of y(fo),y(fi),   ,y(ti),respectively ,which means thatthisisanapproximation tothelocal error.Asinthecase oftheone-step methods ,theglobal error isoforder onedegree less, soforthefunction ythatisthesolution totheoriginal initial -value problem , y'=/(/,y),forapand Tocontrol theglobal error towithin e,wewant tochoose qsothat |z(f,-fqh)— wl+i(using thestepsizeqh)\ i ^ qh Butfrom Eq.(5.5), |z(r,H-qh)-Wj+i(using qh)^ qh19 720z<5)(A.)|?V %19 7208 3/i5lwi+l“ w/+l.p soweneed tochoose qwith 29 7208 3h5K+i-w.+i.pl4,4 1 9 W/+1“ Wi+i,p 4qh=—— — q<£.H270 h * Consequently ,weneed thechange instepsizefrom htoqh,where qsatisfies q< — \'%2f )1. V19K+i-wl+1omc third pur.yCOMCK may besuppteved rrom theeBook and/orcCh deemed Cutany Mjppic-cdcontent do»notmaterial yalTcce theoverall learning experience .('engage [.camon reserve*theright lorenxwe additional contort atanytime ifcutoeqjcni nghto mtrictinn*require It212 C H A P T E R 5 Numerical Solution ofInitial -Value Problems Anumber ofapproximation assumptions have been made inthisdevelopment ,soin practice qischosen conservatively ,usually as QVK +i-Wi+i.pl/ Achange instep sizeforamultistep method ismore costly interms offunctional evaluations than foraone-step method because new equally -spaced starting values must becomputed .Asaconsequence ,itisalsocommon practice toignore thestep-sizechange whenever theglobal error isbetween e/10ande;thatis,when e 10r’- Copyright 2012 Cenfajc Learn in*.AIRighb Reserved May n«becopied.scanned .ocduplicated .inwhole orinpar.Doctociecironie rights.some third pur.ycontcir.may besuppteved rrom theeBook aml/orcCh deemed Cutanysuppressed content dees notmaterial yafTcot theoverall [cam ireexperience Ccnp jpe[.camoproenti thenjht Mremove additional eonteatatanytime i!subseqjent nphts restrictions requite It.5.6 Adaptive Techniques 213 Because thisexceeds thetolerance of105anew step sizeisneeded andthenew step sizeis /10-V4( 10-5\1/4 q h=\*T)=(2(2.941 x1(H)J(0-2)=0.642 (0.2)«0.128 . Asaconsequence ,weneed tobegin theprocedure again computing theRunge -Kutta values with thisstep size,andthen usethepredictor -corrector method with thissame stepsizeto compute thenew values ofw4/,andw4.Wethen need toruntheaccuracy check onthese approximations toseethatwehave been successful .Table 5.14 shows thatthissecond run issuccessful andlistsalltheresults obtained using theAdams Variable Predictor -Corrector method . IBDieS .IH r y(fi) hi sTI1 0 0.5 0.5 0.1257017 0.7002323 0.7002318 0.1257017 4.051 x1060.0000005 0.2514033 0.9230960 0.9230949 0.1257017 4.051 x10"60.0000011 0.3771050 1.1673894 1.1673877 0.1257017 4.051 x10~60.0000017 0.5028066 1.4317502 1.4317480 0.1257017 4.051 x10“ 60.0000022 0.6285083 1.7146334 1.7146306 0.1257017 4.610 x10“ 60.0000028 0.7542100 2.0142869 2.0142834 0.1257017 5.210 x10~60.0000035 0.8799116 2.3287244 2.3287200 0.1257017 5.913 x10“ 60.0000043 1.0056133 2.6556930 2.6556877 0.1257017 6.706 x10"60.0000054 1.1313149 2.9926385 2.9926319 0.1257017 7.604 xlO"60.0000066 1.2570166 3.3366642 3.3366562 0.1257017 8.622 x10-60.0000080 1.3827183 3.6844857 3.6844761 0.1257017 9.777 x10"60.0000097 1.4857283 3.9697541 3.9697433 0.1030100 7.029 x1060.0000108 1.5887383 4.2527830 4.2527711 0.1030100 7.029 xlO60.0000120 1.6917483 4.5310269 4.5310137 0.1030100 7.029 x10-60.0000133 1.7947583 4.8016639 4.8016488 0.1030100 7.029 x10-6 0.0000151 1.8977683 5.0615660 5.0615488 0.1030100 7.760 xlO60.0000172 1.9233262 5.1239941 5.1239764 0.0255579 3.918 x1080.0000177 1.9488841 5.1854932 5.1854751 0.0255579 3.918 x10“ 80.0000181 1.9744421 5.2460056 5.2459870 0.0255579 3.918 x10"80.0000186 2.0000000 5.3054720 5.3054529 0.0255579 3.918 x10” 80.0000191 MATLAB uses thecommand odell 3toimplement avariable -stepsizeandvariable - order Adams -Bashforth -Moulton method .Itcanbemore efficient than ode45forsmaller error tolerances because itcanusehigher -order methods ifneeded . E X E R C I S E S E T 5 . 6 1. Theinitial -value problem y'=y/2— yV,for0 deemed Cutanyvuppicwed content dec>notmaterial yalTca theoverall leamir*experience .C'cniMpc Learn xtprexrvei thert|>htlorenxyve additional contort atanytime i iwtoeqjcni rt|!ht>rotrictionv require IL214 C H A P T E R 5 Numerical Solution ofInitial -Value Problems 2. Theinitial -value problem y=—y+1— j,for1-l-3),for0(0)=-2;actual solution .y(/)=— 3+2(1+e-2,)_ l. d.y=(f+2/3)y3-f)\for0?i£tu2012 Cc«£»fcLearn in*.AIR.(huRocncd Mayr*xbecopied ,canned ,o*daplicaied.»whole o»mpan.Doctoelectronic rifhu.*wcthird pony contcac may besuppreved Trent theeBook and/orcCh deemed CutanyMpprcucd content dec>notimtctlaly alTca theoverall leamir*experience .C'cttitape Learnmp re\me»thertpht 10renxyve additional conceal atanytime i iwtoeqjcni npht »rotrictionc require It