Lecture+15-Bracket+method

# Lecture+15-Bracket+method - Hand Calculation Example...

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

Hand Calculation Example Bisection Method f(2) = 3, f(3.2) = 0.84 [ ] [ ] 2 3 0 2 x , x estimeates initial 0 3 x 2 x x f Example u l 2 . , . ) ( : = = - - = ( ) 1 2.0 3.2 2.6 1.44 1.2 2 2.6 3.2 2.9 0.39 0.6 3 2.9 3.2 3.05 0.2025 0.3 4 2.9 3.05 2.975 0.0994 0.15 5 2.975 3.05 3.0125 0.0502 0.075 6 2.975 3.0125 2.99375 0.02496 0.0375 l u r r iter x x x f x x - - - -

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

View Full Document
Hand Calculation Example Bisection Method [ ] [ ] 2 3 0 2 x , x estimeates initial 0 3 x 2 x x f Example u l 2 . , . ) ( : = = - - = -3 -2.5 -2 -1.5 -1 -0.5 0 0.5 1 2 2.1 2.2 2.3 2.4 2.5 2.6 2.7 2.8 2.9 3 3.1 3.2 3.3
You need to specify the function “func” when calling this function M-file in textbook function [root,fx,ea,iter]=bisect(func,xl,xu,es,maxit,varargin) % bisect: root location zeroes % [root,fx,ea,iter]=bisect(func,xl,xu,es,maxit,p1,p2,. ..): % uses bisection method to find the root of func % input: % func = name of function % …see page 139 of 3rd Ed or page 127 or 2nd Ed for the rest… % output: … if nargin<3,error( 'at least 3 input arguments required' ), end test = func(xl,varargin{:})*func(xu,varargin{:}); if test>0,error( 'no sign change' ), end if nargin<4|isempty(es), es=0.0001; end if nargin<5|isempty(maxit), maxit=50; end iter = 0; xr = xl; ea = 100; while (1) xrold = xr; xr = (xl + xu)/2; iter = iter + 1; if xr ~= 0,ea = abs((xr - xrold)/xr) * 100; end test = func(xl,varargin{:})*func(xr,varargin{:}); if test < 0 xu = xr; elseif test > 0 xl = xr; else ea = 0; end if ea <= es | iter >= maxit, break , end end root = xr; fx = func(xr, varargin{:}); x y xu test<0 xl xr=0.5(xl+xu) x y xu test>0 xl xr=0.5(xl+xu)

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

View Full Document
Example >> trig=@(x) sin(10*x)+cos(3*x); >> xl=3.2; >> xu=3.3; >> maxit=60; >> es=1.0E-5; >> [root,fx,ea,iter]=bisect(trig,xl,xu,es,maxit) root = 3.2624 fx = -2.9578e-008 ea = 5.8464e-006 iter = 19
break: terminate a “for” or “while” loop a x b ya yb y Use “feval” to evaluate the function “func” An interactive M-file

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

View Full Document
1. Find root of Manning ' s equation 2. Two other functions Examples: Bisection ( 29 ( 29 0 S 2h b bh n 1 Q f(h) 1/2 2/3 5/3 = + - = 0 x e ) x ( f 2 x = - = - 0 1 x 3 x ) x ( f 3 = + - =
Bisection Method for Manning Equation »bisect2( 'manning' ) enter lower bound xl = 0 enter upper bound xu = 10 allowable tolerance es = 0.00001 maximum number of iterations maxit = 50 Bisection method has converged step xl xu xr f(xr) 1.0000 0 10.0000 5.0000 264.0114 2.0000 5.0000 10.0000 7.5000 -337.3800 3.0000 5.0000 7.5000 6.2500 -25.2627 4.0000 5.0000 6.2500 5.6250 122.5629 5.0000 5.6250 6.2500 5.9375 49.4013 6.0000

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

View Full Document
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 / 26

Lecture+15-Bracket+method - Hand Calculation Example...

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

View Full Document
Ask a homework question - tutors are online