Please make sure that bracketing techinique is being used for narrowing down the
ID: 2080300 • Letter: P
Question
Please make sure that bracketing techinique is being used for narrowing down the range and bisection method to refine the answer!
Create MATLAB Scilab Bisection Method that finds all roots of the following equation (Hint: There are three, real number roots for the equation.), and compare your result with the result from MATLAB Scilab provided function. x3-3x3 10x 24, 30 You may want to start with the range big enough to cover where roots would exist (-100 to 100 would be a good start). Use Bracketing Technique to narrow the range down. Then, apply the Bisection method to refine the answerExplanation / Answer
1. Matlab script is given below:
%% Script to find the roots of given equation with bisection method
%% Initialization
low_range = -100;
high_range = 100;
p = [1 -3 -10 -24];
a = []; lowrange= []; highrange= [];root=[];
%% Bracketing and bisection
% Finding the inflexion points from bisection bracketing techniques
i=low_range;
j=high_range;
s = low_range:(high_range-low_range)/15:high_range;
for i=1:length(s) % Bisection into 10 equal partition
a = [a,polyval(p,s(i))];
end
% Find the number of sign changes in a
for i=2:length(a) % Bisection into 10 equal partition
if (a(i) * a(i-1) < 0)
lowrange = [lowrange,s(i-1)]
highrange = [highrange,s(i)]
end
end
%% Bisection method
for i=1:length(lowrange)
b = lowrange(i);
c = highrange(i);
j = 0;
while(1)
d = (b+c)/2;
j= j+1
if (abs(polyval(p,d)) <= 0.1)
display(polyval(p,d));
root = [root,d];
break;
elseif(polyval(p,d)*polyval(p,b) < 0)
c = d;
elseif(polyval(p,d)*polyval(p,c) < 0)
b = d;
end
end
end
display(root);
*****************************************************************
The answer obtained is
root =
5.5697
while the inbuild function of Matlab gives:
ans =
5.5693 + 0.0000i
-1.2847 + 1.6306i
-1.2847 - 1.6306i
Thus, the difference obtained is only 5.5697 - 5.5693 = 0.0004.