clc; clear;
tolerence=0.0001;
a=0.8;
b=1.0;
r=1;
i=0;
while abs((r^3) - sin(r))>tolerence;
r=(a+b)/2;
if ((r^3) - sin(r))<0;
a=r;
else ((r^3) - sin(r))>0;
b=r;
end
i=i+1;
end
fprintf('Number of iterations = %g',i)
fprintf('\nThe root = %g\n',r)
Number of iterations = 11
The root = 0.928613
Published with MATLAB 8.0