Hello I am solving a lp problem and linprog shows the wrong answer. If I solve it with fmincon, I get the answer.

5 ビュー (過去 30 日間)
H= @(i,j) exp(-abs(i-j)); % anonymous function
m= 4; noise_pow= 1e-9;
g= [15; 12; 9; 6];
A= [-H(1,1), g(1)*H(2,1), g(1)*H(3,1), g(1)*H(4,1);...
g(2)*H(1,2), -H(2,2), g(2)*H(3,2), g(2)*H(4,2);...
g(3)*H(1,3), g(3)*H(2,3), -H(3,3), g(3)*H(4,3);...;
g(4)*H(1,4), g(4)*H(2,4), g(4)*H(3,4),-H(4,4)];
b= -g*noise_pow;
LB= [0;0;0;0];
%% linprog
c= [1 1 1 1];
[x,fval]= linprog(c,A,b,[],[],LB) % linprog
Optimal solution found.
x = 4×1
0 0 0 0
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
fval = 0
%% fmincon
objfun= @(x) sum(x); % anonymous function
x0= [0;0;0;0];
[x,fval]= fmincon(objfun,x0,A,b,[],[],LB) % fmincon
Local minimum found that satisfies the constraints. Optimization completed because the objective function is non-decreasing in feasible directions, to within the value of the optimality tolerance, and constraints are satisfied to within the value of the constraint tolerance.
x = 4×1
1.0e-08 * 0.1033 0.0393 0.0370 0.1526
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
fval = 3.3217e-09

回答 (1 件)

John D'Errico
John D'Errico 2024 年 12 月 9 日
編集済み: John D'Errico 2024 年 12 月 9 日
H= @(i,j) exp(-abs(i-j)); % anonymous function
m= 4; noise_pow= 1e-9;
g= [15; 12; 9; 6];
A= [-H(1,1), g(1)*H(2,1), g(1)*H(3,1), g(1)*H(4,1);...
g(2)*H(1,2), -H(2,2), g(2)*H(3,2), g(2)*H(4,2);...
g(3)*H(1,3), g(3)*H(2,3), -H(3,3), g(3)*H(4,3);...;
g(4)*H(1,4), g(4)*H(2,4), g(4)*H(3,4),-H(4,4)];
b= -g*noise_pow;
LB= [0;0;0;0];
%% linprog
c= [1 1 1 1];
[x,fval]= linprog(c,A,b,[],[],LB) % linprog
Optimal solution found.
x = 4×1
0 0 0 0
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
fval = 0
%% fmincon
objfun= @(x) sum(x); % anonymous function
x0= [0;0;0;0];
[x,fval]= fmincon(objfun,x0,A,b,[],[],LB) % fmincon
Local minimum found that satisfies the constraints. Optimization completed because the objective function is non-decreasing in feasible directions, to within the value of the optimality tolerance, and constraints are satisfied to within the value of the constraint tolerance.
x = 4×1
1.0e-08 * 0.1033 0.0393 0.0370 0.1526
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
fval = 3.3217e-09
You get a SLIGHTLY DIFFERENT answer from linprog, versus fmincon. The fmincon result is the same, just within the tolerances you specified, so it stopped when it got close.
Is one of the better than the other? Absolutely YES. The objective function value for the linprog solution is LOWER than that from fmincon. ergo, linprog did a better job of solving the problem, finding the exact solution to the problem in this case.
Is all zeros an entirely valid solution to the problem? YES!
Case closed. Linprog was right, you are wrong. At least in terms of the problem you posed. ;-)
  3 件のコメント
Steven Lord
Steven Lord 2024 年 12 月 9 日
Is the linprog solution feasible to within the default ConstraintTolerance specified on its documentation page? That noise_pow term is pretty small, smaller than the constraint tolerances.
Torsten
Torsten 2024 年 12 月 10 日
Lowering the constraint tolerance results in an empty x.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeSolver Outputs and Iterative Display についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by