Documentation

### This is machine translation

Mouseover text to see original. Click the button below to return to the English version of the page.

Note: This page has been translated by MathWorks. Click here to see
To view all translated materials including this page, select Country from the country navigator on the bottom of this page.

## Typical Linear Programming Problem

This example shows the solution of a typical linear programming problem. 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`

The problem in `sc50b.mat` has 48 variables, 30 inequalities, and 20 equalities.

Use `linprog` to solve the problem:

```options = optimoptions(@linprog,'Algorithm','dual-simplex','Display','iter'); [x,fval,exitflag,output] = ... linprog(f,A,b,Aeq,beq,lb,[],options);```

Because the iterative display was set using `optimoptions`, the results displayed are

```LP preprocessing removed 2 inequalities, 16 equalities, 16 variables, and 26 non-zero elements. Iter Time Fval Primal Infeas Dual Infeas 0 0.001 0.000000e+00 0.000000e+00 1.305013e+00 8 0.001 -1.587073e+02 3.760622e+02 0.000000e+00 33 0.001 -7.000000e+01 0.000000e+00 0.000000e+00 Optimal solution found.```

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 exitflag = 1 fval = -70 output = struct with fields: iterations: 33 constrviolation: 3.1264e-13 message: 'Optimal solution found.' algorithm: 'dual-simplex' firstorderopt: 2.3082e-14```

Watch now