lecture20

lecture20 - 1.00 Lecture 20 October 27, 2005 More on root...

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

View Full Document Right Arrow Icon
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
Background image of page 1

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

View Full DocumentRight Arrow Icon
Newton’s Method ) f(x) f’(x Initial guess of root Newton’s Method Pathology f’(x) f(x) Initial guess of root 2
Background image of page 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
Background image of page 3

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

View Full DocumentRight Arrow Icon
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! Numerical Integration
Background image of page 4
Image of page 5
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 14

lecture20 - 1.00 Lecture 20 October 27, 2005 More on root...

This preview shows document pages 1 - 5. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online