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

    function d = constraintDistance(con, X)
%CONSTRAINTDISTANCE Signed distance to constraint boundary for a list of points
%
%  D = CONSTRAINTDISTANCE(CON, X) is the signed distance to the boundary of the
%  constraint CON for the list of points X. This method constitutes the core
%  definition of the constraint in terms of what is in and what is out.
%
%  X should be an array with nFactors( CON ) columns. D will be a vector with
%  the same number of rows as X.
%
%  D = CONSTRAINTDISTANCE(CON, SS), where SS is a sweepset, performs a
%  sweep-by-sweep evaluation of the constraint using the sweep means for
%  the global factors,
%
%  See also CONTWOSTAGE, CONBASE/ISINSIDE, CONBASE/BRINGINSIDE.

%  Copyright 2000-2005 The MathWorks, Inc. and Ford Global Technologies, Inc.

ngm = numel( con.Global );     % number of global models
gi  = getGlobalIndices( con ); 
li  = getLocalIndices(  con );

if isa( X, 'sweepset' ),  %% CHECK ME!
    d = X(:,1,:);
    d(:) = 0;
    b = zeros( ngm, 1 );   % local model parameters
    for i = 1:size( X, 3 ),
        for j = 1:ngm,
            b(j) = EvalModel( con.Global{j}, mean( X(:,gi,i) ) );
        end
        d(:,:,i) = pLocalConstraintDistance( con, b, X(:,li,i) );
    end
    
else
    X = double( X );
    neval = size( X, 1 );
    d = zeros( neval, 1 );
    b = zeros( neval, ngm );
    for j = 1:ngm,
        b(:,j) = EvalModel( con.Global{j}, X(:,gi) );
    end
    for i = 1:neval;
        d(i) = pLocalConstraintDistance( con, b(i,:)', X(i,li) );
    end
end

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