function  findDamp
% findDamp  Use fzero to find optimum damping ratio.  Problem 6-21

% --- Plot the f(xi) function to visually locate roots
xmin = 0;  xmax = 1;
x = linspace(xmin,xmax);
plot(x,damp(x))

% --- Adjust options that control fzero.  Options are (key,value)
%     pairs.  The key is always a string.  The value may be another
%     string or a numeric value.  In the following, we set the
%     'Display' option to 'iter' (key = 'Display', value = 'iter'),
%     which means that fzero will print the results of each iteration.
%     The 'TolX' option is set to 5e-9 (key = 'TolX', value = 5e-9)
%     to adjust the convergence tolerance on the size of the bracket
%     to 5e-9.
opts = optimset('Display','iter','TolX',5e-9);

% --- Call fzero with an initial guess of 0.5 and the opts struct
%     created by optimset.  Evaluate f(xi) at the root returned by fzero
r1 = fzero('damp',0.5,opts)
fr1 = damp(r1);

% --- Call fzero with an initial guess of 0.9
r2 = fzero('damp',0.9,opts);
fr2 = damp(r2);

% --- Add '*' symbols to the plot where fzero found roots, and
%     add a dashed horizontal line through f(xi) = 0
hold('on');
plot([r1 r2],[fr1 fr2],'r*',[xmin xmax],[0 0],'k--')