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.

✞errors & uncertainties in computations 394. Compare the upward and downward recursion methods, printing out l, j (up)j (down)l, and the relative difference |j (up)l− j (down)l|/|j (up)l| + |j (down)l|.5. The errors in computation depend on x, and for certain values of x, both upand down recursions give similar answers. Explain the reason for this.// Bessel . java : Spherical Bessels via up and down recursionimport java . io .∗ ;public class Bessel { / / Global class variablespublic static double xmax = 4 0 . , xmin = 0.25 , step = 0.1;public static int order = 10, start = 50;public static void main ( String [] argv ) throws IOException , FileNotFoundException {double x;PrintWriter w = new PrintWriter (new FileOutputStream ("Bessel .dat") , true );for ( x = xmin ; x 0 ; k−−) j [k−1] = ((2.∗ k+1.)/x)∗ j [k] − j [k+1];scale = (Math . sin ( x )/x )/ j [0]; // Scale solution to known j [ 0 ]return j [n] ∗ scale ;}}✝l,☎Listing 2.1 Bessel.java determines spherical Bessel functions by downward recursion(you should modify this to also work by upward recursion).2.3 Experimental Error Investigation (Problem)Numerical algorithms play a vital role in computational physics. Your problem isto take a general algorithm and decide1. Does it converge?2. How precise are the converged results?3. How expensive (time-consuming) is it?On first thought you may think, “What a dumb problem! All algorithms converge ifenough terms are used, and if you want more precision, then use more terms." Well,some algorithms may be asymptotic expansions that just approximate a functionin certain regions of parameter space and converge only up to a point. Yet even if auniformly convergent power series is used as the algorithm, including more termswill decrease the algorithmic error but increase the round-off errors. And becauseround-off errors eventually diverge to infinity, the best we can hope for is a “best”approximation. Good algorithms are good not only because they are fast but alsobecause being fast means that round-off error does not have much time to grow.−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 39

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

Saved successfully!

Ooh no, something went wrong!