%  minimize/maximize the function    x^3-2*x^2+x  over I= [.25,1.25]
clf
clear all
numbpts=100;
t=linspace(.25,1.25,numbpts);    % 200 equally spaced points
f=t.^3-2*t.^2+t;         % evaluate the function
plot(t,f);
hold on
[minv,mini]=min(f);
[maxv,maxi]=max(f);
xlabel('x-value');
ylabel('f(x^3-2*x^2+x'); 
title('Find the Maximum and Minimum Using Discretization/Plotting');
plot(.25+(mini-1)/(numbpts-1),minv,'xg')
text(.25+(mini-1)/(numbpts-1)+.02,minv+.005,'Minimum')
disp(['minimum value is ',num2str(minv),' attained at ',...
                 num2str(.25+(mini-1)/(numbpts-1))]);
plot(.25+(maxi-1)/(numbpts-1),maxv,'db')
text(.25+(maxi-1)/(numbpts-1)+.04,maxv,'Maximum')
disp(['maximum value is ',num2str(maxv),' attained at ',...
                 num2str(.25+(maxi-1)/(numbpts-1))]);
