FUNCTION REFERENCE

linprog

Minimize a linear objective with linear constraints and bounds.

Minimize a linear objective with linear constraints and bounds.

Syntax

[x, fval, exitflag, output, lambda] = linprog(f, A, b, Aeq, beq, lb, ub, options)

Syntax

x = linprog(problem)

Minimizes f'*x with A*x <= b, Aeq*x = beq and lb <= x <= ub. Arguments

after f can be omitted; [] removes a constraint. Empty f requests feasibility,

with the variable count inferred from constraints or bounds. Problem fields are

f, Aineq, bineq, Aeq, beq, lb, ub, options (A,b are aliases).

Uses a homogeneous self-dual primal-dual interior-point embedding with

Mehrotra predictor-corrector steps. Presolve eliminates fixed variables and

uses rank-revealing QR to drop dependent equality rows. Free variables are

kept directly with regularisation.

Finite boxes without coupled rows are solved directly by choosing endpoints.

Exitflag: 1 convergence, 0 iteration limit or numerical breakdown, -2 verified

primal infeasibility, -3 verified unbounded recession direction, -4 nonfinite

iterate, -5 both primal and dual infeasibility certificates verified.

For -2, -3, -4 and -5, x and fval are []; all lambda fields are [].

On a limit or numerical failure, a finite feasible iterate is returned if

available; otherwise the same empty outputs are returned. Recession rays stay

internal and are never returned as x.

output has iterations, funcCount (zero), constrviolation, stepsize,

firstorderopt, algorithm and message. Options include Display, MaxIterations,

OptimalityTolerance, ConstraintTolerance (TolCon).

Primal feasibility uses ConstraintTolerance; dual residuals and the duality

gap use OptimalityTolerance, with problem scaling. Looser stopping tolerances

can reduce iterations. Certificate checks may use tighter internal tolerances.

The Lagrangian is L = objective + lambda_g'*g + lambda_h'*h. Inequalities

are g <= 0: A*x-b, lb-x, x-ub and c(x); equalities are Aeq*x-beq and ceq(x).

All inequality multipliers are nonnegative; equality multipliers are signed.

lambda fields are ineqlin, eqlin, lower, upper, ineqnonlin and eqnonlin.

SciPy sign table: linprog ineqlin/eqlin marginals are negated; lower marginals

keep their sign; upper marginals are negated. SLSQP multipliers for -g >= 0

keep their sign, and those for h = 0 are negated. lsqlin uses the half-squared

residual objective for its multipliers.

All five solvers accept scalar problem structures and [] placeholders.

Algorithm names 'interior-point', 'interior-point-legacy', 'dual-simplex',

'sqp', 'sqp-legacy' and 'active-set' map to the documented implementation;

output.message notes a mapping. Other names are errors. Bounds default to free.

User-array limits: 2000 unknowns, 4000 total constraint/data rows,

4000000 entries per dense matrix. Generated bound rows and residual variables

use separately bounded internal workspaces. Cancellation is checked in solver loops.

Differences from MATLAB: dense real arrays only. There is no simplex: on LPs

with several optima the result can be a non-vertex point. Algorithm names are

aliases; no sparse solver or simplex crossover.

Example

[x,f] = linprog([-3;-2],[1 1;1 0;0 1],[4;2;3],[],[],[0;0])

Example

p=struct('f',-1,'Aineq',1,'bineq',2); x=linprog(p)

These are the engine’s help pages. Each page keeps its compatibility notes. File operations are unavailable in the browser.