Root finding.

Slides:



Advertisements
Similar presentations
CSE 330: Numerical Methods
Advertisements

Optimisation The general problem: Want to minimise some function F(x) subject to constraints, a i (x) = 0, i=1,2,…,m 1 b i (x)  0, i=1,2,…,m 2 where x.
Bisection Method (Midpoint Method for Equations).
Open Methods Chapter 6 The Islamic University of Gaza
MIT and James Orlin © Nonlinear Programming Theory.
Lectures on Numerical Methods 1 Numerical Methods Charudatt Kadolkar Copyright 2000 © Charudatt Kadolkar.
Bracketing Methods Chapter 5 The Islamic University of Gaza
Fin500J: Mathematical Foundations in Finance Topic 3: Numerical Methods for Solving Non-linear Equations Philip H. Dybvig Reference: Numerical Methods.
- + Suppose f(x) is a continuous function of x within interval [a, b]. f(a) = - ive and f(b) = + ive There exist at least a number p in [a, b] with f(p)
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.
Solving Non-Linear Equations (Root Finding)
Continuity ( Section 1.8) Alex Karassev. Definition A function f is continuous at a number a if Thus, we can use direct substitution to compute the limit.
CHAPTER Continuity Derivatives and the Shapes of Curves.
Section 14.7 Second-Order Partial Derivatives. Old Stuff Let y = f(x), then Now the first derivative (at a point) gives us the slope of the tangent, the.
Graphics Graphics Korea University kucg.korea.ac.kr 2. Solving Equations of One Variable Korea University Computer Graphics Lab. Lee Seung Ho / Shin.
Sec 15.6 Directional Derivatives and the Gradient Vector
Numerical Methods for Engineering MECN 3500
Numerical Methods.
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 5 Bracketing Methods.
Solving Non-Linear Equations (Root Finding)
Solution of Nonlinear Equations Topic: Bisection method
Numerical Methods Solution of Equation.
While loop  a while loop repeats a block of code as long as a logical condition is true  unlike a for loop  there is no loop variable  the number of.
Basis of Mathematical Modeling LECTURE 3 Numerical Analysis with MATLAB Dr. N.K. Sakhnenko, PhD, Professor Associate.
Advanced Computer Graphics Optimization Part 2 Spring 2002 Professor Brogan.
A Different Solution  alternatively we can use the following algorithm: 1. if n == 0 done, otherwise I. print the string once II. print the string (n.
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 1 Part 2 - Chapter 7 Optimization.
Finding zeros (also called roots) of a function Overview: Define the problem Methods of solution Graphical Newton’s Bisection Secant.
1 M 277 (60 h) Mathematics for Computer Sciences Bibliography  Discrete Mathematics and its applications, Kenneth H. Rosen  Numerical Analysis, Richard.
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.
CMPSC 200 Fall 2013 Lecture 37 November 18, 2013.
Integration Chapter 15.
Solution of Nonlinear Equations ( Root Finding Problems )
Chapter 5 Numerical Root Findings
EEE 244-3: MATRICES AND EQUATION SOLVING
Continuity and One-Sided Limits
Announcements Topics: Work On:
Recursion notes Chapter 8.
Solution of Nonlinear Equations (Root finding Problems
Numerical Methods and Analysis
4.1 Notes day 2 Remainder Theorem: If a polynomial f(x) is divided by x – c, then the remainder is f(c). Ex. f(x) = x3 + 3 divided by g(x)= x -1.
Lesson 4-QR Quiz 1 Review.
Maximum & Minimum values
Read Chapters 5 and 6 of the textbook
Part 2 Chapter 6 Roots: Open Methods
MATH 2140 Numerical Methods
More About Optimization
Important Values for Continuous functions
Computers in Civil Engineering 53:081 Spring 2003
Application of Derivative in Analyzing the Properties of Functions
Optimization Part II G.Anuradha.
Intermediate Value Theorem
Intermediate Value Theorem
Continuity and Intermediate Value Theorem
7.2 Polynomial Functions and Their Graphs
1.4 Continuity and One-Sided Limits (Part 2)
ROOTS OF EQUATIONS.
Lecture 5 Higher-order procedures מבוא מורחב - שיעור 5.
Continuity Alex Karassev.
Newton’s Method and Its Extensions
FP1: Chapter 2 Numerical Solutions of Equations
EEE 244-3: MATRICES AND EQUATION SOLVING
APPLICATIONS OF DERIVATIVES
Comp 208 Computers in Engineering Yi Lin Winter, 2007
Copyright © Cengage Learning. All rights reserved.
Part 2 Chapter 6 Roots: Open Methods
Solutions for Nonlinear Equations
Presentation transcript:

Root finding

Root finding suppose you have a mathematical function f(x) and you want to find x0 such that f(x0) = 0 why would you want to do this? many problems in computer science, science, and engineering reduce to optimization problems find the shape of an automobile that minimizes aerodynamic drag find an image that is similar to another image (minimize the difference between the images) find the sales price of an item that maximizes profit if you can write the optimization criteria as a function g(x) then its derivative f(x) = dg/dx = 0 at the minimum or maximum of g (as long as g has certain properties)

Roots of polynomials for roots of polynomials MATLAB has a function named roots roots finds all of the roots of a polynomial defined by its coefficients vector; e.g., the roots of the polynomial 𝑥 3 −6 𝑥 2 −72𝑥−27: p = [1 -6 -72 -27]; r = roots(p) r = 12.1229 -5.7345 -0.3884

Roots of non-polynomials we've already seen Newton's method for root finding (Day 12) start with an initial estimate of the root 𝑥 0 𝑖=0 while 𝑓 𝑥 𝑖 >𝜖 𝑥 𝑖+1 = 𝑥 𝑖 − 𝑓 𝑥 𝑖 𝑓 ′ 𝑥 𝑖 𝑖=𝑖+1 this requires computation of both 𝑓(𝑥) and 𝑓′(𝑥)

Newton's method our previous implementation used local functions to represent both 𝑓(𝑥) and 𝑓′(𝑥) the problem with this approach is that we can only find roots of the local function that defines 𝑓(𝑥) e.g., our previous implementation can only find the roots of 𝑓 𝑥 = 𝑥 2 −1

can only find the root of this function function [ root, xvals ] = newton(x0, epsilon) %NEWTON Newton's method for x^2 - 1 % ROOT = NEWTON(X0, EPSILON) finds a root of f(x) = x^2 - 1 using % Newton's method starting from an initial estimate X0 and a tolerance EPSILON % % [ROOT, XVALS] = NEWTON(X0, EPSILON) also returns the iterative estimates % in XVALS xvals = x0; xi = x0; while abs(f(xi)) > epsilon xj = xi - f(xi) / fprime(xi); xi = xj; xvals = [xvals xi]; end root = xi; function [ y ] = f(x) y = x * x - 1; function [ yprime ] = fprime(x) yprime = 2 * x; can only find the root of this function

Function handles it would be nice if we could tell our implementation of Newton's method what function to use for 𝑓(𝑥) and 𝑓′(𝑥) MATLAB does not allow you to pass a function directly to another function instead you must pass a function handle to the function a function handle is a value that you can use to call a function (instead of using the name of the function) because it is a value, you can store it in a variable!

Function handles you can create a handle for any function by using @ before the function name linspaceHandle = @linspace; % handle for linspace cosHandle = @cos; % handle for cos plotHandle = @plot; % handle for plot

Function handles you can use the handle to call the function exactly the same way that you would use the function name to call the function % use handle to call linspace x = linspaceHandle(-1, 1, 50); % use handle to call cos y = cosHandle(2 * pi * x); % use handle to call plot plotHandle(x, y, 'b:');

Function functions by using function handles, we can modify our implementation of Newton's method to find the root of any function we just have to supply two function handles, one for 𝑓(𝑥) and a second for 𝑓′(𝑥) we also need MATLAB functions that implement 𝑓(𝑥) and 𝑓′(𝑥)

local functions have been removed function handles function [ root, xvals ] = newton(f, fprime, x0, epsilon) %NEWTON Newton's method for root finding % ROOT = NEWTON(F, FPRIME, X0, EPSILON) finds a root of the % function F having derivative FPRIME using Newton's method % starting from an initial estimate X0 and a tolerance EPSILON % % [ROOT, XVALS] = NEWTON(F, FPRIME, X0, EPSILON) also returns % the iterative estimates in XVALS xvals = x0; xi = x0; while abs(f(xi)) > epsilon xj = xi - f(xi) / fprime(xi); xi = xj; xvals = [xvals xi]; end root = xi; local functions have been removed

Function functions let’s find a root of which has the derivative 𝑓 𝑥 = 𝑥 tan 𝜋 𝑥 − 1−𝑥 𝑓 ′ 𝑥 = 1 2 1 1−𝑥 + tan 𝜋 𝑥 𝑥 +𝜋 sec 2 𝜋 𝑥

plot of 𝑓(𝑥)

function [y] = myf(x) %MYF Function to find the root of y = sqrt(x) function [y] = myf(x) %MYF Function to find the root of y = sqrt(x) .* tan(pi * sqrt(x)) - sqrt(1 - x); end

function [y] = myfprime(x) %MYFPRIME Derivative of MYF sqrtx = sqrt(x); a = 1 / sqrt(1 - x); b = tan(pi * sqrtx) / sqrtx; c = pi * (sec(pi * sqrtx))^2; y = 0.5 * (a + b + c); end

Function functions we can now use our Newton’s method implementation by passing in function handles for f and fprime newton(@myf, @myfprime, 0.1, 1e-6)

Bracketing methods Newton’s method requires an initial estimate of the root and the derivative of the function that we want to find the roots for bracketing methods do not require the derivative

Bracketing methods bracketing methods require two estimates 𝑥 1 =𝑎 and 𝑥 2 =𝑏 such that the root lies between the two estimates f(x) 𝑓 𝑎 𝑓 𝑥 =0 𝑏 x 𝑎 𝑓 𝑏

Bisection method the bisection method repeatedly evaluates 𝑓 at the midpoint 𝑐 𝑖 of the interval [ 𝑎 𝑖 , 𝑏 𝑖 ] 𝑐 𝑖 becomes one of the new interval endpoints [ 𝑎 𝑖+1 , 𝑏 𝑖+1 ] depending of the sign of 𝑓( 𝑐 𝑖 )

Bisection Method evaluate f(x) at two points x = a and x = b such that f(a) > 0 f(b) < 0 f(x) 𝑓 𝑎 𝑏 x 𝑎 𝑓 𝑏

Bisection method evaluate f(c) where c is halfway between a and b if f(c) is not close to zero, repeat the bisection using c as one of the new endpoints f(x) 𝑓 𝑎 𝑐 𝑏 x 𝑎 𝑓 𝑏

Bisection method in this example, the value of f(c) is not yet close enough to zero c becomes the new b (because the sign of f(c) is negative) and the process repeats f(x) 𝑓 𝑎 𝑏 x 𝑎 𝑓 𝑏

Bisection method the method stops when f(c) becomes close enough to zero, and c is the estimate of the root of f f(x) 𝑓 𝑎 𝑐 𝑏 x 𝑎 𝑓 𝑏