You are on page 1of 1

% Problem 4a

x=linspace(-10,10);
plot((x.^3)-5.*x+sin(x*(180/pi)));
grid;
% Problem 4b

x_right=3;
x_left=2;
x_new=0;
dum=0;
stop=10^-7;
error_true=100;
count=0;
while error_true > stop

x_new=(x_left+x_right)/2;
if ((x_new.^3)-5.*x_new+sin(x_new))*((x_right.^3)-5.*x_right+sin(x_right))<0

x_left=x_new;
error_true = abs(((x_new-dum)/x_new)*100);
end

if((x_new.^3)-5.*x_new+sin(x_new))*((x_left.^3)-5.*x_left+sin(x_left))<0
x_right=x_new;
error_true = abs(((x_new-dum)/x_new)*100);
end
dum=x_new;

count=count + 1;

end
disp (count)
format long
disp(x_new)

You might also like