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

    function con = and(con1, con2)
%AND  Logical AND (intersection) of two ranges constraints
%
%  CON = AND(CON1, CON2) is the intersection of the constraints CON1 and CON2,
%  i.e., a point X is in AND(CON1,CON2) if and only if it is inside CON1 and it
%  is inside CON2.
% 
%  CON1 and CON2 must be the have the same number of input factors (as returned
%  by NINPUTFACTORS). 
%
%  If either CON1 or CON2 is not a range constraint (CONRANGE) then CON1 & CON2
%  will be a boolean constraint (CONBOOLEAN).
%
%  See also CONRANGE, CONBOOLEAN, CONBASE/AND.

%  Copyright 2004-2005 The MathWorks, Inc.

% Can only combine if both constraints are rnage constraints. Otherwise, just
% redirect to conboolean
if ~isa( con1, 'conrange' ) || ~isa( con2, 'conrange' ),
    con = conboolean( 'And', con1, con2 );
    return
end

% We get the upper and lower bounds for each constraint and then take min's and
% max's to get the range of the overall constraint. We also need to check for
% inactive (+/-inf in the range) factors.
[A1, B1] = getRange( con1 );
[A2, B2] = getRange( con2 );

con = setRange( con1, max( A1, A2 ), min( B1, B2 ) );

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