x3 x1funcx2 x2funcx1funcx2 funcx1 disp i x1 x2 x3 funcx1 funcx2 funcx3 absx3

# X3 x1funcx2 x2funcx1funcx2 funcx1 disp i x1 x2 x3

This preview shows page 14 - 21 out of 21 pages.

x3= (x1*func(x2)-x2*func(x1))/(func(x2)-func(x1)); disp ([i; x1; x2; x3; func(x1); func(x2); func(x3); abs((x3-xold)/x3)]'); if func(x3)*func(x1)<0 x2=x3; elseif func(x3)*func(x1)>0 x1=x3; else break end if abs((x3-xold)/x3)<=elimit break end xold=x3; end function s=func(x) s=x-x^(1/3)-2; func.m falseposition.m 14
start Read X 1 ,X 2 and ε s f(x 1 ) × f(x 2 )<0 yes no f(x 1 ) × f(x 3 )<0 f(x 1 ) × f(x 3 )>0 ε a ≤ε s Set X 2 =X 3 Set X 1 =X 3 Set new range yes no yes root =X 3 2 no b 2 a stop yes a no % 100 3 3 3 new old new x x x a b Print, Root= X 3 ) ( ) ( ) ( ) ( 1 2 1 2 2 1 3 x f x f x f x x f x x 26 April 2015 15 ME262 Numerical Analysis Sessional False Position: Flow Chart 1 1
26 April 2015 ME262 Numerical Analysis Sessional 16 Newton-Raphson Method ) ( ' ) ( 1 i i i i x f x f x x 1 1 i i a i x - x = x
26 April 2015 ME262 Numerical Analysis Sessional 17 Newton-Raphson Method step 01: Start at the point (x 1 , f ( x 1 )). step 02 : If f '( x 1 ) 0 the new root will be found: x 2 = x 1 - f ( x 1 )/ f '( x 1 ) step 03: Examine if f ( x 2 ) = 0 or abs{( x 2 - x 1 )/ x 2 } Error limit step 04: If yes, solution x r = x 2 If not, x 1 = x 2 , repeat from step 02
26 April 2015 ME262 Numerical Analysis Sessional 18 Class Problem 2 ) sin( ) ( x e x f x Find the root of the following equation: Error Limit = 0.0001
26 April 2015 ME262 Numerical Analysis Sessional 19 x1 = 1.0; elimit = 0.0001; while df(x1)~= 0 x2 = x1 - f(x1) / df(x1); if abs((x2 - x1) / x2) <= elimit break elseif f(x2)==0 break end x1 = x2; end disp('root is:'); disp(x2); function y = f(x) y = exp(x)+sin(x)-2; function s = df(x) s = exp(x)+cos(x); nwtnraph.m f.m df.m Solution 0.44867191635130
26 April 2015 ME262 Numerical Analysis Sessional 20 fzero function finds zeros of the function of a single-variable MATLAB Command >> x = fzero(‘ fun

#### You've reached the end of your free preview.

Want to read all 21 pages?