Page 1 of 1

Using MATLAB, what code will be added to the code below to show the error? Provide an explanation the code you've used.

Posted: Mon May 02, 2022 12:25 pm
by answerhappygod
Using MATLAB, what code will be added to the code below to show
the error? Provide an explanation the code you've used.
(Hint: modify the line with %error code)
function [x,e]= Mbisect(f,a,b,n)
l=f(a); u=f(b);
if l*u > 0.0
error("wrong a and b, since F(a)*f(b) > 0.0")
end
disp('x y') %disp('x y error')
for i=1:n
x=(a+b)/2;
y=f(x);
%error code
disp( [x y ]) %disp([x y er])
if y == 0.0
a=x;
b=x;
break
end
if l*y < 0.0
b=x;
else
a=x;
end
end
x=(a+b)/2;
e=(b-a)/2;
end
% Mbisect(inline('x^3 - 5','x'),1,2,10) "sample" (for this
activity set
% n=55)