4/24/16 7:26 PM_/Users/ben/Documents.../myHybridNRFP_bmorris9.m
function [xr, fxr,ea,numIter]= myybridNRFP_bmorris9(myfunc, x0, es,maxIter)
BBB BBB BOOP AE POREEEEREEISOBBOOBOOSOOB OSE ETEEEEAREOSPOBSOOBOOO OO OREOEEEEADS
sFunction file: myHybridNRFP_username.m
%
Purpose:
% To obtain the root of a function using a hybrid (False Position + Newton
% Raphson) method
%
sRecord of revisions (Date | Programmer | Change):
% 2/11/2016 | Ben Morris | Original program
%
sain Variables:
SsINPUTS:
5% myfunc _~ function handle for [fx,dfx]=myfunc(x)
% x0-(1x2) initial bracket [xL,xU]
% es-(1x1) specified error tolerance in % (i-e, es=5 implies error tolerance of 5%)
%
% maxIter ~ (1x1) maximum number of iterations that can be performed %
SxQUTPUTS.
% xr- (1x1) estimate of the root
% fxr- (1x1) value of function at xr
% ea~ (1x1) approx. percentage relative error at xr
% nunIter- (1x1) number of iterations required to obtain xr
%
BAP EA POO PRP POPPER EOD POPEEPDOOEEPPOPPOREOOCOPEDP EOP ERR EOPPOREOBOOTEREOOEED
“basic checks on inputs
assert (Length(x@)==2, 'x0 should be a vector of 2 elements');
assert ((es>0)6&(es<100), ‘es should be between (0,100)')5
assert (maxIter>1, 'maxItér should be >1');
Sinitialize the outputs
fxLemyfunc(xt) ;
fxU=myfunc(xU) ;
assert (fxL.#fxUe®, "function should change sign within [xt,xU]")s
xrPrev:
[xr,dfxr] = myfunc(xu);
while (ea>=es)&&(numIter xr-fxr./dfxr))
xrexr—fxr./dPK6}
(fxr, dfxed=myfune(xe)
easabs((xr-xrPrev)./xr) #100;
numIter=numIter+1;
else
XP=xU-fxU.*(XU-xL) . / (FxU-fXL) ;
wyfune (xr);
Ai (ParetxL0)
xL = xry
fx = fxrs
end
ea = abs((xr-xrPrev) ./xr) #100;
nuntter = numIter+1;