Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Create a MATLAB code for the bisection method. Assuming that your original funct

ID: 673594 • Letter: C

Question

Create a MATLAB code for the bisection method. Assuming that your original function is given by the function file, say, "t. m," create another function file (say, "bisect.m") which will call the file t.m in order to compute values of your function t(x). The function file bisect.m should bear three parameters a, b, tol, i.e., indication of the left and right ends of the interval where the function t(x) is defined, and the tolerance which we wish to use to approximate our root. Assume also that the function t(x) has a unique zero in the interval [a, b] and that t(a)t(b)

Explanation / Answer

% matlab code for bisection method
% coefficient=vector having coefficients of polynomial
% a,b=interval having at least 1 zero
% tol=amount of the stopping tolerance. The bisection should be stopped if the interval having 0 has width less than 2 times tol

function tx = bisection(coefficient, a, b, tol)
xl=a;
xh=b;
pl=polynomialvalue(coefficient,xl);
ph=polynomialvalue(coefficient,xh);
while xh-xl>2*tol,
    xm=(xl+xh)/2;
    pm=polynomialvalue(coeffiecient,xm);
    if pm*pl<0,
       xh=xm;
       ph=pm;
    elseif pm*ph<0,
       xl=xm;
       pl=pm;
    else
       xl=xm;
       xh=xm;
    end
end
tx=[xl,xh];   %interval that contains a zero