Presentation is loading. Please wait.

Presentation is loading. Please wait.

CSCE 206 1 Finding Roots of Equations This is a fundamental computational problem Several methods exist. We will look at the bisection method and at Newton’s.

Similar presentations


Presentation on theme: "CSCE 206 1 Finding Roots of Equations This is a fundamental computational problem Several methods exist. We will look at the bisection method and at Newton’s."— Presentation transcript:

1 CSCE 206 1 Finding Roots of Equations This is a fundamental computational problem Several methods exist. We will look at the bisection method and at Newton’s method

2 CSCE 206 2 Roots of Equations by Bisection If f(x1) and f(x2) are of opposite signs, and if f(x) is a continuous function, then there must be a root of f(x) somewhere between x1 and x2

3 CSCE 206 3 Roots of Equations by Bisection (2) if f(x_lower)*f(x_upper) < 0 x_middle = (x_lower + x_upper)/2 if(f(x_lower)*f(x_middle) < 0) x_upper = x_middle (use lower and middle) else x_lower = x_middle (use middle and upper) endif (Repeat until (x_middle – x_lower) < tolerance

4 CSCE 206 4 Roots of Equations by Bisection (3) We stop on an absolute condition on the root itself— since the root lies between lower and upper, the error in the root if we choose the middle as the approx root is lessequal the distance from the middle to either endpoint. Reasonably fast, reasonably foolproof, and trivial to program.

5 CSCE 206 5 Roots of Equations by Bisection (4) What if we don’t have x-values for which f(x) is of opposite signs? Then we will have to search for values that do. This isn’t necessarily easy…

6 CSCE 206 6 The End

7 CSCE 206 7 Roots by Newton’s Method Given any value x0, then f’(x0) is the slope of the tangent line If x1 is the point at which the tangent line crosses the x-axis, then we have (f(x0) – f(x1))/(x0 – x1) = f’(x0) Since f(x1) = 0, we solve to get x1 = x0 – f(x0)/f’(x0)

8 CSCE 206 8 Roots by Newton’s Method (2) If we have any point x0 and we can compute f(x) and f’(x), then iterate x n+1 = x n – f(x n )/f’(x n ) Unlike the bisection method, we do not have an absolute stopping criterion We stop when ABS(f(x n )/f’(x n )) gets small, because then our approximation to a root is no longer changing very much

9 CSCE 206 9 Roots by Newton’s Method (3) Newton’s method, when it works, converges very quickly (5-6 iterations instead of 20 for simple, student-exercise-like functions) Newton’s method also does not require that we have bracketed the location of a root, as in bisection But it doesn’t always work. On a function with no root, it may run forever. There are functions for which it won’t work at all.

10 CSCE 206 10 Square Roots by Newton’s Method (4) One function on which Newton works brilliantly is x**2 – a that is, square roots For square roots, Newton can be shown to be the best possible method given the accuracy of the intermediate values used.

11 CSCE 206 11 The End


Download ppt "CSCE 206 1 Finding Roots of Equations This is a fundamental computational problem Several methods exist. We will look at the bisection method and at Newton’s."

Similar presentations


Ads by Google