% False-Position Method
clc,clear
f=@(x) -3*x^3+19*x^2-20*x-13;
xl=-1; xu=0; % lower and upper values
ezplot(f,[xl,xu]); % Graph of function
ea=100; % Approximate percent relative error
es=1; % Prespecified percent tolerance
c=1; % Count of steps( Number of iterations)
xrp=0; % xrp-previous
while ea > es
xr=xu-f(xu)*(xl-xu)/(f(xl)-f(xu));
ea=abs((xr-xrp)/xr)*100;
Result(c,:)=[ c , xl ,xu , xr , f(xl), f(xu), f(xr), ea ];
if f(xl)*f(xr)<0
xu=xr;
elseif f(xl)*f(xr)>0
xl=xr;
else
disp(['The root xr=' xr])
break;
end
c=c+1;
xrp=xr; % To change xrp-previous with xr-present
end
Result
--------------------------------------------------------------
>>
Result =
𝒄 𝒙𝐥 𝒙𝐮 𝒙𝐫 𝒇(𝒙𝐥 ) 𝒇(𝒙𝐮 ) 𝒇(𝒙𝐫 ) 𝜺𝒂
1.0000 -1.0000 0 -0.3095 29.0000 -13.0000 -4.9003 100.0000
2.0000 -1.0000 -0.3095 -0.4093 29.0000 -4.9003 -1.4241 24.3832
3.0000 -1.0000 -0.4093 -0.4370 29.0000 -1.4241 -0.3820 6.3271
4.0000 -1.0000 -0.4370 -0.4443 29.0000 -0.3820 -0.1002 1.6475
5.0000 -1.0000 -0.4443 -0.4462 29.0000 -0.1002 -0.0262 0.4290
Bewar Y. Ali Numerical Analysis