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...

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

44 chapter 2computation. Accordingly, do these exercises in double precision, as you shouldfor all scientific calculations involving floating-point numbers.1. Write a program that calculates sin(x) as the finite sum (2.43). (If you alreadydid this in Chapter 1, “Computational Science Basics,” then you may reusethat program and its results here.)2. Calculate your series for x ≤ 1 and compare it to the built-in functionMath.sin(x) (you may assume that the built-in function is exact). Stop yoursummation at an N value for which the next term in the series will be nomore than 10 −7 of the sum up to that point,|(−1) N x 2N+1 |(2N − 1)!≤ 10 −7 ∣ ∣∣∣∣ N ∑n=1(−1) n−1 x 2n−1(2n − 1)!∣ . (2.44)3. Examine the terms in the series for x ≃ 3π and observe the significant subtractivecancellations that occur when large terms add together to give smallanswers. [Do not use the identity sin(x +2π) = sin x to reduce the value ofx in the series.] In particular, print out the near-perfect cancellation aroundn ≃ x/2.4. See if better precision is obtained by using trigonometric identities to keep0 ≤ x ≤ π.5. By progressively increasing x from 1 to 10, and then from 10 to 100, use yourprogram to determine experimentally when the series starts to lose accuracyand when it no longer converges.6. Make a series of graphs of the error versus N for different values of x. (SeeChapter 3, “Visualization Tools.”) You should get curves similar to those inFigure 2.3.Because this series summation is such a simple, correlated process, the round-offerror does not accumulate randomly as it might for a more complicated computation,and we do not obtain the error behavior (2.32). We will see the predicted errorbehavior when we examine integration rules in Chapter 6, “Integration.”−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 44

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

Saved successfully!

Ooh no, something went wrong!