%% Graph Sketching: All All Long
%% Graph Sketching: All All Long
close all
clc
format long
%% graph sketching
x=-5:.001:5;
f=3*x.^3+x.^2-x-5;
plot(x,f)
ylim([-10 10])
grid on
%% interval for x to apply the IVT
a=1; % starting value of the interval
b=2; %ending value of the interval
p=6; % number of currect digit
f=@(x)(3*x.^3+x.^2-x-5);% calling function
fa=f(a);
fb=f(b);
%% Justification
if fa*fb<0
'roots are in the bracket'
else
'roots are not in the bracket'
end
%% bisection method
while (b-a)/2 > 0.5*10^(-p)
c =(a+b)/2;
fc=f(c);
if f(c)==0
'c is a root',c
break
else
if sign(fa*fc)<0
b=c;
fb=fc;
else
a=c;
fa=fc;
end
end
end
xc=(a+b)/2
ans =
10
8
6
4
2
0
-2
-4
-6
-8
-10
-1.5
-1
-0.5
0.5
1.5