请教【三元函数求最小值问题】,多谢了。

12 次查看(过去 30 天)
norip
norip 2022-11-19
求上式最小值和对应的x1、x2、x3,其中n是奇数,0<x1<x2<0.5,x3>0。
因为平时很少用MATLAB,现在完全不知道从何做起,希望高手能给予指点,多谢了。

采纳的回答

basin
basin 2022-11-19
这里给你编一个吧。仅供参考
function y=optfun(x)
%需要优化的目标函数
% by karl
n=[3:2:19];%奇数
for i=1:length(n)
y1=((cos(n(i)*x(1)*pi)+x(3)*cos(n(i)*x(2)*pi))/n(i))^2;
end
y2=sqrt(sum(y1));
y=y2/(cos(x(1)*pi)+x(3)*cos(x(2)*pi));
上面这个函数,你建立一个文件,单独保存下来。不要改名称
如果你看到的最优解为0,0,0.99,你用format long来查看。
clc;clear;
%约束条件设置
A=[1,-1,0];
b=-1e-15;%这个取决于你的精度。如果你想更精确,可以把-1e-15换成-realmin
lb=zeros(3,1);
ub=[0.5;0.5];
x0=[0.25;0.26;1];
%优化
[x,fval,exitflag,output,lambda]=fmincon(@optfun,x0,A,b,[],[],lb,ub);
这样,x就是你想找到的自变量,fval就是目标函数的最小值。最小值的精度为1e-6.你想更精确,修改优化参数。这个你查看fmincon函数的详细说明。
  1 个评论
Cassandra Myers
Cassandra Myers 2023-3-2
I tried your way and it worked fine. For that thank you, try wordle, it will definitely help you.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Database Toolbox 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!