% discussed the various basic methods for finding the zero of a function,
% then finished with a look at FZERO, which is matlab's hybrid method for
% this. FZERO(fname,xo) works on the function specified by fname, and starts
% its search at xo.
% fname is either a string giving the name of a function m-file or is
% constructed by INLINE.
% Use this on the example given in the book:

>> decay = inline('10*exp(-3*t) +2*exp(-2*t)-6')
decay =
     Inline function:
     decay(t) = 10*exp(-3*t) +2*exp(-2*t)-6
>> fzero(decay,1)
Zero found in the interval: [0.094903, 1.64].
ans = 0.2462
>> format long
>> ans
ans = 0.24620829278302
%%  i.e., agrees to all digits with what's given in the book.

%%%  Try a looser tolerance:
>> fzero(decay,1,.001)
ans = 0.24554141090832

%% Also can get explicit info of how FZERO went about its search:
>> fzero(decay,1,.001,2)
 
 Func-count      x           f(x)         Procedure
    1               1      -5.23146        initial
    2        0.971716      -5.17162        search
    3         1.02828      -5.28685        search
    4            0.96      -5.14544        search
    5            1.04      -5.30857        search
    6        0.943431      -5.10695        search
    7         1.05657      -5.33812        search
    8            0.92      -5.04945        search
    9            1.08      -5.37771        search
   10        0.886863      -4.96153        search
   11         1.11314      -5.42956        search
   12            0.84      -4.82266        search
   13            1.16      -5.49538        search
   14        0.773726      -4.59284        search
   15         1.22627      -5.57533        search
   16            0.68      -4.18639        search
   17            1.32      -5.66665        search
   18        0.547452      -3.39562        search
   19         1.45255      -5.76243        search
   20            0.36      -1.63054        search
   21            1.64      -5.85175        search
   22       0.0949033       3.17656        search
 
   Looking for a zero in the interval [0.094903, 1.64]
 
   23        0.638537      -3.96978        interpolation
   24         0.33655      -1.33628        interpolation
   25        0.264997     -0.306924        interpolation
   26        0.245541     0.0111994        interpolation
   27        0.247541    -0.0223242        interpolation
Zero found in the interval: [0.094903, 1.64].
ans = 0.24554141090832


%% from the printout, we see that FZERO starts out by looking for an interval
%% with the given x0 as its center across which the function changes sign, hence
%% has to have a zero in. This is done during SEARCH.
%% Once it finds such an interval, it uses INTERPOLATION, i.e., a local model
%% of the function obtained by interpolation (e.g., as in Newton's method,
%% except that it does NOT use derivatives),
%% to pin down such a zero. Notice that, in this case, it quickly finds a
%% small enough interval that contains a zero.
%%
