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

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

 採用された回答

voperop
voperop 2022 年 11 月 17 日

0 投票

先建立一个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
结果如图:

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File Exchange安装和许可简介 についてさらに検索

タグ

質問済み:

2022 年 11 月 17 日

回答済み:

2022 年 11 月 17 日

Community Treasure Hunt

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

Start Hunting!