USE MATLAB AND SEND ME THE CODE HAVE TO HAVE THE CODE Find t
USE MATLAB AND SEND ME THE CODE HAVE TO HAVE THE CODE.
Find the roots of f(x) = -12 - 21x + 18x^2 - 2.75x^3. Use YOUR Bisection function AND YOUR False-position function with a stopping criterion es = l.e-8 for EACH of the following intervals: (a) Use initial guesses of x_1 = - 1 and x_u = 2. (b) Use initial guesses of x_1 = 0 and x_u = 4. (c) Use initial guesses of x_1 = -1 and x_u = 5. (d) Plot the function and discuss your observations and similarities differences in results (a)-(c) between the two methods. Comment in detail on convergence, speed (i.e. number of iterations), and accuracy of each method and explain similarities and differences.Solution
function p = bisection(a,b)
% Give initial guesses.
% Solves it by method of bisection.
f =@(x) -12-21*x+18*x^2-2.75*x^3;
if f(a)*f(b)>0
disp(\'Wrong choice\')
else
p = (a + b)/2;
err = abs(f(p));
while err > 1e-8
if f(a)*f(p)<0
b = p;
else
a = p;
end
p = (a + b)/2;
err = abs(f(p));
end
end
bisection(-1,2)
ans =
-0.4147
>> bisection(0,4)
ans =
2.2198
>> bisection(-1,5)
ans =
-0.4147
function p = falseposition(a,b)
tolerance=1e-8;
f =@(x) -12-21*x+18*x^2-2.75*x^3;
for i=0:inf
d= b - (f(b)* (b-a)/(f(b)-f(a)))
c = f(d)
absolute_c= abs(c);
if absolute_c < tolerance
break
end
if f(a)*c <0
b=d;
continue
else
a=d;
continue
end
end
i

