You are on page 1of 2

PROGRAMME

f = @ (x) (x^3+4*x^2-10);
x = 0:0.5:3;
y = x.^3+4*x.^2-10;
plot(x,y)
a = 0;
b = 5;
n = 10;
if f(a)*f(b)<0
for i=1:n
c=(a+b)/2;
fprintf('x%d=%.4f\n',i,c)
if f(a)*f(c)<0
b=c;
elseif f(b)*f(c)<0
a=c;
end
end
else
disp('No root between given brackets')
end
grid on

%%RESULT%%

x1=2.5000
x2=1.2500
x3=1.8750
x4=1.5625
x5=1.4062
x6=1.3281
x7=1.3672
x8=1.3477
x9=1.3574
x10=1.3623

1
Published with MATLAB® R2023a

You might also like