Newton’s Method, Root Finding with MATLAB and Excel

Slides:



Advertisements
Similar presentations
Part 2 Chapter 6 Roots: Open Methods
Advertisements

Numerical Computation Lecture 4: Root Finding Methods - II United International College.
Chapter 6: Roots: Open Methods
Fixed point iterations and solution of non-linear functions
Part 2 Chapter 6 Roots: Open Methods
Polynomial Approximation PSCI 702 October 05, 2005.
CSE 330: Numerical Methods
Computer Programming (TKK-2144) 13/14 Semester 1 Instructor: Rama Oktavian Office Hr.: M.13-15, W Th , F
Newton’s Method finds Zeros Efficiently finds Zeros of an equation: –Solves f(x)=0 Why do we care?
Roots: Bracketing Methods
Open Methods Chapter 6 The Islamic University of Gaza
ROOTS OF EQUATIONS Student Notes ENGR 351 Numerical Methods for Engineers Southern Illinois University Carbondale College of Engineering Dr. L.R. Chevalier.
Chapter 1 Computing Tools Data Representation, Accuracy and Precision Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction.
Copyright © 2006 The McGraw-Hill Companies, Inc. Permission required for reproduction or display. by Lale Yurttas, Texas A&M University Chapter 61.
Open Methods Chapter 6 The Islamic University of Gaza
Open Methods.
Chapter 4 Roots of Equations
PHYS2020 NUMERICAL ALGORITHM NOTES ROOTS OF EQUATIONS.
Copyright © 2006 The McGraw-Hill Companies, Inc. Permission required for reproduction or display. by Lale Yurttas, Texas A&M University Chapter 51.
CSCE Finding Roots of Equations This is a fundamental computational problem Several methods exist. We will look at the bisection method and at Newton’s.
Chapter 6 Open Methods.
Copyright © 2006 The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Martin Mendez UASLP Chapter 61 Unit II.
Lecture 1: Numerical Solution of Non-linear equations.
Open Methods Chapter 6 The Islamic University of Gaza
NUMERICAL METHODS WITH C++ PROGRAMMING
Linear Simultaneous Equations
Fin500J: Mathematical Foundations in Finance Topic 3: Numerical Methods for Solving Non-linear Equations Philip H. Dybvig Reference: Numerical Methods.
Differential Equations
Matrix Mathematics in MATLAB and Excel
Non-Linear Simultaneous Equations
Roots of Equations Chapter 3. Roots of Equations Also called “zeroes” of the equation –A value x such that f(x) = 0 Extremely important in applications.
Copyright © 2006 The McGraw-Hill Companies, Inc. Permission required for reproduction or display. by Lale Yurttas, Texas A&M University Chapter 31.
Solving Non-Linear Equations (Root Finding)
Copyright © 2006 The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 1 Part 2 Roots of Equations Why? But.
Chapter 9 Numerical Integration Flow Charts, Loop Structures Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
Chapter 6 Finding the Roots of Equations
Numerical Methods Applications of Loops: The power of MATLAB Mathematics + Coding 1.
Loop Application: Numerical Methods, Part 1 The power of Matlab Mathematics + Coding.
Part 2 Chapter 5 Roots: Bracketing Methods PowerPoints organized by Dr. Michael R. Gustafson II, Duke University All images copyright © The McGraw-Hill.
Lecture 3 Numerical Analysis. Solution of Non-Linear Equations Chapter 2.
Copyright © 2006 The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 1 ~ Roots of Equations ~ Open Methods Chapter 6 Credit:
Lecture 6 Numerical Analysis. Solution of Non-Linear Equations Chapter 2.
Chapter 3 Roots of Equations. Objectives Understanding what roots problems are and where they occur in engineering and science Knowing how to determine.
4.5: Linear Approximations, Differentials and Newton’s Method.
Numerical Methods for Engineering MECN 3500
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 1 Part 6 - Chapter 24 Boundary Value Problems.
Quadrature rules 1Michael Sokolov / Numerical Methods for Chemical Engineers / Numerical Quadrature Michael Sokolov ETH Zurich, Institut für Chemie- und.
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 1 Chapter 3.
Applied Numerical Methods
Lecture 5 - Single Variable Problems CVEN 302 June 12, 2002.
Solving Non-Linear Equations (Root Finding)
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 1 Chapter 27.
SOLVING NONLINEAR EQUATIONS. SECANT METHOD MATH-415 Numerical Analysis 1.
Root Finding UC Berkeley Fall 2004, E77 Copyright 2005, Andy Packard. This work is licensed under the Creative.
Chapter 2 Excel Fundamentals Logical IF (Decision) Statements Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
The formulae for the roots of a 3rd degree polynomial are given below
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 1 Part 6 - Chapters 22 and 23.
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 1 Part 2 - Chapter 7 Optimization.
CSE 330: Numerical Methods. What is true error? True error is the difference between the true value (also called the exact value) and the approximate.
MATH342: Numerical Analysis Sunjae Kim.
CSE 330: Numerical Methods. Introduction The bisection and false position method require bracketing of the root by two guesses Such methods are called.
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 1 Part 2 / Chapter 5.
Numerical Methods and Analysis
Part 2 Chapter 6 Roots: Open Methods
SOLUTION OF NONLINEAR EQUATIONS
Copyright © Cengage Learning. All rights reserved.
Part 2 Chapter 6 Roots: Open Methods
MATH 1910 Chapter 3 Section 8 Newton’s Method.
1 Newton’s Method.
Presentation transcript:

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.

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

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

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

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

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

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

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

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

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

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

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

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

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

Newton’s Method Example Three roots found: x = -2.0764 x = 1.4187 x = 5.6577 Engineering Computation: An Introduction Using MATLAB and Excel

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

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

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

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

MATLAB Code Engineering Computation: An Introduction Using MATLAB and Excel

MATLAB Results >> Newton Enter initial guess 10 Root found: 5.6577 0 Root found: 1.4187 -10 Root found: -2.0764 Engineering Computation: An Introduction Using MATLAB and Excel

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

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

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

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

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

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

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

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

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

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

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

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

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

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