用MATLAB软件 如何编写 y=xsin(x)的峰值 的程序???

2025-04-12 08:55:54
推荐回答(1个)
回答1:

这样更好些,无需知道dy【如果很复杂,就显得很有用了】:

function hh
%global dy
y='x*sin(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)+x*cos(x)

Optimization terminated: first-order optimality is less than options.TolFun.

ans =

-4.9132 -2.0288 0 2.0288 4.9132