ans=[];
for x=0:100;
y=sin(exp(x));
if(y>=05&&y>=sin(exp(x-1))&&y>=sin(exp(x+1)))
ans=[ans,y]
end
%ans里面的数就是大于等于05的峰值
这样更好些,无需知道dy如果很复杂,就显得很有用了:
function hh
%global dy
y='xsin(x)';
ezplot(y),grid
dy=diff(y)
x0=[-5 -2 0 2 5];
fsolve(@myfun,x0)
function f=myfun(x)
global dy
f=subs(dy);
结果:
dy =
sin(x)+xcos(x)
Optimization terminated: first-order optimality is less than optionsTolFun
ans =
-49132 -20288 0 20288 49132
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)