function ShowGlobalNewton()
% Illustrates how Newton's method can jump around before it
% converges.
close all
clc
% Display MyF...
L = -1;
R = 12;
N = 500;
xVals = linspace(L,R);
yVals = MyF(xVals);
plot([L R],[0 0],'k',xVals,yVals)
axis([L R -1.5 1.5])
axis manual
set(gcf,'position',[100,200,800,600])
shg
title('MyF(x) = exp(-x/10).*sin(2*x)','fontsize',16)
xlabel('Click in a bracketing interval','fontsize',16)
hold on
[a,y] = ginput(1);
plot(a,0,'.r','Markersize',25)
[b,y] = ginput(1);
plot(b,0,'.r','Markersize',25)
plot([a b],[0 0],'r','linewidth',2)
xlabel(' ')

tolx = .0000000001;
tolf = .0000000001;
nEvalsMax = 100;
[xStar,fStar,nEvals,aF,bF] = GlobalNewton(@MyF,@derMyF,a,b,tolx,tolf,nEvalsMax);
plot(xStar,0,'.g','Markersize',25)

function y = MyF(x)
y = exp(-x/10).*sin(2*x);

function yp = derMyF(x)
yp = -exp(-x/10).*sin(2*x)/10 + 2*exp(-x/10).*cos(2*x);