赞
踩
(1) linprog函数是用来求解线性规划问题的。
什么是线性规划问题?
就是在一系列的线性条件的约束下,从而规定了可行解,在通过具体的目标函数,求得满足函数 的最优的解
例如平常的线性规划函数的例子:
而在matlab中使用matlab 标准的格式:
若是目标函数是求解最大值的话,则取-C形式:
具体的应用:
代码:
c = [2;3;-5]; <span style="background-color:rgb(51,204,0);"> %目标函数的系数</span>
a = [-2,5,-1;1,3,1]; <span style="color:#33cc00;"> </span><span style="color:#009900;"><strong>%不等式的系数(其中的不等式是小于等于</strong></span><span style="color:#33cc00;">)</span>
b = [-10,12]; <span style="color:#33ff33;"> </span><strong><span style="color:#009900;">%不等式的右边的矩阵</span></strong>
aeq = [1,1,1]; <span style="color:#33ff33;"> </span><span style="color:#009900;"><strong>%等式部分的系数</strong></span>
deq = 7; <span style="color:#009900;"><strong> %等式的右边的值</strong></span>
x = linprog(-c,a,b,aeq,deq,zeros(3,1))
value = c'*x
结果:
(2)具体的函数linprog:
使用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(PROBLEM) finds the minimum for PROBLEM. PROBLEM is a
structure with the vector 'f' in PROBLEM.f, the linear inequality
constraints in PROBLEM.Aineq and PROBLEM.bineq, the linear equality
constraints in PROBLEM.Aeq and PROBLEM.beq, the lower bounds in
PROBLEM.lb, the upper bounds in PROBLEM.ub, the start point
in PROBLEM.x0, the options structure in PROBLEM.options, and solver
name 'linprog' in PROBLEM.solver. Use this syntax to solve at the
command line a problem exported from OPTIMTOOL. The structure PROBLEM
must have all the fields.
[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 Magnitude of search direction became too small; no further
progress can be made. The problem is ill-posed or badly
conditioned.
[X,FVAL,EXITFLAG,OUTPUT] = linprog(f,A,b) returns a structure OUTPUT
with the number of iterations taken in OUTPUT.iterations, maximum of
constraint violations in OUTPUT.constrviolation, the type of
algorithm used in OUTPUT.algorithm, the number of conjugate gradient
iterations in OUTPUT.cgiterations (= 0, included for backward
compatibility), 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 interior-point (the default) algorithm 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.
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。