clear all;close all;
f = @(x) sin(15.*x).*x.^2;
h=10^-5;
x=-1:h:1;
N=size(x,2);
y=f(x);
der=diff(y)./h;
prod=der(1,1:N-2).*der(1,2:N-1);
mm=find(prod<0);
subplot(2,1,1);
plot(x(1,2:N),der,'b-',x,0.*x,'g-');
legend('numerical derivative');
subplot(2,1,2);
plot(x,f(x),'b-',x(mm),f(x(mm)),'go');
legend('original function','extrema');