2. Read doc fzero to learn how to use MATLAB's fzero routine. This is an accelerated version of bisection called the Brent-Dekker algorithm, not covered in the textbook (but referenced briefly in §2.7.)
(a) Try it out on the previous example: fzero(@sin, [a b]), replacing a and b with the ones you used. How many digits are correct?
(b) Try out fzero's Display option:
fzero(@tan, [1 2])
fzero(@tan, [1 2], optimset('Display', 'iter'))
(Note: the second command may help you complete Question 1(b).)
(c) Try out fzero's PlotFcns option:
fzero(@sin, [3 4], optimset('PlotFcns', @optimplotfval));
(d) Add an optional sixth input argument to your function bisection, so that
bisection(f, a, b, tol, maxits, 'iter')
outputs all approximations to the root, not just the last one -- see Part (b) -- and so that
bisection(f, a, b, tol, maxits, 'plot')
generates a plot of the iteration history -- see Part (c). (You'll need to use varargin and strcmp.)