12.07.2015 Views

COPYRIGHT 2008, PRINCETON UNIVERSITY PRESS

COPYRIGHT 2008, PRINCETON UNIVERSITY PRESS

COPYRIGHT 2008, PRINCETON UNIVERSITY PRESS

SHOW MORE
SHOW LESS
  • No tags were found...

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

150 chapter 7algorithm (7.7) is O(h 2 ):ɛ fdapprox ≃ y′′ h2 , ɛcd approx ≃ y′′′ h 224 . (7.12)To obtain a rough estimate of the round-off error, we observe that differentiationessentially subtracts the value of a function at argument x from that of the samefunction at argument x + h and then divides by h: y ′ ≃ [y(t + h) − y(t)]/h. Ashis made continually smaller, we eventually reach the round-off error limit wherey(t + h) and y(t) differ by just machine precision ɛ m :ɛ ro ≃ ɛ mh . (7.13)Consequently, round-off and approximation errors become equal whenɛ ro ≃ ɛ approx ,ɛ mh ≃ ɛfd approx = y(2) h2 , ɛ mh ≃ ɛcd approx = y(3) h 224 , (7.14)⇒ h 2 fd = 2ɛ my , ⇒ (2) h3 cd = 24ɛ my . (3)We take y ′ ≃ y (2) ≃ y (3) (which may be crude in general, though not bad for e t orcos t) and assume double precision, ɛ m ≃ 10 −15 :⇒h fd ≃ 4 × 10 −8 , h cd ≃ 3 × 10 −5 ,ɛ fd ≃ ɛ mh cd≃ 3 × 10 −8 , ⇒ ɛ cd ≃ ɛ mh cd≃ 3 × 10 −11 .(7.15)This may seem backward because the better algorithm leads to a larger h value.It is not. The ability to use a larger h means that the error in the central-differencemethod is about 1000 times smaller than the error in the forward-difference method.We give a full program Diff.java on the instructor’s disk, yet the programmingfor numerical differentiation is so simple that we need give only the lines✞☎FD = ( y ( t +h ) − y(t) ) /h; / / forward diffCD = ( y( t+h/2) − y(t−h/2) ) /h; // central diffED = ( 8 ∗ (y( t+h/4) − y(t−h/4) ) − (y(t+h/2)−y(t−h/2) ) ) /(3∗h) ; // extrap diff✝1. Use forward-, central-, and extrapolated-difference algorithms to differentiatethe functions cos t and e t at t =0.1, 1., and 100.a. Print out the derivative and its relative error E as functions of h. Reducethe step size h until it equals machine precision h ≃ ɛ m .b. Plot log 10 |E| versus log 10 h and check whether the number of decimalplaces obtained agrees with the estimates in the text.c. See if you can identify regions where truncation error dominates at largeh and round-off error at small h in your plot. Do the slopes agree with ourmodel’s predictions?−101<strong>COPYRIGHT</strong> <strong>2008</strong>, PRINCET O N UNIVE R S I T Y P R E S SEVALUATION COPY ONLY. NOT FOR USE IN COURSES.ALLpup_06.04 — <strong>2008</strong>/2/15 — Page 150

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!