【问题标题】:Matlab: fmincon converging to infeasible point, not meeting equality constraintMatlab:fmincon收敛到不可行点,不满足等式约束
【发布时间】:2018-07-12 02:21:31
【问题描述】:

我正在尝试使用 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

【问题讨论】:

    标签: matlab optimization


    【解决方案1】:

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

    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;
    

    使得x 的总和等于 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
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2022-11-10
      • 2020-09-10
      • 1970-01-01
      • 1970-01-01
      • 2018-10-12
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多