www.gusucode.com > mbcdata 工具箱 matlab 源码程序 > mbcdata/@cgtabgradconstraint/private/pGetDG.m

    function [D, g] = pGetDG(obj)
%PGETDG Return the gradient operator and bounds
%
%   [D, g] = PGETDG(OBJ) returns the difference operator, D, in the table
%   gradient constraint. The table gradient constraint is defined by (*)
%
%   C(x) = DX_{t}X_{p}^{-1}x - g <= 0   (*)
%       def
%
%   The structure of D and g is defined below
%
%   2-d Tables:
%
%   D = [   Denominator of row gradient   ]
%       [  -Denominator of row gradient   ]
%       [  Denominator of column gradient ]
%       [ -Denominator of column gradient ]
%
%   g = [maxrowg;-minrowg;maxcolg;-mincolg]
%
%   1-d Tables:
%
%   D = [ Denominator of row gradient]
%       [-Denominator of row gradient]
%
%   g = [maxrowg;-minrowg]
%

%   See also PGETXT, PGETXPINV

%   Copyright 2006-2015 The MathWorks, Inc.

% Create D for the full grid
NAXES = length(obj.pAxisVariables);
if NAXES == 2
    
    % Get row and column gradient operators
    [Ar, Ac] = cg2dtablegradoperator(obj.ScaledAxisBreakpoints{:});
    
    % Generate difference operator
    numRowCon = size(Ar, 1);
    numColCon = size(Ac, 1);
    D = [Ar;-Ar;Ac;-Ac];
        
    % Generate gradient bound vector. The scaling scheme implies that the
    % bound for an axis is multiplied by the range of the axis.
    g = zeros(2*numRowCon + 2*numColCon, 1);
    g(1:numRowCon) = obj.Bounds(1, 2)/obj.Bounds(1, 3);
    g(numRowCon+1:2*numRowCon) = -obj.Bounds(1, 1)/obj.Bounds(1, 3);
    g(2*numRowCon+1:2*numRowCon+numColCon) = ...
        obj.Bounds(2, 2)/obj.Bounds(2, 3);
    g(2*numRowCon+numColCon+1:end) = -obj.Bounds(2, 1)/obj.Bounds(2, 3);   
    g = g.*pGetAxisRangeScale(obj);
          
elseif NAXES == 1
    
    % Get row and column gradient operators
    A = cg1dtablegradoperator(obj.ScaledAxisBreakpoints{1});

    % Generate difference operator
    numRowCon = size(A, 1);
    D = [A;-A];

    % Generate gradient bound vector. The scaling scheme implies that the
    % bound for an axis is multiplied by the range of the axis.   
    g = zeros(2*numRowCon, 1);
    g(1:numRowCon) = obj.Bounds(2)/obj.Bounds(3);
    g(numRowCon+1:end) = -obj.Bounds(1)/obj.Bounds(3);
    g = g.*pGetAxisRangeScale(obj);

else
    D = [];
    g = [];
end

% Only keep constraints that have finite bounds
idxFinite = isfinite(g);
D = D(idxFinite, :);
g = g(idxFinite);