clc;
clear;
f = @(x) x.*3-cos(x)-1;
a = input("a: \n");
b = input("b: \n");
tol = input("tollerance: \n");
error = 100;
prev_c = 0
e(1) = 0;
for i = 1:100
c = (a+b)/2;
error = abs((prev_c-c)/c)*100;
if f(a)*f(c)<0
b=c;
else
a=c;
end
if error < tol
break;
end
prev_c = c;
end
fprintf('Root = %.6f\n',c);
To embed this project on your website, copy the following code and paste it into your website's HTML: