www.gusucode.com > mbcdesign 工具箱 matlab 源码程序 > mbcdesign/@conellipsoid/bringInside.m
function X = bringInside(con, X) %BRINGINSIDE Move a set of points so they are all inside the constraint. % % Y = BRINGINSIDE(CON, X) is the data set X but with any points outside the % constraint CON projected into the constraint. % If X(i,:) is inside the constraint, then Y(i,:) = X(i,:). % If X(i,:) is outside the constriant, then Y(:,i) will be the closest point to % X(i,:) that is inside (on the boundary of) the constraint. % % See also CONELLIPSOID, CONELLIPSOID/ISINSIDE, % CONELLIPSOID/CONSTRAINTDISTANCE, CONBASE/BRINGINSIDE. % Copyright 2004-2005 The MathWorks, Inc. % We only need to process the active factors ... ai = getActiveIndices( con ); % ... and points that are outside the constraint. d = constraintDistance( con, X ); out = d > 0; % The closest interior point is given by % v = lambda * X + (1-lambda) * Xc % where lambda = 1/sqrt( (X-Xc)'*W*(X-Xc) ) lambda = 1./(con.scalefactor * d(out) + 1); xc = repmat( con.xc, nnz( out ), 1 ); X(out,ai) = diag( lambda )*X(out,ai) + diag( 1-lambda )*xc; %------------------------------------------------------------------------------| % EOF %------------------------------------------------------------------------------|