www.gusucode.com > mbcdesign 工具箱 matlab 源码程序 > mbcdesign/@conboolean/getLinearForm.m

    function [A, b] = getLinearForm(con)
%GETLINEARFORM Get the linear form of a constraint
%
%  [A, B] = GETLINEARFORM(CON)
%
%  The linear form of a constraint, CON, is a matrix, A, and a vector, b, such
%  that  
%              constraintDistance( CON, X ) = A * X - b,
%
%  i.e., the constraint is given by
%
%              A * X <= b.
%
%  See also CONBOOLEAN, CONBOOLEAN/ISLINEAR, CONBOOLEAN/CONSTRAINTDISTANCE.

%  Copyright 2004-2005 The MathWorks, Inc.

if ~islinear( con ),
    error(message('mbc:conboolean:UnknownError', upper( mfilename )));
end

% Number of constraints
nc = length( con.Constraints );

% Use cell arrays to store each A, b and then concatenate
A = cell( nc, 1 );
b = cell( nc, 1 );

% Get the linear form for each constraint
for i = 1:nc
    [A{i}, b{i}] = getLinearForm( con.Constraints{i} );
end

% Concatenate all the A, b
A = cat( 1, A{:} );
b = cat( 1, b{:} );

if con.Not,
    A = -A;
    b = -b;
end

%------------------------------------------------------------------------------|
% EOF
%------------------------------------------------------------------------------|