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!