Title: Engineering Computation
1EngineeringComputation
2Bisection Method
This is the MainBisection program xl0.0000001
xu1 es0.00002 imax50 xxlinspace(xl,xu,20)
yyf(xx) plot(xx,yy) hold on Bisect ea
iterBisection(xl,xu,es,imax) fprintf('Solution
18.12f Relative error 18.12f Iterations
5d\n',Bisect,ea,iter)
3Bisection Method
function Bisect ea iterBisection(xl,xu,es,imax)
iter0 flf(xl) ea2es xrxl while eagtes
iterltimax xroldxr xr(xlxu)/2
frf(xr) iteriter1 if xr 0
eaabs((xr-xrold)/xr)100 end
testflfr if testlt0 xuxr else
if testgt0 xlxr flfr
else ea0 end end
fprintf(' xl 18.8f xu 18.8f\n',xl,xu) end
Bisectxr
4False Position Method
function xr ea iterFalsePosition(xl,xu,es,imax)
iter0 flf(xl) fuf(xu) ea2es xrxl il0
iu0 while eagtes iterltimax xroldxr
xrxu-fu(xl-xu)/(fl-fu) frf(xr)
iteriter1 if xr 0
eaabs((xr-xrold)/xr)100 end
testflfr if testlt0 xuxr
fuf(xu) iu0 ilil1
if ilgt2 flfl/2 else if
testgt0 xlxr
flf(xl) il0
iuiu1 if iugt2
fufu/2 else
ea0 end end
end end fprintf(' xl 18.8f xu
18.8f\n',xl,xu) end
xl0.0000001 xu1 es0.00002 imax100 xxlinsp
ace(xl,xu,20) yyf(xx) plot(xx,yy) hold
on plot(xl,xu,0,0,'') xr ea
iterFalsePosition(xl,xu,es,imax) fprintf('Solut
ion 18.12f Relative error 18.12f Iterations
5d\n',xr,ea,iter)
5Fixed Point Method
x00.000001 es0.0000000001 imax30 xr ea
iterFixedPoint(x0,es,imax) fprintf('Solution
18.12f Relative error 18.12f Iterations
5d\n',xr,ea,iter) function xr ea
iterFixedPoint(x0,es,imax) xrx0 iter0 ea2e
s while eagtes iterltimax xroldxr
xrg(xrold) iteriter1 if xr 0
eaabs((xr-xrold)/xr)100 end
fprintf(' xr 18.8f ea 18.8f\n',xr,ea) end
6Modified Secant Method
x00.1 es0.00002 imax30 xr ea
iterModifiedSecant(x0,es,imax) fprintf('Solutio
n 18.12f Relative error 18.12f Iterations
5d\n',xr,ea,iter) function xr ea
iterModifiedSecant(x0,es,imax) xrx0 iter0 ea
2es eps0.01 while eagtes iterltimax
xroldxr xrxr-f(xr)/(f(xreps)-f(xr-eps))2
eps iteriter1 if xr 0
eaabs((xr-xrold)/xr)100 end fprintf('
xr 18.8f ea 18.8f\n',xr,ea) end plot(xr,0
,'')
7Newton-Raphson Method
x00.2 es0.00002 imax30 xr ea
iterNewtonRaphson(x0,es,imax) fprintf('Solution
18.12f Relative error 18.12f Iterations
5d\n',xr,ea,iter) function xr ea
iterNewtonRaphson(x0,es,imax) xrx0 iter0 ea
2es while eagtes iterltimax xroldxr
xrxr-f(xr)/f1(xr) iteriter1 if xr
0 eaabs((xr-xrold)/xr)100 end
fprintf(' xr 18.8f ea 18.8f\n',xr,ea) end