Numerical Methods 5633

Similar documents
Numerical Methods 5633

Chapter 3: Root Finding. September 26, 2005

Math Numerical Analysis

Solution of Algebric & Transcendental Equations

Outline. Math Numerical Analysis. Intermediate Value Theorem. Lecture Notes Zeros and Roots. Joseph M. Mahaffy,

Scientific Computing: An Introductory Survey

Numerical Solution of f(x) = 0

Queens College, CUNY, Department of Computer Science Numerical Methods CSCI 361 / 761 Spring 2018 Instructor: Dr. Sateesh Mane.

Lecture Notes to Accompany. Scientific Computing An Introductory Survey. by Michael T. Heath. Chapter 5. Nonlinear Equations

Outline. Scientific Computing: An Introductory Survey. Nonlinear Equations. Nonlinear Equations. Examples: Nonlinear Equations

Solving Non-Linear Equations (Root Finding)

CLASS NOTES Models, Algorithms and Data: Introduction to computing 2018

Figure 1: Graph of y = x cos(x)

Numerical Methods. Root Finding

5 Finding roots of equations

PART I Lecture Notes on Numerical Solution of Root Finding Problems MATH 435

THE SECANT METHOD. q(x) = a 0 + a 1 x. with

Numerical Methods Lecture 3

Numerical Methods in Informatics

Finding the Roots of f(x) = 0. Gerald W. Recktenwald Department of Mechanical Engineering Portland State University

Finding the Roots of f(x) = 0

Lecture 7. Root finding I. 1 Introduction. 2 Graphical solution

Midterm Review. Igor Yanovsky (Math 151A TA)

ROOT FINDING REVIEW MICHELLE FENG

Root Finding: Close Methods. Bisection and False Position Dr. Marco A. Arocha Aug, 2014

Solving Nonlinear Equations

Root Finding Convergence Analysis

MATH 3795 Lecture 12. Numerical Solution of Nonlinear Equations.

CS 450 Numerical Analysis. Chapter 5: Nonlinear Equations

Computational Methods CMSC/AMSC/MAPL 460. Solving nonlinear equations and zero finding. Finding zeroes of functions

3.1 Introduction. Solve non-linear real equation f(x) = 0 for real root or zero x. E.g. x x 1.5 =0, tan x x =0.

Math 471. Numerical methods Root-finding algorithms for nonlinear equations

Introductory Numerical Analysis

Solution of Nonlinear Equations

Solving nonlinear equations

Notes for Numerical Analysis Math 5465 by S. Adjerid Virginia Polytechnic Institute and State University. (A Rough Draft)

Goals for This Lecture:

CHAPTER-II ROOTS OF EQUATIONS

R x n. 2 R We simplify this algebraically, obtaining 2x n x n 1 x n x n

MATH 3795 Lecture 13. Numerical Solution of Nonlinear Equations in R N.

1.1: The bisection method. September 2017

Root Finding (and Optimisation)

1. Method 1: bisection. The bisection methods starts from two points a 0 and b 0 such that

MA 8019: Numerical Analysis I Solution of Nonlinear Equations

INTRODUCTION TO NUMERICAL ANALYSIS

Bisection and False Position Dr. Marco A. Arocha Aug, 2014

Nonlinear Equations. Chapter The Bisection Method

MAE 107 Homework 7 Solutions

Motivation: We have already seen an example of a system of nonlinear equations when we studied Gaussian integration (p.8 of integration notes)

Extended Introduction to Computer Science CS1001.py. Lecture 8 part A: Finding Zeroes of Real Functions: Newton Raphson Iteration

At the end, f(m) 0. We can see how this works with a plot using the objective function f(x) = 1/2 e x2 :

SOLUTION OF ALGEBRAIC AND TRANSCENDENTAL EQUATIONS BISECTION METHOD

Chapter 1. Root Finding Methods. 1.1 Bisection method

Solutions of Equations in One Variable. Newton s Method

Math 551 Homework Assignment 3 Page 1 of 6

Numerical Study of Some Iterative Methods for Solving Nonlinear Equations

Lecture 11: Probability, Order Statistics and Sampling

Outline. Additional Nonlinear Systems. Abstract. Finding Equilibrium Points Numerically. Newton s Method

Math Introduction to Numerical Methods - Winter 2011 Homework 2 Assigned: Friday, January 14, Due: Thursday, January 27,

STOP, a i+ 1 is the desired root. )f(a i) > 0. Else If f(a i+ 1. Set a i+1 = a i+ 1 and b i+1 = b Else Set a i+1 = a i and b i+1 = a i+ 1

Unit 2: Solving Scalar Equations. Notes prepared by: Amos Ron, Yunpeng Li, Mark Cowlishaw, Steve Wright Instructor: Steve Wright

Math Numerical Analysis Mid-Term Test Solutions

1-D Optimization. Lab 16. Overview of Line Search Algorithms. Derivative versus Derivative-Free Methods

Root finding. Eugeniy E. Mikhailov. Lecture 06. The College of William & Mary. Eugeniy Mikhailov (W&M) Practical Computing Lecture 06 1 / 10

Halley s Method: A Cubically Converging. Method of Root Approximation

PARALLEL NUMERICAL METHODS FOR SOLVING NONLINEAR EQUATIONS

Numerical Methods Dr. Sanjeev Kumar Department of Mathematics Indian Institute of Technology Roorkee Lecture No 7 Regula Falsi and Secant Methods

Non-linear Equations. Chapter Particle in a Box Potential. h2 d 2 u. dx 2. 0 x>a. d 2 u(x) + 2m h 2 (V 0+ E)u(x)=0 x<a, (4.

Numerical Analysis Fall. Roots: Open Methods

Lecture 8. Root finding II

Today s class. Numerical differentiation Roots of equation Bracketing methods. Numerical Methods, Fall 2011 Lecture 4. Prof. Jinbo Bi CSE, UConn

If you need the source code from the sample solutions, copy and paste from the PDF should work. If you re having trouble, send me an .

Root finding. Eugeniy E. Mikhailov. Lecture 05. The College of William & Mary. Eugeniy Mikhailov (W&M) Practical Computing Lecture 05 1 / 10

Chapter 5: Numerical Integration and Differentiation

Chapter 2 Solutions of Equations of One Variable

15 Nonlinear Equations and Zero-Finders

Determining the Roots of Non-Linear Equations Part I

SOLVING EQUATIONS OF ONE VARIABLE

Lecture 14 Ellipsoid method

Line Search Methods. Shefali Kulkarni-Thaker

Variable. Peter W. White Fall 2018 / Numerical Analysis. Department of Mathematics Tarleton State University

PHYS 410/555 Computational Physics Solution of Non Linear Equations (a.k.a. Root Finding) (Reference Numerical Recipes, 9.0, 9.1, 9.

Tangent Lines and Derivatives

Optimization and Calculus

MATH 2053 Calculus I Review for the Final Exam

Lecture 7: Numerical Tools

1. Nonlinear Equations. This lecture note excerpted parts from Michael Heath and Max Gunzburger. f(x) = 0

X. Numerical Methods

COMPUTING AND DATA ANALYSIS WITH EXCEL. Numerical Methods of Solving Equations

Iterative Methods to Solve Systems of Nonlinear Algebraic Equations

Scientific Computing. Roots of Equations

CLASS NOTES Computational Methods for Engineering Applications I Spring 2015

MATH 2400: PRACTICE PROBLEMS FOR EXAM 1

Math 4329: Numerical Analysis Chapter 03: Newton s Method. Natasha S. Sharma, PhD

MTH603 FAQ + Short Questions Answers.

dy = f( x) dx = F ( x)+c = f ( x) dy = f( x) dx

Mean Value Theorem. MATH 161 Calculus I. J. Robert Buchanan. Summer Department of Mathematics

CS 323: Numerical Analysis and Computing

Root finding. Root finding problem. Root finding problem. Root finding problem. Notes. Eugeniy E. Mikhailov. Lecture 05. Notes

CS 323: Numerical Analysis and Computing

Transcription:

Numerical Methods 5633 Lecture 4 Michaelmas Term 2017 Marina Krstic Marinkovic mmarina@maths.tcd.ie School of Mathematics Trinity College Dublin Marina Krstic Marinkovic 1 / 17 5633-Numerical Methods

Root Finding Finding an argument of a function f(x) that makes y=f(x) zero We seek the value α, such that f(α)=0 α - zero of the function f(x) α - root of the equation f(x)=0 f(x) may be a scalar, or a vector-valued function of a vector-valued variable -> solving system of equations - Bisection Method - Newton s method - Secant Method Marina Krstic Marinkovic 2 / 17 5633-Numerical Methods

Bisection Method 1. Given an initial interval [a0,b0]=[a,b], set k=0 2. Compute ck+1=ak+(bk-ak)/2 3. If f(ck+1)f(ak)<0 then set ak+1=ak, bk+1=ck+1 4. If f(ck+1)f(bk)<0 then set ak+1=ck+1, bk+1=bk 5. Update k and go to Step 2. Each step is decreasing an upper bound on the absolute error by a factor of 2 Programming hint: For numerical stability, we want to replace (a+b)/2 with a+(b-a)/2. This is because large values of a,b may lead to the computational overflow in (a+b)/2. Marina Krstic Marinkovic 3 / 17 5633-Numerical Methods

Bisection Convergence and Error Theorem Let [a0,b0]=[a,b] be the initial interval, with f(a)f(b)<0. If we define an approximate root as Xn=cn=(an-1 + bn-1)/2, then there exists a root α [a,b] s.t. Moreover, to achieve accuracy of it suffices to take x n apple 1 (b a) 2n x n apple n log(b a) log log 2 Marina Krstic Marinkovic 4 / 17 5633-Numerical Methods

Bisection Method for root-finding # Bisection method for root-finding # f - user defined function # a - start of an interval # b - end of an interval # nmax - maximal number of steps in the bisection method (divisions of the interval [a,b]) # eps - required precision for the root BisectionMethod <- function(f, a, b, eps, nmax) { fa <- f(a) # check if a or b are the root of f(x) if (fa == 0.0) { return(a) fb <- f(b) if (fb == 0.0) { return(b) k=1 # iteration nr. counter while ((abs(a-b)>eps)&&(k<nmax)) { x0 <- a+(b-a)/2 # finding midpoint of the interval if ((f(a) * f(x0)) < 0) b<-x0 else a<-x0 k<-k+1 if (k<nmax) { print('the found root on the interval [a,b] is:') return(x0) else print('maximal number of iterations reached and solution not yet found.') Marina Krstic Marinkovic 5 / 17 5633-Numerical Methods

Bisection Method for root-finding f<-function(x) { x**3-2 a<-1 b<-2 eps<-1e-10 n<-1000 source( BisectionMethod.R ) NewtonMethod(f,a,b,eps,n) Marina Krstic Marinkovic 6 / 17 5633-Numerical Methods

Bisection Method Globally convergent method: it always converges no matter how far from the actual root we start, assuming that the root is bracketed (f(a)f(b)<0) Disadvantages: - cannot be used when the function is tangent to the axis and does not pass through the axis (e.g. f(x)=x 2 ) - converges slowly compared to other methods How many iterations is needed in bisection method in order to decrease the initial error by a factor of ~1000? Marina Krstic Marinkovic 7 / 17 5633-Numerical Methods

Newton s Method Historically - first used by Newton in 1669 Babylonians also had a method for approximating sqrt(x) Assume we want to find a root of y=f(x) given an initial guess x0 Newton s method uses tangent line approximation to f at (x0,f(x0)) Marina Krstic Marinkovic 8 / 17 5633-Numerical Methods

Newton s Method Tangent line approximation to f at (x0,f(x0)) y y 0 x x0 = f 0 (x 0 ) Finding where this tangent line crosses the x-axis (y=0) x = x 0 f(x 0 ) f 0 (x 0 ) x 1 Continue the process with another tangent line through f(x1) x 2 = x 1 f(x 1 ) f 0 (x 1 ) And so on - until the new tangent line through f(xn) x n+1 = x n f(x n ) f 0 (x n ) Marina Krstic Marinkovic 9 / 17 5633-Numerical Methods

Newton s Method Example: f(x)=2-e x, choosing x0=0 x 1 = x 0 2 e x 0 e x 0 x 2 = x 1 2 e x 1 e x 1 x 3 = x 2 2 e x 2 e x 2 = 2 1 1 =1 =1 2 e e =0.7357588823 =0.6940422999 The convergence is much more rapid then the for the bisection n xn α-xn log10(α-xn) 0 0.0000000 0.6931472-0.1591 1 1.000000 0.3068528-0.5131 2 0.7357589 0.0426117-1.3705 3 0.6940423 0.0008951-3.0481 4 0.6931476 0.0000004-6.3974 5 0.6931472 0.0000000-13.0553 Marina Krstic Marinkovic 10 / 17 5633-Numerical Methods

Convergence of Newton s Method Study other examples: f(x)=4/3e 2-x/2 (1+x -1 log(x)), Application of Newton s method will be problematic unless the initial guess x0 is chosen very carefully. What happens in case x0 [0.8,1.2]? How about f(x)=arctan(x) - try to apply Newton s method here, with initial guess x0=1.39174520027 If f, f anf f are continuous near the root, and if f does not equal 0 at the root, then Newton s method will converge whenever the initial guess is sufficiently close to the root. This convergence will be very rapid (see example on previous page) > number of correct digits doubling in every iteration Marina Krstic Marinkovic 11 / 17 5633-Numerical Methods

Newton s Method Locally convergent method: we have to start the iteration with a good enough approximation to the root, otherwise the method will not converge Stopping criterium for the Newton s method: 5 x n+1 x n apple Warning! If f (xn) is very large compared to f(xn), it is possible to have xn+1 -xn small and yet not have xn+1 very close to α - common to add a term to the error check: f(x n ) + x n x n 1 apple /5 Disadvantages: - requires a formula for the derivative of f(x)! Marina Krstic Marinkovic 12 / 17 5633-Numerical Methods

Newton s Method for root-finding # Note: other implementation of num. derivative is possible (e.g. backward, symmetric or some predefined function in R could be used) # f - user defined function # a - start of an interval # b - end of an interval # h - step used in the numerical integration # eps - required precision for the root # n - maximal number of iterations NumDerivative <- function (f, x0,dx) { (f(x0+dx)-f(x0))/dx NewtonMethod <- function(f, a, b, eps, n) { x0 <- a fa <- f(a) if (fa == 0.0) { return(a) fb <- f(b) if (fb == 0.0) { return(b) for (k in 1:n) { fprime= NumDerivative(f, x0, dx) x1 = x0 - (f(x0) / fprime) if (abs(x1 - x0) < eps) { print('the found root on the interval [a,b] is:') return(x1) x0 = x1 # computing numerical derivative of a function f # setting start value to the interval lower bound # check if a or b are the root of f(x) # f'(x0) # calculate next value x1 # check if required precision reached print('maximal number of iterations reached and solution not yet found.') #continue Newton's method until convergence or max #iter. reached Marina Krstic Marinkovic 13 / 17 5633-Numerical Methods

Newton s Method for root-finding f<-function(x) { x**3-2 a<-1 b<-2 dx<-1e-7 eps<-1e-10 n<-1000 source( NewtonMethod.R ) NewtonMethod(f,a,b,eps,n) Marina Krstic Marinkovic 14 / 17 5633-Numerical Methods

Secant Method Disadvantage of the Newton s Method: - requires a formula for the derivative of f(x)! Approximate the derivative with secant line two points in the curve needed (instead of just one for the tangent) Assume two initial guesses are given: x0,x1; f(x0)=f0 f(x1)=f1 Marina Krstic Marinkovic 15 / 17 5633-Numerical Methods

Secant Method Assume two initial guesses are given: x0,x1 The secant line Setting y=0 and solving for x=x2: Or, generally: y f(x 1 ) x x 1 = f(x 1) f(x 0 ) x 1 x 0 x 2 = x 1 f(x 1 ) x n+1 = x n f(x n ) x 1 x 0 f(x 1 ) f(x 0 ) x n x n 1 f(x n ) f(x n 1 ) Consistent with Newton s method, with approximation: f 0 (x n ) f(x n) f(x n 1 ) x n x n 1 Marina Krstic Marinkovic 16 / 17 5633-Numerical Methods

Secant Method 1. Given two initial guesses x0,x1, and f(x0)=f0 f(x1)=f1 set k=1 2. Compute Xk+1=x1-f1*(x1-x0)/(f1-f0) 3. Compute f(xk+1); Assign: x0=x1, x1=xk+1; f0=f1=f(x0),f1=f(xk+1) 4. If x1-x0 <tol then set root=x1, exit the loop. Less costly than the Newton s method (one function call per iteration) Similar convergence propreties as Newton s method Error formula for secant method: x n+1 = 1 2 ( x n)( x n 1 ) f 00 ( n ) f 00 ( n ) min{,x n,x n 1 apple n, n apple max{,x n,x n 1 Therefore: x n+1 = C x n x n 1, for x n,x n+1,x n 1 Programming hint: avoid unnecessary function calls in your code! Marina Krstic Marinkovic 17 / 17 5633-Numerical Methods