function Showfzero()
% Shows the different ways that fzero can be used.
clc

% Find a zero of f(x) = sin(x) in the bracketing interval [2,4]...

MyPi1 = fzero(@sin,[2 4])

fprintf('\n-------------------------------------------------------------\n')

% It is usually better to feed fzero a bracketing interval. But you can
% also use it to simply find a root near a specified value...

MyPi2 = fzero(@sin,3)

fprintf('\n-------------------------------------------------------------\n')

% The TolX parameter controls precision. Here we are asking for .01
% accuracy...

options = optimset('TolX',.01);
MyPi3 = fzero(@sin,3,options)

fprintf('\n-------------------------------------------------------------\n')

% Information about the iteration can be displayed as follows...
options = optimset('Display','iter');
MyPi = fzero(@sin,3,options);

fprintf('\n-------------------------------------------------------------\n')

% Or you can control the display of "what happened" yourself:

[xStar,fStar,EXITFLAG,OUTPUT] = fzero(@sin,3);
fprintf('xStar = %18.15f\n',xStar)
fprintf('f(xStar) = %18.15f\n',fStar)
fprintf('EXITFLAG = %1d\n',EXITFLAG)
fprintf('\nNumber of iterations to find a bracketing interval: %1d\n',OUTPUT.intervaliterations)
fprintf('\nNumber of iterations to find a root: %1d\n',OUTPUT.iterations)
fprintf('\nNumber of f-evaluations: %1d\n',OUTPUT.funcCount)
fprintf('\nAlgorithms used: %s\n',OUTPUT.algorithm)
fprintf('\nOverall message: %s\n',OUTPUT.message)