function showFzeroFx
% showFzeroFx  Watch convergence of fzero

  % -- Embedded test function
  function z = fx(x)
    z = 1.4 - 1./(x.^2.71 - 3) - 0.234*x.^1.2;
  end

% -- Plot f(x)
x = linspace(1.5,6);
plot(x,fx(x),'-');
hold('on')
ylim([-5,3])
grid('on')

% -- Use fzero with a single initial guess
fprintf('\nIterations with fzero and single initial guess\n\n')
fprintf('  x0         r          f(r)        iter   f.count\n')
for x0 = [1.55, 1.6, 2, 2.5, 3, 3.5, 4, 5]
  [r,~,~,output] = fzero(@fx,x0);
  fr = fx(r);
  plot(r,fr,'o');
  fprintf('%8.5f  %8.5f  %12.3e  %6d  %6d\n',x0,r,fr,output.iterations,output.funcCount)
end
hold('off')

% -- Use fzero with a bracket
fprintf('\nIterations with fzero and a bracket\n\n')
fprintf('  xleft   xright     r          f(r)        iter   f.count\n')
xb = [1.51 2; 4 5; 2 20];
for i = 1:size(xb,1)
  [r,~,~,output] = fzero(@fx,xb(i,:));
  fr = fx(r);
  fprintf('%7.2f %7.2f  %8.5f  %12.3e  %6d  %6d\n',xb(i,:),r,fr,output.iterations,output.funcCount)
end

end