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
%% fmincon
objfun= @(x) sum(x); % anonymous function
x0= [0;0;0;0];
[x,fval]= fmincon(objfun,x0,A,b,[],[],LB) % fmincon
댓글 수: 0
답변 (1개)
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
%% 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
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.
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!