www.gusucode.com > mbcexpr 工具箱 matlab 源码程序 > mbcexpr/@cgexpr/getrange.m

    function rng = getrange(obj, varargin)
%GETRANGE Return range of expression
%
%  RNG = GETRANGE(OBJ) returns a two-element vector containing the minimum
%  and maximum output values of the expression.  For an general expression
%  this is determined numerically and will only be an approximation to the
%  real minimum and maximum.
%
%  RNG = GETRANGE(OBJ, QUANTITY) returns the output range for the specified
%  quantity.  QUANTITY must be a function handle to an expression method of
%  the form Y = FUNC(OBJ).

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


pInp = cgindependentvars(getinports(obj));
if nargin==1 && isempty(pInp)
    % Form range from the current output
    x = evalAtInputs(obj, {});
    rng = mbcmakelimits(x(1), 'loose');
elseif nargin==1 && length(pInp)==1
    % Use a 1D optimization
    rng = [0 0];
    [unused, rng(1)] = findextremum(obj, pInp, 'minimum');
    [unused, rng(2)] = findextremum(obj, pInp, 'maximum');
else
    % Evaluate expression over a set of scattered points and take the
    % min/max of them.
    output = evaluateOverDesign(obj, varargin{:});
    rng = mbcmakelimits(output, 'loose');
end