0% found this document useful (0 votes)
35 views2 pages

%% Graph Sketching: All All Long

The document uses MATLAB to apply the bisection method to find a root of the function f(x)=3x^3+x^2-x-5 between 1 and 2. It first plots the function to verify there is a root in the given interval. It then applies the bisection method in a while loop, iteratively narrowing the interval and checking the sign of the function at each midpoint until the interval is smaller than the specified tolerance of 0.5x10^(-p) where p is the desired number of correct digits. The output confirms there is a root in the given interval and finds the root xc to be 1.169725894927979.

Uploaded by

Md.Arifur Rahman
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
35 views2 pages

%% Graph Sketching: All All Long

The document uses MATLAB to apply the bisection method to find a root of the function f(x)=3x^3+x^2-x-5 between 1 and 2. It first plots the function to verify there is a root in the given interval. It then applies the bisection method in a while loop, iteratively narrowing the interval and checking the sign of the function at each midpoint until the interval is smaller than the specified tolerance of 0.5x10^(-p) where p is the desired number of correct digits. The output confirms there is a root in the given interval and finds the root xc to be 1.169725894927979.

Uploaded by

Md.Arifur Rahman
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

clear all

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 =

roots are in the bracket


xc =
1.169725894927979
>>

10
8
6
4
2
0
-2
-4
-6
-8
-10
-1.5

-1

-0.5

0.5

1.5

You might also like