clear; close all;
%
x = 0:.2:20; y = bessel(1,x); h = plot(x,y); axis([-1 21 -.5 0.7]);
legend(h,'\it f(x)');
[f,ix] = max(y);
text(x(ix),f,'  \leftarrow Global max','HorizontalAlignment','left');
[f,ix] = min(y);
text(x(ix),f,'Global min \rightarrow  ','HorizontalAlignment','right');
%
mni = []; mnv = []; mxi = []; mxv = [];
for i = ix+1:length(x)
   if i < length(x) & y(i)>max(y(i-1),y(i+1))
      mxi = [mxi; i]; mxv = [mxv; y(i)];
    end
   if i < length(x) & y(i)<min(y(i-1),y(i+1))
      mni = [mni; i]; mnv = [mnv; y(i)];
    end
end
for i=1:length(mxi)
   text(x(mxi(i)),mxv(i),'  \leftarrow Local max',...
   'HorizontalAlignment','left');  
end
for i=1:length(mni)
   text(x(mni(i)),mnv(i),'Local min \rightarrow  ',...
   'HorizontalAlignment','right');  
end
%print -deps minmax.eps




