Let fx x 2x 12 xx 13x 2 Without running your code analy
Let f(x) = (x + 2)(x + 1)^2 x(x - 1)^3(x - 2). Without running your code, analytically determine all of the roots of this function. Put your answer in a comment. To which root does the Bisection method converge when applied on the following intervals? Use a tolerance of 10^-4. There may be more than one root within each interval, so you will need to run your code to see which root the method converges to! Call your bisection.m function from within your Lab6. m function 4 times. You may do separately or in a loop. [-1.5, 2.5] [-0.5, 2.4] [-0.5, 3] [-3, -0.5] % This is bisection template function [p, steps, error) = bisection_template(f, a, b, tol) %function returns an estimate for the root, p, and requires %inputs of the function, g, the interval endpoints, a and b, %the desired tolerance for the error, tol, and the maximum %number of iterations, nmax. %evaluate math function at a %initialize error %initialize step counter while error>tol %increment counter %calculate p, the midpoint of a and b %evaluate math function at p if sign(fpn)*sign(fa)==0 %check sign of product of f(pn) and f(a) %If product = 0 then landed on root elseif (sign(fpn)*sign(fa)
Solution
f=@(x) (x+1)2(x+2)x(x-1)3(x-2)
a=1;
b=2;
for i=1:100
c=(a+b)/2;
if f(c)>0
b=c;
else a=c;
end
end
a=1; b=2; p=c;
for i=1:100
c=(a+b)/2;
er(i)=f(c)-f(p);
if f(c)>0
b=c;
else a=c;
end
end
fprintf(\'Root of given equation is %f\',c)
plot(er);
title(\'Plot of error\')
xlabel(\'Number of iterations\')
ylabel(\'Error\')
grid on;
the roots of the function is x7-6x5-4x4+9x3+12x2+4x
2) root x=7 ,x7-6x5-4x4+9x3+12x2+4x with the tolerance 10-4
End points of the interval: a = 7.5, b = 8
Error tolerance: t = 10-4
Substituting the values of a0 and b0 in the above formula, we get
N >log10(1.5) log10(10-4)log102
=log10(1.5) + 7log102
= 10.5507.
