Comp 208 Computers in Engineering Yi Lin Winter, 2007

Slides:



Advertisements
Similar presentations
Copyright © Cengage Learning. All rights reserved.
Advertisements

Part 2 Chapter 6 Roots: Open Methods
Chapter 6: Roots: Open Methods
Lecture 5 Newton-Raphson Method
Part 2 Chapter 6 Roots: Open Methods
Line Search.
CSE 330: Numerical 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.
Copyright © 2006 The McGraw-Hill Companies, Inc. Permission required for reproduction or display. by Lale Yurttas, Texas A&M University Chapter 51.
Second Term 05/061 Roots of Equations Bracketing Methods.
ECIV 301 Programming & Graphics Numerical Methods for Engineers Lecture 6 Roots of Equations Bracketing Methods.
Roots of Equations Bracketing Methods.
ECIV 301 Programming & Graphics Numerical Methods for Engineers Lecture 9 Roots of Equations Open Methods.
Open Methods Chapter 6 The Islamic University of Gaza
ECIV 301 Programming & Graphics Numerical Methods for Engineers Lecture 8 Roots of Equations Open Methods.
Fin500J: Mathematical Foundations in Finance Topic 3: Numerical Methods for Solving Non-linear Equations Philip H. Dybvig Reference: Numerical Methods.
Secant Method Another Recursive Method. Secant Method The secant method is a recursive method used to find the solution to an equation like Newton’s Method.
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.
Lecture Notes Dr. Rakhmad Arief Siregar Universiti Malaysia Perlis
1 EEE 431 Computational Methods in Electrodynamics Lecture 4 By Dr. Rasime Uyguroglu
Chapter 3 Roots of Equations. Objectives Understanding what roots problems are and where they occur in engineering and science Knowing how to determine.
Numerical Methods for Engineering MECN 3500
Numerical Methods.
Newton’s Method, Root Finding with MATLAB and Excel
Today’s class Roots of equation Finish up incremental search
MECN 3500 Inter - Bayamon Lecture 6 Numerical Methods for Engineering MECN 3500 Professor: Dr. Omar E. Meza Castillo
4 Numerical Methods Root Finding Secant Method Modified Secant
Lecture 5 - Single Variable Problems CVEN 302 June 12, 2002.
The Islamic University of Gaza Faculty of Engineering Civil Engineering Department Numerical Analysis ECIV 3306 Chapter 7 Roots of Polynomials.
Numerical Methods Solution of Equation.
4 Numerical Methods Root Finding Secant Method Modified Secant
Linearization, Newton’s Method
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.
6/13/ Secant Method Computer Engineering Majors Authors: Autar Kaw, Jai Paul
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.
Chapter 5 Numerical Root Findings
Numerical Methods Some example applications in C++
4 Numerical Methods Root Finding Secant Method Modified Secant
Approximate computations
Numerical Analysis Lecture 5.
MTH1150 Tangents and Their Slopes
Numerical Methods and Analysis
Secant Method.
4.5: Linear Approximations, Differentials and Newton’s Method
LECTURE 3 OF SOLUTIONS OF NON -LINEAR EQUATIONS.
Advanced Numerical Methods (S. A. Sahu) Code: AMC 51151
Approximate computations
Computational Methods EML3041
Read Chapters 5 and 6 of the textbook
Part 2 Chapter 6 Roots: Open Methods
Secant Method – Derivation
Chapter 6.
Numerical Analysis Lecture 7.
Numerical Analysis Lecture 45.
Computers in Civil Engineering 53:081 Spring 2003
The Discriminant   Determine the number of real solutions for a quadratic equation including using the discriminant and its graph.
ROOTS OF EQUATIONS.
Some Comments on Root finding
6-8 Roots and Zeros Given a polynomial function f(x), the following are all equivalent: c is a zero of the polynomial function f(x). x – c is a factor.
Chapter 6.
Copyright © Cengage Learning. All rights reserved.
Part 2 Chapter 6 Roots: Open Methods
MATH 1910 Chapter 3 Section 8 Newton’s Method.
5.6 Complex Zeros; Fundamental Theorem of Algebra
Solutions for Nonlinear Equations
Presentation transcript:

Comp 208 Computers in Engineering Yi Lin Winter, 2007 01/06/2019 Lecture 20 Root finding Comp 208 Computers in Engineering Yi Lin Winter, 2007 6/1/201911/15/05 Comp208 Computers in Engineering

Comp208 Computers in Engineering 01/06/2019 01/06/2019 Lecture 19 Root finding Objectives Learn about 4 numerical methods Bisection Secant False position Newton Raphson Learn new features of C Pointer to function, pass as an argument to a function typedef Learn enough in-depth C to implement these 6/1/201911/15/05 Comp208 Computers in Engineering 2

Comp208 Computers in Engineering 01/06/2019 01/06/2019 Intro to Root Finding A way to solve equations in one unknown that cannot be solved symbolically. For example, suppose that we would like to solve the simple equation: x2 = 5 To solve this equation using the bisection method, we first manipulate it algebraically so that one side is zero. x2 - 5 = 0 Finding a solution to this equation is then equivalent to finding a root of the function f(x) = x2 - 5 6/1/201911/15/05 Comp208 Computers in Engineering 3

Comp208 Computers in Engineering 01/06/2019 Bisection (con’t) We next find two numbers, a positive guess and a negative guess, so that f(positive guess) > 0 and f(negative guess) <0. So long as the function whose root we are finding is continuous, there must be at least one root between the positive and negative guesses. The bisection method locates such a root by repeatedly narrowing the distance between the two guesses. middle = (positive guess + negative guess)/2 6/1/201911/15/05 Comp208 Computers in Engineering

Comp208 Computers in Engineering 01/06/2019 Bisection example X2 f(x2) X3=(x1+x2)/2 f(x3) X4=(x3+x1)/2 f(x4) X5=(x4+x1)/2 f(x5)≈0 X1 f(x1) 6/1/201911/15/05 Comp208 Computers in Engineering

Non-recursive implementation double bisection_rf(DfD f, double x0, double x1, double tol){ double middle = (x0 + x1) / 2.0; while(fabs(f(middle)) > tol) { if(f(middle) * f(x0) < 0) x1 = middle; else if ( f(middle) * f(x1) < 0 ) x0 = middle; else printf("Should not be here! f(x0) and f(x1) are the same sign!\n"); middle = (x0 + x1) / 2.0; } return middle; 6/1/201911/15/05 Comp208 Computers in Engineering

Bisection-recursive implementation 01/06/2019 Bisection-recursive implementation double bisection_rf(DfD f, double x0, double x1, double tol) { double middle = (x0 + x1) / 2.0; if((middle - x0) < tol) return middle; else if(f(middle) * f(x0) < 0.0) // From the Intermediate Value Theorem, if there is a sign change then there is a root. return bisection_rf(f, x0, middle, tol); else return bisection_rf(f, middle, x1, tol); } 6/1/201911/15/05 Comp208 Computers in Engineering

Bisection complete program 01/06/2019 Bisection complete program #include <stdio.h> #include <math.h> typedef double (*DfD) (double); double bisection_rf(DfD f, double x0, double x1, double tol) { double middle = (x0 + x1) / 2.0; if(fabs(f(middle)) < tol) return middle; else if(f(middle) * f(x0) < 0.0) // From the Intermediate Value Theorem, if there is a sign change then there is a root. return bisection_rf(f, x0, middle, tol); else return bisection_rf(f, middle, x1, tol); } double func(double x){ return x*x - 5; } int main(){ double root, tolerance; tolerance = 0.00001; root = bisection_rf(func, -4, 1, tolerance); printf("root=%lf\n", root); 6/1/201911/15/05 Comp208 Computers in Engineering

Bisection counter-example 01/06/2019 Bisection counter-example If f(x1) and f(x2) are both positive or both negative, unable to find the root! X1 f(x1) X3=(x1+x2)/2 f(x3) x2 f(x2) 6/1/201911/15/05 Comp208 Computers in Engineering

Comp208 Computers in Engineering 01/06/2019 Secant method X1 f(x1) x2 f(x2) f(x4) f(x5)≈0 f(x3) x3 6/1/201911/15/05 Comp208 Computers in Engineering

Comp208 Computers in Engineering 01/06/2019 Secant method Assume a function to be approximately linear in the region of interest. Each improvement is taken as the point where the approximating line crosses the axis. 6/1/201911/15/05 Comp208 Computers in Engineering

Comp208 Computers in Engineering Secant Non-recursive double secant(DfD f, double x1, double x2, double tol, double count){ double slope = (f(x1) - f(x2) )/(x1-x2); double x = x2 - f(x2)/slope; while(fabs(f(x)) > tol && count-->0){ x1 = x2; x2 = x; slope = (f(x1) - f(x2) )/(x1-x2); x = x2 - f(x2)/slope; } return x; 6/1/201911/15/05 Comp208 Computers in Engineering

Comp208 Computers in Engineering 01/06/2019 False position method The secant method retains only the most recent estimate, so the root does not necessarily remain bracketed. Combined with bisection in order to bracket the root. 6/1/201911/15/05 Comp208 Computers in Engineering

False position non-recursive double falseposition(DfD f, double x1, double x2, double tol){ double slope = (f(x1) - f(x2) )/(x1-x2); double x = x2 - f(x2)/slope; while(fabs(f(x)) > tol){ if(f(x) * f(x1) < 0) x2 = x; else x1 = x; slope = (f(x1) - f(x2) )/(x1-x2); x = x2 - f(x2)/slope; } return x; 6/1/201911/15/05 Comp208 Computers in Engineering

Comp208 Computers in Engineering 01/06/2019 Newton-Raphson Much like secant, but using the real derivative x1 f(x1) x4 f(x4)≈0 f(x2) x2 x3 f(x3) 6/1/201911/15/05 Comp208 Computers in Engineering

Comp208 Computers in Engineering 01/06/2019 Newton-Raphson double newton_raphson_rf(DfD f, double x0, double tol) { double h = 0.001; double derivative; do{ derivative = centered3_diff(f, x0, h); x0 = x0 - f(x0)/derivative; } while(fabs(f(x0)) > tol); return x0; } 6/1/201911/15/05 Comp208 Computers in Engineering

How to calculate derivative 01/06/2019 How to calculate derivative Forward 3 points differentiation Backward 3 points differentiation Centered 3 points differentiation 6/1/201911/15/05 Comp208 Computers in Engineering

Comp208 Computers in Engineering 01/06/2019 Forward 3 points Mathematical formula: double forward3_diff(double x, double h) { return (-3*f(x) + 4*f(x+h) - f(x+2*h)) / (2 * h); } 6/1/201911/15/05 Comp208 Computers in Engineering

Comp208 Computers in Engineering 01/06/2019 Backward 3 points Mathematical formula: double backward3_diff(double x, double h) { return (f(x - 2 * h) - 4 * f(x - h) + 3 * f(x)) / (2 * h); } 6/1/201911/15/05 Comp208 Computers in Engineering

Comp208 Computers in Engineering 01/06/2019 Centered 3 points Mathematical formula: double centered3_diff(double x, double h) { return (-f(x - h) + f(x + h)) / (2 * h); } 6/1/201911/15/05 Comp208 Computers in Engineering