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.

156 chapter 7Figure 7.3 Two examples of how the Newton–Raphson algorithm may fail if the initial guess isnot in the region where f (x) can be approximated by a straight line. Left: A guess lands at alocal minimum/maximum, that is, a place where the derivative vanishes, and so the nextguess ends up at x = ∞. Right: The search has fallen into an infinite loop. Backtracking wouldhelp here.programs Newton_cd.java (also Listing 7.1) and Newton_fd.java, which implementthe derivative both ways.✞/ / Newton_cd . java : Newton−Raphson root finder , central diff derivativepublic class Newton_cd {public static double f(double x) { return 2∗Math . cos ( x ) − x; } // functionpublic static void main ( String [] argv ) {double x = 2. , dx = 1e−2, F= f(x) , eps = 1e−6, df ;int it , imax = 100; // Max no of iterations permittedfor ( i t = 0; i t

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

Saved successfully!

Ooh no, something went wrong!