| Products & Services | Industries | Academia | Support | User Community | Company |
| Download Product Updates | | | Get Pricing | | | Trial Software |
| Documentation → Optimization Toolbox |
| Contents | Index |
| Learn more about Optimization Toolbox |
| On this page… |
|---|
Example: Linear Programming with Equalities and Inequalities Example: Linear Programming with Dense Columns in the Equalities |
The problem is

You can load the matrices and vectors A, Aeq, b, beq, f, and the lower bounds lb into the MATLAB workspace with
load sc50b
This problem in sc50b.mat has 48 variables, 30 inequalities, and 20 equalities.
You can use linprog to solve the problem:
[x,fval,exitflag,output] = ...
linprog(f,A,b,Aeq,beq,lb,[],[],optimset('Display','iter'));Because the iterative display was set using optimset, the results displayed are
Residuals: Primal Dual Duality Total
Infeas Infeas Gap Rel
A*x-b A'*y+z-f x'*z Error
---------------------------------------------------
Iter 0: 1.50e+003 2.19e+001 1.91e+004 1.00e+002
Iter 1: 1.15e+002 3.18e-015 3.62e+003 9.90e-001
Iter 2: 8.32e-013 1.96e-015 4.32e+002 9.48e-001
Iter 3: 3.47e-012 7.49e-015 7.78e+001 6.88e-001
Iter 4: 5.66e-011 1.16e-015 2.38e+001 2.69e-001
Iter 5: 1.13e-010 3.67e-015 5.05e+000 6.89e-002
Iter 6: 5.03e-011 1.21e-016 1.64e-001 2.34e-003
Iter 7: 5.75e-012 1.12e-016 1.09e-005 1.55e-007
Iter 8: 8.08e-014 5.67e-013 1.09e-011 3.82e-012
Optimization terminated.For this problem, the large-scale linear programming algorithm quickly reduces the scaled residuals below the default tolerance of 1e-08.
The exitflag value is positive, telling you linprog converged. You can also get the final function value in fval and the number of iterations in output.iterations:
exitflag =
1
fval =
-70.0000
output =
iterations: 8
algorithm: 'large-scale: interior point'
cgiterations: 0
message: 'Optimization terminated.'The problem is
![]()
You can load the matrices and vectors Aeq, beq, f, lb, and ub into the MATLAB workspace with
load densecolumns
The problem in densecolumns.mat has 1677 variables and 627 equalities with lower bounds on all the variables, and upper bounds on 399 of the variables. The equality matrix Aeq has dense columns among its first 25 columns, which is easy to see with a spy plot:
spy(Aeq)

You can use linprog to solve the problem:
[x,fval,exitflag,output] = ...
linprog(f,[],[],Aeq,beq,lb,ub,[],optimset('Display','iter'));Because the iterative display was set using optimset, the results displayed are
Residuals: Primal Dual Upper Duality Total
Infeas Infeas Bounds Gap Rel
A*x-b A'*y+z-w-f {x}+s-ub x'*z+s'*w Error
-------------------------------------------------------------
Iter 0: 1.67e+003 8.11e+002 1.35e+003 5.30e+006 2.92e+001
Iter 1: 1.37e+002 1.33e+002 1.11e+002 1.27e+006 2.48e+000
Iter 2: 3.56e+001 2.38e+001 2.89e+001 3.42e+005 1.99e+000
Iter 3: 4.86e+000 8.88e+000 3.94e+000 1.40e+005 1.89e+000
Iter 4: 4.24e-001 5.89e-001 3.44e-001 1.91e+004 8.41e-001
Iter 5: 1.23e-001 2.02e-001 9.97e-002 8.41e+003 5.79e-001
Iter 6: 3.98e-002 7.91e-002 3.23e-002 4.05e+003 3.52e-001
Iter 7: 7.25e-003 3.83e-002 5.88e-003 1.85e+003 1.85e-001
Iter 8: 1.47e-003 1.34e-002 1.19e-003 8.12e+002 8.52e-002
Iter 9: 2.52e-004 3.39e-003 2.04e-004 2.78e+002 2.99e-002
Iter 10: 3.46e-005 1.08e-003 2.81e-005 1.09e+002 1.18e-002
Iter 11: 6.96e-007 2.00e-012 5.64e-007 1.48e+001 1.62e-003
Iter 12: 9.35e-007 6.98e-013 3.18e-008 8.32e-001 9.09e-005
Iter 13: 1.14e-007 2.03e-012 3.86e-009 7.26e-002 7.94e-006
Iter 14: 1.92e-010 1.16e-012 6.55e-012 1.11e-003 1.21e-007
Iter 15: 1.05e-013 2.50e-012 3.71e-013 8.62e-008 9.42e-012
Optimization terminated.
You can see the returned values of exitflag, fval, and output:
exitflag =
1
fval =
9.1464e+003
output =
iterations: 15
algorithm: 'large-scale: interior point'
cgiterations: 0
message: 'Optimization terminated.'
This time the algorithm detects dense columns in Aeq are detected. Therefore, instead of using a sparse Cholesky factorization, linprog tries to use the Sherman-Morrison formula to solve a linear system involving Aeq*Aeq'. If the Sherman-Morrison formula does not give a satisfactory residual, the algorithm uses a solution process based on LDL factorization. See Main Algorithm.
![]() | Linear Programming | Quadratic Programming | ![]() |

Includes the most popular MATLAB recorded presentations with Q&A sessions led by MATLAB experts.
| © 1984-2009- The MathWorks, Inc. - Site Help - Patents - Trademarks - Privacy Policy - Preventing Piracy - RSS |