Hello I am solving a lp problem and linprog shows the wrong answer. If I solve it with fmincon, I get the answer.
3 views (last 30 days)
Show older comments
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
%% fmincon
objfun= @(x) sum(x); % anonymous function
x0= [0;0;0;0];
[x,fval]= fmincon(objfun,x0,A,b,[],[],LB) % fmincon
0 Comments
Answers (1)
John D'Errico
on 9 Dec 2024
Edited: John D'Errico
on 9 Dec 2024
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
%% fmincon
objfun= @(x) sum(x); % anonymous function
x0= [0;0;0;0];
[x,fval]= fmincon(objfun,x0,A,b,[],[],LB) % fmincon
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
Steven Lord
on 9 Dec 2024
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.
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!