M 0 Numercal Metods fferentaton Tese presentatons are prepared by r. Cuneyt Sert Mecancal ngneerng epartment Mddle ast Tecncal Unversty Ankara, Turkey csert@metu.edu.tr Tey can not be used wtout te permsson of te autor
ervatve: Rate of cange of a dependent varable wt respect to an ndependent varable. f df dx X lm x0 x x tangent slope = f (x x x wc can be wrtten approxmately as a dfference equaton df dx X f x x x x f x x Numercal dfferentaton s consdered f te functon can not be dfferentated analytcally te functon s known at dscrete ponts only te dfferentaton s to be automated n an algortm.
Fnte vded fference Formulas usng TS Formulas for te frst dervatve Forward dfferencng (use st order TS of + around x. Call ts TS f(! were = x + - x f(! O( Backward dfferencng (use st order TS of - around x. Call ts TS f(! were = x x - f(! O( Centered dfferencng (use TS TS. But consder nd order terms also.!! O( O( O(
Forward and centered dfference formulas are frst order, O(, accurate. Tat s te error drops approxmately by a factor of as te step sze drops to /. Centered dfference formula s second order, O(. rror drops by a factor of 4 as drops to /. Centered dfference formula uses te same number of artmetc operatons as forward and backward formulas, and t offers better accuracy. Terefore t s more effcent. xample : Poston of a body movng n a stragt pat s sown below. Fnd ts velocty. t x v 0.0 0.00.50 0. 0.5 0. 0.47.5 Use forward dfferencng at t = 0.0 x(0. x(0.0 0.5 0.00 v(0.0.50 0. Use centered dfferencng at t = 0., 0., 0. and 0.4 0. 0.6 0.4 0.84 v(0. x(0. x(0. 0.6 0.5 0..5 0.5 0.98.40 Use backward dfferencng at t = 0.5 v(0.5 x(0.5 x(0.4 0.98 0.84 0..40 xercse : Complete te above table. 4
Hger order formulas for te frst dervatve To derve tem use proper combnatons of TS of +, -, +, - Forward dfferencng 4 O( Backward dfferencng 4 O( Centered dfferencng 8 8 O( 4 See pages 6-64 for even more ger order formulas. xercse : erve te above formulas. xercse : Solve te prevous example usng te above formulas. Note tat for t=0.0 and 0. forward dfferencng must be used. For t=0.4 and 0.5 backward dfferencng s sutable. Centered dfferencng can be used only for t=0. and 0.. 5
Formulas for te second dervatve Forward dfferencng f (x O( Backward dfferencng f (x O( Centered dfferencng f (x O( See pages 6-64 for formulas for te rd and 4 t dervatves. xercse 4: erve te above formulas. Use proper combnatons of TS of +, -, + and -. xercse 5: Use te table gven for te frst example to calculate te acceleraton of te partcle. Use te above formulas to take te second dervatve of tme. You can also take te frst dervatve of te prevously calculated veloctes. Compare and comment on te results. 6
How can we mprove te dervatve estmates? Use small values. Use ger order approxmatons. xercse 6: Te followng two tables are for te functon = e x. Tey use step szes of 0. and 0.. Calculate te frst dervatve of te functon usng O( estmates. Calculate true errors. Compare te results. x e t 0.4.49847 0.6.888 0.8.55409.0.7888 x e t 0.4.49847 0.5.6487 0.6.888 0.7.0757 0.8.55409 0.9.45960.0.7888 Anoter alternatve to mprove dervatve estmates s to use Rcardson xtrapolaton. It combnes two estmates obtaned wt dfferent values to get a better estmate. Later we wll use Rcardson xtrapolaton for ntegraton too. 7
8 : xact dervatve (usually not known : stmated dervatve usng =. : rror of te estmaton. = + : stmated dervatve usng =. : rror of te estmaton. = + If we used second-order dfferentaton to get and, tan = O(, = O( Substtute ts nto te frst equaton Solve for Combne ts wt Ts estmate s or order O( 4, obtaned by two O( estmates. A specal case of = / results n 4 Rcardson s xtrapolaton
xample 4: Use Rcardson xtrapolaton to estmate te frst dervatve of sn(x at x=p/4 usng step szes of =p/ and =p/6. Use centered dfferences of O(. Usng =p/ f( p/4 sn( p/4 p/ sn( p/4 ( p/ p/ 0.5847760 e t = 7. % Usng =p/6 f( p/4 sn( p/4 p/6 sn( p/4 ( p/6 p/6 0.67577 e t = 4.5 % Apply Rcardson xtrapolaton f( p/4 4 0.67577 0.5847760 0.70595 e t = 0.4 % Romberg Algortm Apply multple Rcardson xtrapolaton one after te oter untl te error falls below a specfed tolerance. xercse 7: In te above example use =p/ to calculate. Combne wt, and wt to get two O( 4 estmates. Tan combne tese two estmates to get an estmate of order O( 6. 9