新手求助!根据求函数最大值来确定其中的变量。

不知表达的是否恰当。
比如:
x是一个矩阵,x=[0:pi/36:pi/2];
z=sin(x+y);
我想求最大值z,并在z为最大值的基础上,对应每一个x的y值是多少?
y的范围就定为(0,pi/2)吧
急求,这样得到的y也是对应于x的矩阵。

 Réponse acceptée

voperop
voperop le 17 Nov 2022

0 votes

先建立一个file文件
输入
function f=myfun(y,x)
f=-sin(x+y);
然后在命令窗口里,写上
x=[0:pi/36:pi/2];
for i=1:size(x,2),
[y(i,1),fval(i,1),exitflag(i,1)]=fminbnd(@(y) myfun(y,x(1,i)),0,pi/2);
end
结果如图:

Plus de réponses (0)

Catégories

En savoir plus sur App 构建 dans Centre d'aide et File Exchange

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!