{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

lecture20

lecture20 - 1.00 Lecture 20 More on root finding Numerical...

This preview shows pages 1–5. Sign up to view the full content.

1.00 Lecture 20 October 27, 2005 More on root finding Numerical Integration Newton’s Method For small increment and smooth function, st 1 st derivative is small, etc. ... 2 / ) ( ) ( ' ) ( ) ( 2 + + + + δ δ δ x f 0 ) ( = + δ ) ( ' / ) ( x f = δ Based on Taylor series expansion: higher order derivatives are small and implies If high order derivatives are large or 1 derivative is small, Newton can fail miserably Converges quickly if assumptions met Has generalization to N dimensions that is one of the few available See Numerical Recipes for ‘safe’ Newton- Raphson method, which uses bisection when ' ' x f x f x f x f x f 1

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
Newton’s Method ) f(x) f’(x Initial guess of root Newton’s Method Pathology f’(x) f(x) Initial guess of root 2
Newton’s Method public class Newton { // NumRec, p. 365 public static double newt(MathFunction2 func, double a, double b, double epsilon) { double guess= 0.5*(a + b); for (int j= 0; j < JMAX; j++) { double fval= func.fn(guess); double fder= func.fd(guess); double dx= fval/fder; guess -= dx; System.out.println(guess); if ((a - guess)*(guess - b) < 0.0) { System.out.println("Error: out of bracket"); return ERR_VAL; // Experiment with this } // It’s conservative if (Math.abs(dx) < epsilon) return guess; } System.out.println("Maximum iterations exceeded"); return guess; } Newton’s Method, p.2 public static int JMAX= 50; public static double ERR_VAL= -10E10; public static void main(String[] args) { double root= Newton.newt(new FuncB(), -0.0, 8.0, 0.0001); System.out.println("Root: " + root); System.exit(0); } } class FuncB implements MathFunction2 { public double fn(double x) { return x*x - 2; } public double fd(double x) { return 2*x; } } public interface MathFunction2 { public double fn(double x); // Function value public double fd(double x); } // 1st derivative value 3

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
Examples f(x)= x 2 + 1 No real roots, Newton generates ‘random’ guesses f(x)= sin(5x) + x 2 – 3 Root= -0.36667 Bracket between –1 and 2, for example Bracket between 0 and 2 will fail with conservative Newton (outside bracket) f(x)= ln(x 2 –0.8x + 1) Roots= 0, 0.8 Bracket between 0 and 1.2 works Bracket between 0.0 and 8.0 fails 8 Use Roots.java from lab to experiment!
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

• As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

Kiran Temple University Fox School of Business ‘17, Course Hero Intern

• I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

Dana University of Pennsylvania ‘17, Course Hero Intern

• The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

Jill Tulane University ‘16, Course Hero Intern