help linprog; LINPROG Linear programming. X=LINPROG(f,A,b) attempts to solve the linear programming problem: min f'*x subject to: A*x <= b x X=LINPROG(f,A,b,Aeq,beq) solves the problem above while additionally satisfying the equality constraints Aeq*x = beq. X=LINPROG(f,A,b,Aeq,beq,LB,UB) defines a set of lower and upper bounds on the design variables, X, so that the solution is in the range LB <= X <= UB. Use empty matrices for LB and UB if no bounds exist. Set LB(i) = -Inf if X(i) is unbounded below; set UB(i) = Inf if X(i) is unbounded above. X=LINPROG(f,A,b,Aeq,beq,LB,UB,X0) sets the starting point to X0. This option is only available with the active-set algorithm. The default interior point algorithm will ignore any non-empty starting point. X=LINPROG(f,A,b,Aeq,beq,LB,UB,X0,OPTIONS) minimizes with the default optimization parameters replaced by values in the structure OPTIONS, an argument created with the OPTIMSET function. See OPTIMSET for details. Options are Display, Diagnostics, TolFun, LargeScale, MaxIter. Currently, only 'final' and 'off' are valid values for the parameter Display when LargeScale is 'off' ('iter' is valid when LargeScale is 'on'). [X,FVAL]=LINPROG(f,A,b) returns the value of the objective function at X: FVAL = f'*X. [X,FVAL,EXITFLAG] = LINPROG(f,A,b) returns an EXITFLAG that describes the exit condition of LINPROG. Possible values of EXITFLAG and the corresponding exit conditions are 1 LINPROG converged to a solution X. 0 Maximum number of iterations reached. -2 No feasible point found. -3 Problem is unbounded. -4 NaN value encountered during execution of algorithm. -5 Both primal and dual problems are infeasible. -7 Search direction became too small; no further progress can be made. [X,FVAL,EXITFLAG,OUTPUT] = LINPROG(f,A,b) returns a structure OUTPUT with the number of iterations taken in OUTPUT.iterations, the type of algorithm used in OUTPUT.algorithm, the number of conjugate gradient iterations (if used) in OUTPUT.cgiterations, and the exit message in OUTPUT.message. [X,FVAL,EXITFLAG,OUTPUT,LAMBDA]=LINPROG(f,A,b) returns the set of Lagrangian multipliers LAMBDA, at the solution: LAMBDA.ineqlin for the linear inequalities A, LAMBDA.eqlin for the linear equalities Aeq, LAMBDA.lower for LB, and LAMBDA.upper for UB. NOTE: the LargeScale (the default) version of LINPROG uses a primal-dual method. Both the primal problem and the dual problem must be feasible for convergence. Infeasibility messages of either the primal or dual, or both, are given as appropriate. The primal problem in standard form is min f'*x such that A*x = b, x >= 0. The dual problem is max b'*y such that A'*y + s = f, s >= 0. Reference page in Help browser doc linprog % 1. defining an optimization problem % to maximize profit, we would like to determine % the values of x and y x = 0:80; y1 = max(75 - x,0); % constraint on available land y2 = max((4000-110*x)/30,0); % storage y3 = max((15000-120*x)/210,0); % expenses ytop = min([y1; y2; y3]); area(x,ytop) % feasible region % we can solve the optimization problem % graphically hold on [u v] = meshgrid(0:80 ,0:80); contour(u,v,143*u + 60*v); % plots the profit % the contour lines give the lines of equal % profit, the solution to our optimization % problem occurs at the corner of the feasible % region where the line of highest profit meets % 2. using linprog f = [-143 -60]; % target A = [120 210; 110 30; 1 1; -1 0; 0 -1]; % the matrix a contains in its three rows % the original constraints; the last two % rows indicate that x and y must be >= 0 b = [15000; 4000; 75; 0; 0]; % right hand side % now we defined the following problem: % min f'*x subject to A*x <= b linprog(f,A,b) Optimization terminated. ans = 21.8750 53.1250 % the answer gives us the values for x and y % for which the profit is maximized: sol = ans; -f*sol ans = 6.3156e+003 A*sol ans = 1.0e+004 * 1.3781 0.4000 0.0075 -0.0022 -0.0053 format long b - A*sol ans = 1.0e+003 * 1.21875000063205 0.00000000000707 0.00000000000263 0.02187500000090 0.05312499999648 diary off