引用matlab linprog的例子
http://www.mathworks.com/help/toolbox/optim/ug/linprog.html
Find x that minimizes
f(x) = –5*x1 – 4*x2 –6*x3,
subject to
x1 – x2 + x3 ≤ 20
3x1 + 2x2 + 4x3 ≤ 42
3x1 + 2x2 ≤ 30
0 ≤ x1, 0 ≤ x2, 0 ≤ x3.
%%%%%matlab linprog code
f = [-5; -4; -6];
A = [1 -1 1
3 2 4
3 2 0];
b = [20; 42; 30];
lb = zeros(3,1);
[x,fval,exitflag,output,lambda] = linprog(f,A,b,[],[],lb);
%%%%cvx toolbox
cvx_begin
variables x1 x2 x3;
minimize(-5*x1 - 4*x2 -6*x3 );
subject to
x1- x2 + x3 <= 20
3*x1 + 2*x2 + 4*x3 <= 42
3*x1 + 2*x2 <= 30
0 <= x1; 0 <= x2; 0 <= x3;
cvx_end
Calling sedumi: 6 variables, 3 equality constraints
For improved efficiency, sedumi is solving the dual problem.
------------------------------------------------------------
SeDuMi 1.21 by AdvOL, 2005-2008 and Jos F. Sturm, 1998-2003.
Alg = 2: xz-corrector, Adaptive Step-Differentiation, theta = 0.250, beta = 0.500
eqs m = 3, order n = 7, dim = 7, blocks = 1
nnz(A) = 11 + 0, nnz(ADA) = 9, nnz(L) = 6
it : b*y gap delta rate t/tP* t/tD* feas cg cg prec
0 : 4.35E+002 0.000
1 : 5.10E+001 1.44E+002 0.000 0.3314 0.9000 0.9000 1.84 1 1 3.0E+000
2 : 6.89E+001 3.89E+001 0.000 0.2695 0.9000 0.9000 2.50 1 1 4.9E-001
3 : 7.62E+001 9.96E+000 0.000 0.2563 0.9000 0.9000 0.99 1 1 1.4E-001
4 : 7.80E+001 4.04E-001 0.000 0.0405 0.9900 0.9900 1.03 1 1
iter seconds digits c*x b*y
4 0.1 15.7 7.8000000000e+001 7.8000000000e+001
|Ax-b| = 0.0e+000, [Ay-c]_+ = 5.3E-015, |x|= 1.9e+000, |y|= 1.5e+001
Detailed timing (sec)
Pre IPM Post
1.092E-001 1.404E-001 3.120E-002
Max-norms: ||b||=6, ||c|| = 42,
Cholesky |add|=0, |skip| = 0, ||L.L|| = 1.82429.
------------------------------------------------------------
Status: Solved
Optimal value (cvx_optval): -78