Numerical Methods Lecture 3

Similar documents
1.1: The bisection method. September 2017

Chapter 3: Root Finding. September 26, 2005

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

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

Solving Non-Linear Equations (Root Finding)

MATH 3795 Lecture 12. Numerical Solution of Nonlinear Equations.

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

Solution of Algebric & Transcendental Equations

Numerical Methods. Roots of Equations

Goals for This Lecture:

Nonlinear Equations. Chapter The Bisection Method

Intro to Scientific Computing: How long does it take to find a needle in a haystack?

Numerical Methods. Root Finding

Math Numerical Analysis

NON-LINEAR ALGEBRAIC EQUATIONS Lec. 5.1: Nonlinear Equation in Single Variable

SOLUTION OF ALGEBRAIC AND TRANSCENDENTAL EQUATIONS BISECTION METHOD

INTRODUCTION TO NUMERICAL ANALYSIS

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.

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

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

Scientific Computing. Roots of Equations

NUMERICAL AND STATISTICAL COMPUTING (MCA-202-CR)

Numerical Analysis Fall. Roots: Open Methods

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

BEKG 2452 NUMERICAL METHODS Solution of Nonlinear Equations

CHAPTER 4 ROOTS OF EQUATIONS

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

Numerical mathematics with GeoGebra in high school

Zeroes of Transcendental and Polynomial Equations. Bisection method, Regula-falsi method and Newton-Raphson method

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

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

Solving nonlinear equations (See online notes and lecture notes for full details) 1.3: Newton s Method

CHAPTER-II ROOTS OF EQUATIONS

Hence a root lies between 1 and 2. Since f a is negative and f(x 0 ) is positive The root lies between a and x 0 i.e. 1 and 1.

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

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

Analysis Methods in Atmospheric and Oceanic Science

Numerical Solution of f(x) = 0

PARALLEL NUMERICAL METHODS FOR SOLVING NONLINEAR EQUATIONS

CHAPTER 10 Zeros of Functions

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

Zeros of Functions. Chapter 10

SOLVING EQUATIONS OF ONE VARIABLE

Nonlinearity Root-finding Bisection Fixed Point Iteration Newton s Method Secant Method Conclusion. Nonlinear Systems

Math 551 Homework Assignment 3 Page 1 of 6

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

Determining the Roots of Non-Linear Equations Part I

Lecture 8. Root finding II

Chapter 2 Solutions of Equations of One Variable

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

Finding the Roots of f(x) = 0

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

Lecture 5: Random numbers and Monte Carlo (Numerical Recipes, Chapter 7) Motivations for generating random numbers

Numerical Methods in Informatics

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

Zeros of functions with Matlab: Bisection method and fixed point iteration

Analysis Methods in Atmospheric and Oceanic Science

Numerical Analysis. EE, NCKU Tien-Hao Chang (Darby Chang)

Nonlinear Equations. Not guaranteed to have any real solutions, but generally do for astrophysical problems.

Root Finding (and Optimisation)

Student Study Session. Theorems

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

Finding Roots of Equations

CS 221 Lecture 9. Tuesday, 1 November 2011

Chapter 2 Linear Equations and Inequalities in One Variable

Solutions of Equations in One Variable. Newton s Method

Root Finding For NonLinear Equations Bisection Method

Instructor: Marios M. Fyrillas HOMEWORK ASSIGNMENT ON NUMERICAL SOLUTION OF NONLINEAR EQUATIONS

Introductory Numerical Analysis

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

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

Computational Methods. Solving Equations

CLASS NOTES Computational Methods for Engineering Applications I Spring 2015

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

15 Nonlinear Equations and Zero-Finders

Nonlinearity Root-finding Bisection Fixed Point Iteration Newton s Method Secant Method Conclusion. Nonlinear Systems

Scientific Computing. Roots of Equations

TWO METHODS FOR OF EQUATIONS

We saw in Section 5.1 that a limit of the form. arises when we compute an area.

MA 8019: Numerical Analysis I Solution of Nonlinear Equations

A Review of Bracketing Methods for Finding Zeros of Nonlinear Functions

x 2 x n r n J(x + t(x x ))(x x )dt. For warming-up we start with methods for solving a single equation of one variable.

Optimization and Calculus

Justify all your answers and write down all important steps. Unsupported answers will be disregarded.

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

SECTION A. f(x) = ln(x). Sketch the graph of y = f(x), indicating the coordinates of any points where the graph crosses the axes.

Solution of Nonlinear Equations

Lecture 10: Powers of Matrices, Difference Equations

Scientific Computing: An Introductory Survey

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

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

Lecture 10: Finite Differences for ODEs & Nonlinear Equations

Finding roots. Lecture 4

5.1 Increasing and Decreasing Functions. A function f is decreasing on an interval I if and only if: for all x 1, x 2 I, x 1 < x 2 = f(x 1 ) > f(x 2 )

Math 117: Calculus & Functions II

Investigating Limits in MATLAB

Applied Mathematics Letters. Combined bracketing methods for solving nonlinear equations

Chapter 4. Solution of a Single Nonlinear Algebraic Equation

Lecture 44. Better and successive approximations x2, x3,, xn to the root are obtained from

Solution of nonlinear equations

Transcription:

Numerical Methods Lecture 3 Nonlinear Equations by Pavel Ludvík

Introduction Definition (Root or zero of a function) A root (or a zero) of a function f is a solution of an equation f (x) = 0. We learn several root-finding methods: the bisection method, false position, the secant method, the Newton Raphson method. Numerical Methods Lecture 3 by Pavel Ludvík 2 / 24

Introduction Definition (Root or zero of a function) A root (or a zero) of a function f is a solution of an equation f (x) = 0. We learn several root-finding methods: the bisection method, false position, the secant method, the Newton Raphson method. Numerical Methods Lecture 3 by Pavel Ludvík 2 / 24

Introduction General Root-Finding Strategy 1. Bracket the roots, i.e. find the disjoint intervals containing the individual roots. 2. Set the initial approximation(s). 3. Repeat applying the iterative formula until the stopping criterion is met. Numerical Methods Lecture 3 by Pavel Ludvík 3 / 24

Introduction General Root-Finding Strategy 1. Bracket the roots, i.e. find the disjoint intervals containing the individual roots. 2. Set the initial approximation(s). 3. Repeat applying the iterative formula until the stopping criterion is met. Differences Between Methods the number of starting values, the guarantee, or otherwise, of convergence, the speed of convergence, the cost, in terms of the work to be done per iteration. Numerical Methods Lecture 3 by Pavel Ludvík 3 / 24

Bisection Method - Description The bisection method is the simplest of all the methods for finding a root of a nonlinear equation. We start with an interval containing a root and divide it into a left and a right half.we decide which of the two halves contains a root and proceed with a further division of that half. We do this repeatedly until the interval containing a root is sufficiently narrowed down to meet the level of accuracy required. If we take the mid-point of the latest interval to be an approximation to a root, we can say that this is accurate to within ± half the width of the interval. Numerical Methods Lecture 3 by Pavel Ludvík 4 / 24

Bisection Method - Algorithm Theorem Let f be a continuous function on an interval [a, b] and f (a)f (b) < 0. Then there exists a number c (a, b) that f (c) = 0. Algorithm for solving f (x) = 0 by Bisection Method 1. Find an interval [a, b] in which f (x) = 0. 2. Set x to a+b 2. 3. Test for convergence: Find out if b a 2 ε. 4. Calculate f (x ). 5. If f (x ) and f (b) have opposite sign set a to x, otherwise set b to x. 6. Repeat from step 2. Numerical Methods Lecture 3 by Pavel Ludvík 5 / 24

Example Find a root of the equation 8 4.5(x sin x) = 0 with a tolerance less than ε = 0.01. Solution 1. We define a function f (x) = 8 4.5(x sin x), plot its graph and find out the solution is between x = 2 and x = 3. Hence we choose a 0 = 2 and b 0 = 3. 2. We compute the midpoint c 0 = a 0+b 0 2 = 2.5 and the current error value Error 0 = b 0 a 0 2 = 0.5 which is bigger than the tolerance 0.01. 3. We have to carry out a next step. We need to answer the question: "Is the root in the interval [a 0, c 0 ] = [2, 2.5] or [c 0, b 0 ] = [2.5, 3]?"If f (2)f (2.5) < 0 then the root is in [2, 2.5], if f (2.5)f (3) < 0 then in [2.5, 3], if none of it is truth then necessarily 2.5 is a root itself. We compute that f (2)f (2.5) < 0 and hence we set a 1 = 2, b 1 = 2.5. Numerical Methods Lecture 3 by Pavel Ludvík 6 / 24

Solution 4. We repeat the algorithm until the error is smaller or equal to ε. 5. See the results in a table: n a n c n b n Error 0 2 2.5 3 0.5 > 0.01 1 2 2.25 2.5 0.25 > 0.01 2 2.25 2.375 2.5 0.125 > 0.01 3 2.375 2.4375 2.5 0.0625 > 0.01 4 2.375 2.40625 2.4375 0.03125 > 0.01 5 2.40625 2.421875 2.4375 0.015625 > 0.01 6 2.421875 2.429688 2.4375 0.007813 0.01 6. The conclusion is: Root = 2.429688 ± 0.01 Numerical Methods Lecture 3 by Pavel Ludvík 7 / 24

Bisection Method - Matlab Exercise A Write an M-File for one step of the Bisection Method. Input: Function f and limitpoints of an interval [a n, b n ]. Output: Limitpoints of an interval [a n+1, b n+1 ]. Exercise B Create an M-File for the Bisection Method. The program should stop before doing 24 iterations. Numerical Methods Lecture 3 by Pavel Ludvík 8 / 24

Answers Answer A p = (a+b)/2; if f(a)*f(p)<0 b=p; elseif f(p)*f(b)<0 a=p else break end Numerical Methods Lecture 3 by Pavel Ludvík 9 / 24

Answer B f = ; % the function formula epsilon = ; % the precision maxn = ; % limitation on the number of steps a(1) = ; b(1) = ; % initial approximation for n = 1 : maxn p(n) = (a(n)+b(n))/2; if (b(n)-a(n))/2 <= epsilon, break elseif f(a(n))*f(p(n))<0 a(n+1) = a(n); b(n+1) = p(n); elseif f(p(n))*f(b(n))<0 a(n+1) = p(n); b(n+1) = b(n); else break end end disp( a(n) p(n) b(n) ) disp([a p b ]) Numerical Methods Lecture 3 by Pavel Ludvík 10 / 24

Exercises 1. Solve the equation e 0.2x e 0.8x 2 = 0 with an accuracy 10 3. 2. Show that a function f (x) = x sin x cos x has just one root in the interval [0, π/2] and find it to an accuracy of four decimal places. 3. Derive a formula for an error upper bound after n steps. 4. Try to use the Bisection Method with starting interval [ 2, 1] to find a root of the function f (x) = 1 x. What did happen? Explain why. 5. Can you tell the number of steps needed for Bisection Method to find the root to a given accuracy without carrying it out? How? Numerical Methods Lecture 3 by Pavel Ludvík 11 / 24

The Secant Method Description The Secant Method is a version of the bisection method that takes a more informed approach to reducing the interval containing a root. It is likely therefore to require a smaller number of iterations. The idea is to approximate the function by its secant and instead of looking for the root of the original function to use the root of the secant line as an approximation. A formula for a secant line of the function f connecting two points [a, f (a)] and [b, f (b)] is y = f (a) + f (b) f (a) (x a). b a Numerical Methods Lecture 3 by Pavel Ludvík 12 / 24

The Secant Method Algorithm Mathematical Formula x 0, x 1 = initial guesses, x x n = x n 1 f (x n 1 ) n 1 x n 2 f (x n 1 ) f (x n 2 ). Numerical Methods Lecture 3 by Pavel Ludvík 13 / 24

The Secant Method Algorithm Algorithm for solving f (x) = 0 by the Secant Method 1. Find an interval containing x such that f (x) = 0. 2. Set x to b f (b) b a f (b) f (a). 3. Test for convergence: Find out if b x ε. 4. Set a to b and b to x. 5. Repeat from step 2. Numerical Methods Lecture 3 by Pavel Ludvík 13 / 24

Example Find a root of the equation 8 4.5(x sin x) = 0 with a tolerance less than ε = 0.0001 = 10 4. Solution 1. We define a function f (x) = 8 4.5(x sin x). 2. From a graph of f we set the first two initial approximations, i.e. x 0 = 2 and x 1 = 3. The error is x 1 x 0 = 1 > ε. 3. The next approximation is x x 2 = x 1 f (x 1 ) 1 x 0 f (x 1 ) f (x 0 ) = 3 f (3) 3 2 f (3) f (2) = 2.3886 4. We evaluate the error which is x 3 x 2 = 0.6114 and the value is bigger then 10 4. Numerical Methods Lecture 3 by Pavel Ludvík 14 / 24

Solution x 2 x 1 5. We compute x 3 = x 2 f (x 2 ) f (x 2 ) f (x 1 ) = 2.4273, Error = x 3 x 2 = 0.0387. and continue in this manner until error is sufficiently small. 6. See the results in a table: 7. The conclusion is: n x n Error 0 2 1 3 1 > ε 2 2.3886 0.6114 > ε 3 2.4273 0.0386 > ε 4 2.4305 0.0032 > ε 5 2.4305 0.00002549598350 ε Root = 2.4305 ± 10 4 Numerical Methods Lecture 3 by Pavel Ludvík 15 / 24

The Secant Method Matlab f = ; % the function formula epsilon = ; % the precision maxn = ; % limitation on the number of steps x(1) = ; x(2) = ; % initial approximation for n = 3 : maxn x(n) = x(n-1) - f(x(n-1))*(x(n-1)-x(n-2))/(f(x( n-1))-f(x(n-2))); if abs(x(n)-x(n-1)) <= epsilon, break, end disp( x(n-2) x(n-1) x(n) Error ) disp([x(1:n-2) x(2:n-1) x(3:n) (x(3:n)-x(2:n-1)) ]) Numerical Methods Lecture 3 by Pavel Ludvík 16 / 24

Exercises 1. Solve the problems from the section about Bisection Method. 2. Use the Secant Method to calculate the 4 2 to an accuracy of six decimal places. 3. Think about the stopping criterion. Is it precise? If the consider error is small, does it necessarily mean we have a good approximation? Try to find an counterexample. 4. Look up the commands fzero and roots in the help of Matlab. Numerical Methods Lecture 3 by Pavel Ludvík 17 / 24

Newton-Raphson Method Description A feature of the secant method is its attempt to follow the graph of the function using a straight line. The Newton method pursues the idea by allowing the two points of the secant method to merge into one. In so doing it uses a single point and the tangent to the function at that point to construct a new estimate to the root. A formula for a zero point of a tangent line of the function f constructed at point a is x = a f (a) f (a). Numerical Methods Lecture 3 by Pavel Ludvík 18 / 24

Newton-Raphson Method Algorithm Mathematical Formula x 0 = initial guess, x n+1 = x n f (x n) f (x n ). Numerical Methods Lecture 3 by Pavel Ludvík 19 / 24

Newton-Raphson Method Algorithm Algorithm for solving f (x) = 0 by the Newton-Raphson Method 1. Find an interval containing x such that f (x) = 0. 2. Choose a starting point a. 3. If f (a) 0 replace a by x = a f f (a), otherwise restart using a different starting point a. 4. Test for convergence: Find out if x a ε. 5. Repeat from step 2. Numerical Methods Lecture 3 by Pavel Ludvík 19 / 24

Newton-Raphson Method Convergence Theorem (Convergence Theorem) Let e n denote the error after step n of the N-R Method. Furthermore, let f be twice continuously differentiable and f (p) = 0. If f (p) 0, then N-R Method is locally convergent to p and e lim n+1 n e 2 n = M (i. e., method is quadratically convergent), where Local Convergence M = f (p) 2f (p). A method is locally convergent if there exists an interval containing a root such that the sequence generated by this method converge to the root. Numerical Methods Lecture 3 by Pavel Ludvík 20 / 24

Example Find a root of the equation 8 4.5(x sin x) = 0 with a tolerance less than ε = 0.000001 = 10 6. Solution 1. We define a function f (x) = 8 4.5(x sin x) and compute its derivative f (x) = 4.5(1 cos x). 2. From a graph of f we set the initial approximation. We try x 0 = 2. 3. The first approximation will be x 1 = x 0 f (x 0) 8 4.5(2 sin(2)) f = 2 = 2.48517 (x 0 ) 4.5(1 cos(2)) 4. We evaluate the error which is x 1 x 0 = 0.48517 and the value is bigger then 10 6. Numerical Methods Lecture 3 by Pavel Ludvík 21 / 24

Solution 5. We compute x 2 = x 1 f (x 1) f (x 1 ), Error = x 2 x 1. and continue in this manner until error is sufficiently small. 6. See the results in a table: 7. The conclusion is: n x n Error 0 2 1 2.485172 0.485172 > ε 2 2.430987 0.054185 > ε 3 2.430465 0.000521 > ε 4 2.430465 0.000000 ε Root = 2.43046574172363 ± 10 6 Numerical Methods Lecture 3 by Pavel Ludvík 22 / 24

The Newton-Raphson Method Matlab f = @(x) ; % the function formula %%%%%%%%%%%%% SYMBOLIC TOOLBOX REQUIRED syms x ; % creating the symbolic variable x symdf = diff(f(x)); % the derivative df = matlabfunction(symdf); % conversion %%%%%%%%%%%%%OTHERWISE COMPUTE DERIVATIVE MANUALLY epsilon = ; % the precision maxn = ; % limitation on the number of steps clear x; x(1) = ; % clearing x as a symbolic variable; setting initial approximation for n = 2 : maxn x(n) = x(n-1) - f(x(n-1))/df(x(n-1)); if abs(x(n)-x(n-1)) <= epsilon, break, end end disp( x(n-1) x(n) Error ) disp([x(1:n-1) x(2:n) (x(1:n-1)-x(2:n)) ]) Numerical Methods Lecture 3 by Pavel Ludvík 23 / 24

Exercises 1. Solve the problems from the section about Bisection Method. 2. Use the Newton Method to calculate the 4 2 to an accuracy of six decimal places. 3. Think about the stopping criterion. Is it precise? If the consider error is small, does it necessarily mean we have a good approximation? Try to find an counterexample. 4. Prove that Newton Method applied to f (x) = ax + b converges in one step. 5. A 10-cm-high cone contains 60 cm 3 of ice cream, including a hemispherical scoop on top. Find the radius of the scoop to four correct decimal places. Numerical Methods Lecture 3 by Pavel Ludvík 24 / 24