Typical Linear Programming Problem

This example shows the solution of a typical linear programming problem. The problem is

minxfTx such that {Axb,Aeqx=beq,x0.

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.

Use linprog to solve the problem:

options = optimoptions(@linprog,'Display','iter');
[x,fval,exitflag,output] = ...

Because the iterative display was set using optimoptions, 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+03 2.19e+01 1.91e+04 1.00e+02
  Iter    1:  1.15e+02 3.59e-15 3.62e+03 9.90e-01
  Iter    2:  1.32e-12 3.60e-15 4.32e+02 9.48e-01
  Iter    3:  3.82e-12 6.59e-15 7.78e+01 6.88e-01
  Iter    4:  2.96e-11 9.24e-16 2.38e+01 2.69e-01
  Iter    5:  1.37e-10 1.34e-15 5.05e+00 6.89e-02
  Iter    6:  6.85e-11 1.93e-16 1.64e-01 2.34e-03
  Iter    7:  4.30e-12 1.60e-16 1.09e-05 1.55e-07
  Iter    8:  1.25e-12 1.97e-16 1.09e-11 1.51e-13
Optimization terminated.

For this problem, the interior-point 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 =

fval =

output = 
         iterations: 8
          algorithm: 'interior-point-legacy'
       cgiterations: 0
            message: 'Optimization terminated.'
    constrviolation: 3.8369e-13
      firstorderopt: 2.7908e-13
Was this topic helpful?