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

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

Answers (1)

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 Comments

Both solutions (the one from "linprog" and the one from "fsolve") are not feasible since A*x-b > 0.
My guess is that the feasible region is empty.
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.
Lowering the constraint tolerance results in an empty x.

Sign in to comment.

Asked:

on 9 Dec 2024

Commented:

on 10 Dec 2024

Community Treasure Hunt

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

Start Hunting!