Presentation is loading. Please wait.

Presentation is loading. Please wait.

Newton’s Method, Root Finding with MATLAB and Excel

Similar presentations


Presentation on theme: "Newton’s Method, Root Finding with MATLAB and Excel"— Presentation transcript:

1 Newton’s Method, Root Finding with MATLAB and Excel
Chapter 6 Finding the Roots of Equations Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display.

2 Review: Classification of Equations
Linear: independent variable appears to the first power only, either alone or multiplied by a constant Nonlinear: Polynomial: independent variable appears raised to powers of positive integers only General non-linear: all other equations Engineering Computation: An Introduction Using MATLAB and Excel

3 Review: Solution Methods
Linear: Easily solved analytically Polynomials: Some can be solved analytically (such as by quadratic formula), but most will require numerical solution General non-linear: unless very simple, will require numerical solution Engineering Computation: An Introduction Using MATLAB and Excel

4 Review: The Bisection Method
In the bisection method, we start with an interval (initial low and high guesses) and halve its width until the interval is sufficiently small As long as the initial guesses are such that the function has opposite signs at the two ends of the interval, this method will converge to a solution Engineering Computation: An Introduction Using MATLAB and Excel

5 Newton’s Method Newton’s Method (also know as the Newton-Rapshon Method) is another widely-used algorithm for finding roots of equations In this method, the slope (derivative) of the function is calculated at the initial guess value and projected to the x-axis The corresponding x-value becomes the new guess value The steps are repeated until the answer is obtained to a specified tolerance Engineering Computation: An Introduction Using MATLAB and Excel

6 Newton’s Method y(xi) Tangent Line: Slope = y’(xi) Initial guess xi
Engineering Computation: An Introduction Using MATLAB and Excel

7 Newton’s Method New guess for x: xn = xi - y(xi)/y’(xi) y(xi) xi
Engineering Computation: An Introduction Using MATLAB and Excel

8 Newton’s Method Example
Find a root of this equation: The first derivative is: Initial guess value: x = 10 Engineering Computation: An Introduction Using MATLAB and Excel

9 Newton’s Method Example
For x = 10: This is the new value of x Engineering Computation: An Introduction Using MATLAB and Excel

10 Newton’s Method Example
y = 1350 y’ = 580 New x-value = Initial guess = 10 Engineering Computation: An Introduction Using MATLAB and Excel

11 Newton’s Method Example
For x = : Engineering Computation: An Introduction Using MATLAB and Excel

12 Newton’s Method Example
y = y’ = Initial value = New x-value = Engineering Computation: An Introduction Using MATLAB and Excel

13 Newton’s Method Example
Continue iterations: Method quickly converges to this root Engineering Computation: An Introduction Using MATLAB and Excel

14 Newton’s Method Example
To find the other roots, use different initial guess values Engineering Computation: An Introduction Using MATLAB and Excel

15 Newton’s Method Example
Three roots found: x = x = x = Engineering Computation: An Introduction Using MATLAB and Excel

16 Newton’s Method - Comments
Usually converges to a root much faster than the bisection method In some cases, the method will not converge (discontinuous derivative, initial slope = 0, etc.) In most cases, however, if the initial guess is relatively close to the actual root, the method will converge Don’t necessarily need to calculate the derivative: can approximate the slope from two points close to the x-value. This is called the Secant Method Engineering Computation: An Introduction Using MATLAB and Excel

17 In-Class Exercise Draw a flow chart of Newton’s Method
Write the MATLAB code to apply Newton’s Method to the previous example: Engineering Computation: An Introduction Using MATLAB and Excel

18 Define converge tolerance tol
Input initial guess x Calculate f(x) while abs(f(x)) > tol Calculate slope fpr(x) x = x – f(x)/fpr(x) Calculate f(x) Output root x Engineering Computation: An Introduction Using MATLAB and Excel

19 MATLAB Code MATLAB functions defining the function and its derivative:
Engineering Computation: An Introduction Using MATLAB and Excel

20 MATLAB Code Engineering Computation: An Introduction Using MATLAB and Excel

21 MATLAB Results >> Newton Enter initial guess 10 Root found: Root found: Root found: Engineering Computation: An Introduction Using MATLAB and Excel

22 Excel and MATLAB Tools Bisection method or Newton’s method can be easily programmed However, Excel and MATLAB have built-in tools for finding roots of equations Engineering Computation: An Introduction Using MATLAB and Excel

23 Excel and MATLAB Tools General non-linear equations: Excel: Goal Seek, Solver MATLAB: fzero Polynomials: MATLAB: roots Graphing tools are also important to locate roots approximately Engineering Computation: An Introduction Using MATLAB and Excel

24 Excel Tools We have seen how to use Solver for a system of equations; we can easily apply it to find roots of a single equation There is a tool in Excel even easier to use for a single equation: Goal Seek With Goal Seek, we instruct Excel to change the value of a cell containing the independent variable to cause the value of the cell containing the function to equal a given value Engineering Computation: An Introduction Using MATLAB and Excel

25 Goal Seek Example Engineering Computation: An Introduction Using MATLAB and Excel

26 Goal Seek Example Engineering Computation: An Introduction Using MATLAB and Excel

27 fzero Example The MATLAB function fzero finds the root of a function, starting with a guess value Example: function fun1 defines this equation: Engineering Computation: An Introduction Using MATLAB and Excel

28 fzero Example The function fzero has arguments of the name of the function to be evaluated and a guess value: >> fzero('fun1',10) ans = 5.6577 Or the name of function to be evaluated and a range of values to be considered: >> fzero('fun1',[4 10]) Engineering Computation: An Introduction Using MATLAB and Excel

29 fzero Example If a range is specified, then the function must have opposite signs at the endpoints > fzero('fun1',[0 10]) ??? Error using ==> fzero at 292 The function values at the interval endpoints must differ in sign. Engineering Computation: An Introduction Using MATLAB and Excel

30 Graphing to Help Find Roots
Making a graph of the function is helpful to determine how many real roots exist, and the approximate locations of the roots Example: Consider these two equations: How many roots does each have? Engineering Computation: An Introduction Using MATLAB and Excel

31 Graphing to Help Find Roots
Equation 1: Equation 2: 3 real roots 1 real root Engineering Computation: An Introduction Using MATLAB and Excel

32 roots Example For polynomials, the MATLAB function roots finds all of the roots, including complex roots The argument of roots is an array containing the coefficients of the equation For example, for the equation the coefficient array is [3, -15, -20, 50] Engineering Computation: An Introduction Using MATLAB and Excel

33 roots Example >> A = [3, -15, -20, 50]; >> roots(A) ans = Engineering Computation: An Introduction Using MATLAB and Excel

34 roots Example Now find roots of Two complex roots
>> B = [3, -5, -20, 50]; >> roots(B) ans = i i Two complex roots Engineering Computation: An Introduction Using MATLAB and Excel

35 Summary The bisection method and Newton’s method (or secant method) are widely-used algorithms for finding the roots of equations When using any tool to find the roots of non-linear equations, remember that multiple roots may exist The initial guess value will affect which root is found Engineering Computation: An Introduction Using MATLAB and Excel


Download ppt "Newton’s Method, Root Finding with MATLAB and Excel"

Similar presentations


Ads by Google