Matlab:fmincon收敛到不可行点,不满足等式约束



我正在尝试使用fmincon来优化x,以便最小化R*x,而x可以是介于0和1.5之间的值,并且sum(x) = 3

R = transpose([6 6 6 6 6 6 6 9 9 9 9 13 13 13 13 9 9 9 9 6 6 6 6 6]);
x0 = zeros(24,1);
f='0';
for j=1:24
s='%d*x(%d)';
s=sprintf(s,R(j),j);
g='%s+%s';
f=sprintf(g,f,s);
end
A = ones(2,24);
A(2,:) = -1;
b = [1.5; 0];    % Want x's to be between 0 and 1.5
Aeq = ones(1,24);
beq = [3];
%Bounds
lb = zeros(24,1);
ub = ones(24,1);
x = fmincon(f, x0, A, b,Aeq, beq,lb,ub);

我希望x的和等于3(试图用等价矩阵Aeq和beq来证明这一点(。当我运行代码时显示了以下错误:

收敛到一个不可行点

需要注意的是,此代码显示sum(x) = 2.25而不是sum(x) = 3

首先,您的函数定义可以缩短为:

R = [6 6 6 6 6 6 6 9 9 9 9 13 13 13 13 9 9 9 9 6 6 6 6 6];
f = @(x)R*x;

其次,您的初始点x0不满足您的约束,所以让我们将其更改为:

x0 = zeros(24,1)+3/24;

使得CCD_ 5的和等于3。

接下来,由于x上有一个恒定的上界和下界,所以不需要使用Ab矩阵,所以我们去掉它们,用空矩阵[]代替它们。我们将只依赖lbub

lb = zeros(24,1);
ub = 1.5*ones(24,1);

最后,我们使用启动fmincon

x = fmincon(f, x0,[],[],Aeq, beq,lb,ub)
Optimization completed because the objective function is non-decreasing in 
feasible directions, to within the default value of the optimality tolerance,
and constraints are satisfied to within the default value of the constraint tolerance.
<stopping criteria details>

x =
0.2500
0.2500
0.2500
0.2500
0.2500
0.2500
0.2500
0.0000
0.0000
0.0000
0.0000
0.0000
0.0000
0.0000
0.0000
0.0000
0.0000
0.0000
0.0000
0.2500
0.2500
0.2500
0.2500
0.2500

最新更新