Matlab中的求解线性规划的程序
楼主 · 1 楼
Matlab中的求解线性规划的程序
type lp
function [x,lambda,how]=lp(f,A,B,vlb,vub,x,neqcstr,verbosity)
%LP Linear programming.
% LP has been replaced with LINPROG. LP currently works but
% will be removed in the future. Use LINPROG instead.
%
% X=LP(f,A,
solves the
linear programming problem:
%
% min f'x subject to: Ax <= b
% x
%
% X=LP(f,A,b,VLB,VUB) defines a set of lower and upper
% bounds on the design variables, X, so that the solution is always in
% the range VLB <= X <= VUB.
%
% X=LP(f,A,b,VLB,VUB,X0) sets the initial starting point to X0.
%
% X=LP(f,A,b,VLB,VUB,X0,N) indicates that the first N constraints defined
% by A and b are equality constraints.
%
% X=LP(f,A,b,VLB,VUB,X0,N,DISPLAY) controls the level of warning
% messages displayed. Warning messages can be turned off with
% DISPLAY = -1.
%
% [x,LAMBDA]=LP(f,A,
returns the
set of Lagrangian multipliers,
% LAMBDA, at the solution.
%
% [X,LAMBDA,HOW] = LP(f,A,
also returns
a string how that indicates
% error conditions at the final iteration.
%
% LP produces warning messages when the solution is either unbounded
% or infeasible.
% Copyright 1990-2001 The MathWorks, Inc.
% $Revision: 1.17 $ $Date: 2001/03/27 19:55:11 $
% Andy Grace 7-9-90. Mary Ann Branch 9-30-96.
% This function is old, the current version should be used.
WarningStr=sprintf(...
['The function LP is obsolete and has been replaced by\n',...
'LINPROG. LP will be removed in a future release of the\n',...
'Optimization Toolbox. Update your code to call LINPROG to\n',...
'suppress this warning message. See "Converting your code to\n',...
'Version 2 Syntax" in the Optimization Toolbox User''s Guide\n',...
'for more information.\n']);
warning(WarningStr)
if nargin<8, verbosity = 0;
if nargin<7, neqcstr = 0;
if nargin<6, x = [];
if nargin<5, vub = [];
if nargin<4, vlb = [];
end, end, end, end, end
[ncstr,nvars]=size(A);
nvars = max([length(f),nvars]); % In case A is empty
if isempty(verbosity), verbosity = 0; end
if isempty(neqcstr), neqcstr = 0; end
if isempty(x), x=zeros(nvars,1); end
if isempty(A), A=zeros(0,nvars); end
if isempty(
,
B=zeros(0,1); end
% Set to column vectors
f = f(
;
B = B(
;
x = x(
;
caller = 'lp';
[x,lambda,how]=qpsubold([],f,A,B,vlb,vub,x,neqcstr,verbosity,caller,ncstr,nvars);
>>
type lp
function [x,lambda,how]=lp(f,A,B,vlb,vub,x,neqcstr,verbosity)
%LP Linear programming.
% LP has been replaced with LINPROG. LP currently works but
% will be removed in the future. Use LINPROG instead.
%
% X=LP(f,A,
%
% min f'x subject to: Ax <= b
% x
%
% X=LP(f,A,b,VLB,VUB) defines a set of lower and upper
% bounds on the design variables, X, so that the solution is always in
% the range VLB <= X <= VUB.
%
% X=LP(f,A,b,VLB,VUB,X0) sets the initial starting point to X0.
%
% X=LP(f,A,b,VLB,VUB,X0,N) indicates that the first N constraints defined
% by A and b are equality constraints.
%
% X=LP(f,A,b,VLB,VUB,X0,N,DISPLAY) controls the level of warning
% messages displayed. Warning messages can be turned off with
% DISPLAY = -1.
%
% [x,LAMBDA]=LP(f,A,
% LAMBDA, at the solution.
%
% [X,LAMBDA,HOW] = LP(f,A,
% error conditions at the final iteration.
%
% LP produces warning messages when the solution is either unbounded
% or infeasible.
% Copyright 1990-2001 The MathWorks, Inc.
% $Revision: 1.17 $ $Date: 2001/03/27 19:55:11 $
% Andy Grace 7-9-90. Mary Ann Branch 9-30-96.
% This function is old, the current version should be used.
WarningStr=sprintf(...
['The function LP is obsolete and has been replaced by\n',...
'LINPROG. LP will be removed in a future release of the\n',...
'Optimization Toolbox. Update your code to call LINPROG to\n',...
'suppress this warning message. See "Converting your code to\n',...
'Version 2 Syntax" in the Optimization Toolbox User''s Guide\n',...
'for more information.\n']);
warning(WarningStr)
if nargin<8, verbosity = 0;
if nargin<7, neqcstr = 0;
if nargin<6, x = [];
if nargin<5, vub = [];
if nargin<4, vlb = [];
end, end, end, end, end
[ncstr,nvars]=size(A);
nvars = max([length(f),nvars]); % In case A is empty
if isempty(verbosity), verbosity = 0; end
if isempty(neqcstr), neqcstr = 0; end
if isempty(x), x=zeros(nvars,1); end
if isempty(A), A=zeros(0,nvars); end
if isempty(
% Set to column vectors
f = f(
B = B(
x = x(
caller = 'lp';
[x,lambda,how]=qpsubold([],f,A,B,vlb,vub,x,neqcstr,verbosity,caller,ncstr,nvars);
>>
2 楼
由于和表情冲突,就放文本了 
3 楼
偶也帖一个:Matlab中的求解线性规划的程序