MEE07 Computer Modelng Technques n Engneerng Chapter Derentaton and Integraton Reerence: An Introducton to Numercal Computatons, nd edton, S. yakowtz and F. zdarovsky, Mawell/Macmllan, 990. Derentaton and ntegraton are the two basc processes o calculus. One or both o these processes wll generally be encountered n applcatons where models are descrbed n terms o rates. In prncple, t s always possble to determne an analytc orm o a dervatve or a gven uncton. In some cases, however, the analytc orm s very complcated, and a numercal appromaton o the dervatve may be sucent or our purposes. For unctons whch are descrbed only n terms o tabulated data, numercal derentaton s the only means o computng a dervatve. Numercal ntegraton s used to ntegrate tabulated unctons or to ntegrate unctons whose ntegrals are ether mpossble or very dcult to obtan analytcally.. Numercal Derentaton One approach to numercal derentaton s to t a curve wth a smple orm to the uncton, and then to derentate the curve-t uncton. For eample, the polynomal or splne methods can be used to t a curve to tabulated data or the uncton, and the resultng polynomal or splne can then be derentated. Another approach s to obtan an appromaton o a dervatve drectly n terms o the uncton values. The resultng epresson or the appromaton s known as a derence ormular. Such ormulars are especally useul or solvng derental equatons and may be derved ether rom curve ttng or rom the Taylor seres... Derence Formulas The Taylor seres epanson or a uncton s [(h/! (d / d + (h /! (d /d + L] ( + h ( + (.a We can also wrte the Taylor seres wth a remander term R n+ as (h /! (d / d + (h /! (d I dx +... (h' ln! (d' ld" (.b + + ( h (X + + Rn+
MEE07 Computer Modelng Technques n Engneerng n whch the remander term s gven by n+ n+ ( h [ n + ] d ( n+ ( d R ; ξ + h (.c n+! ξ The error that occurs when the Taylor seres s truncated mmedately ater the term contanng the n-th dervatve s R n+ and s sad to be o order h n+ or 0(h n+. Smple derence ormulas may be obtaned by truncatng the Taylor seres ater -- the rst dervatve term. That s, by wrtng ( ± h ( ± h ( + 0(h ( d (/d (.d we obtan the appromatons Forward Derence: [ ( + h ]/ h O( ( + h (. Backward Derence: [ ( h ]/ h O( ( + h (. The ormulas n Eqs. (. ans (. have truncaton error o order h and are epressed n terms o two uncton values. Hgher-order appromatons may be derved by usng addtonal uncton values. For eample, we use Roman superscrpts to denote the dervatves o the uncton at and wrte epansons or two uncton values as ( + h ( + h + h + h + ( h / + (4h / + O( h + O( h (.4 (.5 We then elmnate the second dervatve term and solve or to obtan [ + 4 ( + h ( + h ]/[ h] O( h ( + (.6 A smlar second-order ormula n terms o (, ( h, and ( h s [ 4 ( h + ( h ]/[ h] O( h ( + (.7
MEE07 Computer Modelng Technques n Engneerng Another way to obtan hgher-order ormulas s to recognze that the sgns n the terms o the Taylor seres epansons or ( + h and ( - h can produce cancellatons. Thus we wrte ( + h ( h + h h + ( h + ( h / / + O( h + O( h (.8 (.9 Subtracton gves the rst-dervatve ormula Central Derence: [ ( + h ( h ]/[ h] O( h ( + (.0 Addton o the epansons or ( + h and ( - h through the thrd-dervatve terms gves a central-derence ormula or the second dervatve as ( [ ( h + ( + h ]/ h + O( h (. The ormulas nvolvng three uncton values have been derved so ar wth constant spacng h between the values. The Taylor seres approach can also be used wth unequal spacng as llustrated n the ollowng eample. Eample. A partcle crosses three sensors whch are spaced at ntervals o 0.m. Measurements o the tme to travel rom sensor to sensor and rom sensor to sensor are 0.0550s and 0.0554s, respectvely. Estmate the speed and acceleraton o the partcle as t crosses the second sensor. Let denote poston, let t denote tme, and let subscrpts denote the sensors. Then Speed at sensor d / dt at tme t ; Acceleraton at sensor d / dt at tme t From Eqs. (.b and (.c, we have epansons about t : 0.0550 ( d/dt + ( 0.0550 / ( d / dt + O ( 0.0550 + 0.0554 ( d/dt + ( 0.0554 / ( d / dt + O ( 0.0554
MEE07 Computer Modelng Technques n Engneerng We neglect the remander terms and solve the resultng lnear equatons by Cramer s rule to obtan the estmate: where v d/dt [( ( 0.0554 / ( ( 0.0550 / ] / D; a d /dt [( ( -0.0550 ( ( 0.0554 ] / D; D -( 0.0550 ( 0.0554 (0.0554 + 0.0550 / ; -0.m; 0.m The results are Speed v 5.4495m/s; acceleraton a -0.7460m/s The estmates or the speed and acceleraton n Eample. could have been ound ( to a slghtly derent level o accuracy by derentaton wth respect to. The procedures are shown n Eample.. Eample. Repeat eample. by usng dervatves wth respect to poston. v d / dt / ( dt / d. From the central-derence ormula o Eq. (.0, v / [( t t / ( ] 5.478m/s a dv / dt ( dv / d ( d / dt v ( dv / d. Thus a v [( v v / ( ] We compute v and v rom Eq. (.4 and (.5 as ollows : v / [ ( -t + 4t t / ( ] 5.474456m/s v / [(t 4t + t / ( ] 5.95685m/s Then a v ( 5.95685 5.474456 / ( 0.6-0.7489m/s The computaton o partal dervatves s the same s or ordnary dervatves when derentaton s wth respect to only one varable. For cross dervatves such as [ /( y], we may derve buld ormulars rom the Taylor seres or several varables, or we may buld up the dervatve rom one-varable orms. For eample, we may use the central-derence ormular to obtan 4
MEE07 Computer Modelng Technques n Engneerng (, y /( y [ (, y / ] / y {[ ( +, y + y (, y + y] /( [ ( +, y + y ( +, y y]/( }/( y (.. Numercal Integraton Integrals arse when we wsh to determne the change n a quantty y whose rate o change wth respect to another varable s descrbed as a uncton (. I we have a relaton dy / d (. the change n y rom y a at equal to a to y b at equal to b s b y b ya d (.4 The relaton n Eq.(. s a smple orm o an ordnary derental equaton. Its soluton s descrbed by the dente ntegral n Eq.(.4. The ntegraton process s a summaton process. We may thnk o the quantty [(d] as the area o a rectangle wth heght ( and wth an nntesmally small wdth d. The dente ntegral n Eq. (. s the same o all such areas or values rom a to b. Numercal ntegraton methods are used when ( s dcult or mpossble to ntegrate analytcally, or when ( s gven as a set o tabulated values... The Trapezodal Rule Consder a uncton ( as vares rom to +. I we use Lagrange nterpolaton to appromate the uncton rom ( to ( by the straght lne [ ] [ ], +, + [( ( ] ( + [( ( ] ( + + + + (.4 and we ntegrate the appromate uncton analytcally, we obtan [ ][ ( ( / d + + + ] + (.5 5
MEE07 Computer Modelng Technques n Engneerng The appromaton gven n Eq. (.5 s known as the trapezodal rule because the rght sde s the area o a trapezod wth base equal to ( + - and parallel sdes equal to ( and ( + as shown n Fg... A smplstc use o the trapezodal rule to evaluate ntegrals o the orm n Eq. (. s as ollows. Dvde the nterval rom a to b nto n subntervals by choosng values 0 through n, that satsy a 0 < < < n- < n b The ponts should he chosen so that the part o the curve ( between and + can be appromated well by a straght lne. Then we have a b d n 0 + d n { [ + ][ ( + ( + ]/ } 0 (.6 Fg.. Illustraton o the trapezodal rule The result gven by Eq. (.6 does not contan any mechansm or controllng the accuracy o the appromaton. It should thereore be used only or quck, normal estmates, or when eperence allows the user to choose the control ponts wth good spacngs, or when ( s descrbed by data values at speced control ponts. Applcatons o the trapezodal rule to obtan estmates that are controlled by a crteron depend on equal spacngs between control ponts and +. I we have equal spacngs, the appromaton n Eq. 6. may be rewrtten as I a d ( / [ ( 0 + ( n ] + [ + ( + L + ( n ] (.7 b 6
MEE07 Computer Modelng Technques n Engneerng The rst term on the rght-hand sde s the trapezodal rule appromaton wth only the end ponts as the control ponts. We begn wth ths term as the ntal estmate o the ntegral I. Then we repeatedly rene our estmate by addng more control ponts at the mdponts o estng ntervals untl successve estmates show no sgncant change. An llustraton o the process through two renements s shown n Fg... For any renement r (greater than zero, the spacng r s equal to ( r- /, the number k o new control ponts s equal to r-, and the new control ponts are located at m- ( a + [m ] r ; m,,, k (.8 Fg.. Rened estmates o an ntegral wth the trapezod rule. The quantty ε n the trapezodal rule pseudo code s used to end the renement process when the change n the estmate o I becomes sucently small. The quantty r na s used to lmt the number o renements n case ε s chosen to be unrealstcally small. In general, the applcaton that we have descrbed s best used or ntervals onwhch the values o the ntegrand ( are ether all nonnegatve or all non-postve. I we observe ths restrcton, we can change the termnaton crteron to one n whch the magntude o I becomes smaller than a small racton o the magntude o I. Ths racton can be based easly on the precson level o the machne and s not as arbtrary as the choce o the quantty ε. 7
MEE07 Computer Modelng Technques n Engneerng I we do not observe the restrcton on the uncton values, we should specy a mnmum number o renements; otherwse, the renement loop may be termnated too quckly and may produce an ncorrect result. For eample, consder the ntegrand ( e - sn and ntegraton lmts a, equal to 0 and b equal to π. Because ( s zero at a, and at b and also at ( a + b /, the estmates I 0 and I wll both be zero and wll cause premature termnaton o the process. To overcome that problem, we should ether specy a mnmum number o renements or splt the ntegral nto two ntegrals rom 0 to π and rom π to π... Smpson's Rule An obvous way to mprove the appromaton o an ntegral s to use a better model or the ntegrand (. One attempt at a better model s to use a quadratc nstead o a lnear appromaton. A Lagrange nterpolatng polynomal through the ponts [, ( ], [ +, ( + ], and [ +, ( + ] provdes a quadratc appromaton. When the spacngs ( + and ( + - + are chosen to be equal, analytcal ntegraton o the appromatng quadratc yelds Smpson's rule: + d [ + ][ ( + 4 ( + + ( + ]/ 6 (.9 As wth the trapezodal rule, we may apply Smpson s rules n a smplstc way to ntegrals o the orm n Eq. (.4 by dvdng the nterval rom a to b nto an even number o subntervals. We do so by choosng control ponts 0 through j that satsy a+0<< <Xj-<jb The Smpson's rule appromaton o the ntegral s then; b a d j p 0 p+ p d j { [ p+ p ][ ( p + 4 ( p+ + ( p+ ]/ 6} p 0 (.0 8