a = 10;
x = -50:0.1:50;
y = 1./sqrt(a^2+(a+x).^2)+1./sqrt(a^2+(a-x).^2);
plot(x,y);
grid on;
yy = diff(y);
yy(yy<0) = -1;
yy(yy>0) = 1;
yyy = diff(yy);
mv = yyy(yyy~=0);
id = find(yyy~=0);
x0 = x(id);
y0 = y(id);
hold on;
for k = 1:length(id);
plot(x0(k),y0(k),'r.');
if mv(k)<0
s = '峰:';
else
s = '谷:';
end;
s = [s num2str(x0(k)) ',' num2str(y0(k))];
text(x0(k),y0(k),s);
end;
hold off;
你先求个1阶导数,找出f’(x)=0的根x1,x2,…,
然后再代入f(x)求出相应的y1,y2……,
最后把(x1,y1),(x2,y2),……标到图上。