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

不知表达的是否恰当。
比如:
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!