Use the Bisection Method to locate all solutions of followin
Solution
This question has multiple sub parts. I am going to solve the first part.
Part a.
In bisection method we need to assume a range where we think our root lies and then we need to go on and bisect the interval in the range to find the root.
let us take our equation
2x^3 -6x-1
Now let us take x=1
value of function will be 2-6-1=-5 (negative)
Now let us take x=2
value of function will be 2*8-6*2-1
=16-12-1=3 (positive)
So the root of the equation lies somewhere in between 1 and 2.
matlab code will be:
f=@(x) 2x^3-6x-1;
low=1;
high=2;
for i=1:100
result=(low+high)/2;
if f(result)>0
high=result;
else low=result;
end
end
low=1; high=2; p=result;
for i=1:100
result=(low+high)/2;
er(i)=f(result)-f(p);
if f(result)>0
high=result;
else low=result;
end
end
fprintf(\'Root of our equation 2x^3-6x-1 is %f\',result)
plot(er);
title(\'bisection method slot\')
xlabel(\'Iterations\')
ylabel(\'Margin of error\')
grid on;
Here low indicates 1 and high indicates 2.
