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

不知表达的是否恰当。
比如:
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 中查找有关 安装和许可简介 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!