Lecture+17--Secant+_+fzero

# Lecture 17-Secant_ - Newtons Method-Matlab code function[root,ea,iter]=newtraph(func,dfunc,xr,es,maxit,varargin if nargin<3,error'at least 3 input

This preview shows pages 1–9. Sign up to view the full content.

Newton’s Method--Matlab code >> [r,ea,it]=newtraph(@(x) 3*x+sin(x)-exp(x),@(x) 3+cos(x)-exp(x),1) r = 0.360421702960200 ea = 3.459226917839900e-011 it = 6 function [root,ea,iter]=newtraph(func,dfunc,xr,es,maxit,varargin) if nargin<3,error( 'at least 3 input arguments required' ), end if nargin<4|isempty(es),es=0.0001; end if nargin<5|isempty(maxit),maxit=50; end iter = 0; while (1) xrold = xr; xr = xr - func(xr)/dfunc(xr); iter = iter + 1; if xr ~= 0, ea = abs((xr - xrold)/xr) * 100; end if ea <= es | iter >= maxit, break , end end root = xr; x 1 = x 0 - f 0/ f 0 '

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
Newton’s Method Example : f ( x ) = 3 x + sin( x ) - exp( x ) Iter. # x n f ( x n) e n= x n- r 1 0.333333333 -6.84E-02 2.71E-02 2 0.360170714 -6.28E-04 2.52E-04 0.346 3 0.360421681 -5.63E-08 2.25E-08 0.354 4 0.360421703 -6.66E-16 Comments: * It may not converge if x 0 is too far from x = r . * If x 0 is close to r , Newton's method converges very fast. x 0 = 0 doubling
Newton’s Method Quadratic convergence: = constant Illustration of quadratic convergence: 0 2 4 6 8 10 12 0 0 0 0 0 0 0 0.01 1 100 parabola n Error=|xn-r| Linear convergence

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
Newton-Raphson Method Examples of poor convergence or failure
Secant Method Ø Use secant line instead of tangent line at f ( xi )

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
Secant Method The formula for the secant method is Notice that this is very similar to the false position method in form Still requires two initial estimates But it doesn ' t bracket the root at all times -- there is no sign test ) ( ) ( ) )( ( i 1 i i 1 i i i 1 i x f x f x x x f x x - - - = - - +
False-Position and Secant Methods

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
Algorithm for Secant method Open Method . 1 Begin with any two endpoints [ a, b ] = [ x0 , x1 ] . 2 Calculate x2 using the secant method formula 3. Replace x0 with x1 , replace x1 with x2 and repeat from (2) until convergence is reached Use the two most recently generated points in subsequent iterations (not a bracket method!) ) ( ) ( ) )( ( i 1 i i 1 i i i 1 i x f x f x x x f x x - - - = - - +
This is the end of the preview. Sign up to access the rest of the document.

## This note was uploaded on 11/07/2011 for the course EGM 3344 taught by Professor Raphaelhaftka during the Spring '09 term at University of Florida.

### Page1 / 21

Lecture 17-Secant_ - Newtons Method-Matlab code function[root,ea,iter]=newtraph(func,dfunc,xr,es,maxit,varargin if nargin<3,error'at least 3 input

This preview shows document pages 1 - 9. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online