sqrtm_internal.m

来自「matlab波形优化算法经常要用到的matlab toolbox工具箱:yalm」· M 代码 · 共 64 行

M
64
字号
function varargout = sqrtm(varargin)
%SQRTM (overloaded)

% Author Johan L鰂berg
% $Id: sqrtm_internal.m,v 1.10 2008/01/08 08:02:41 joloef Exp $
switch class(varargin{1})

    case 'double'
        varargout{1} = sqrt(varargin{1});

    case 'sdpvar'
        if length(varargin{1}) == 1
            varargout{1} = yalmip('define',mfilename,varargin{1});
        else
            error('SQRTM is only implemented for scalar argument')
        end

    case 'char'

        X = varargin{3};
        F = set(X > eps);

        varargout{1} = F;
        varargout{2} = struct('convexity','concave','monotonicity','increasing','definiteness','positive','convexhull',@convexhull,'bounds',@bounds,'model','callback','derivative',@(x) 1./(eps + 2*abs(x).^0.5));
        varargout{3} = X;

    otherwise
        error('SDPVAR/SQRTM called with CHAR argument?');
end

function [L,U] = bounds(xL,xU)
if xL < 0
    % The variable is not bounded enough yet
    L = 0;
else
    L = sqrt(xL);
end
if xU < 0
    % This is an infeasible problem
    L = inf;
    U = -inf;
else
    U = sqrt(xU);
end

function [Ax, Ay, b] = convexhull(xL,xU)
if xL < 0 | xU == 0
    Ax = []
    Ay = [];
    b = [];
else
    fL = sqrt(xL);
    fU = sqrt(xU);
    dfL = 1/(2*sqrt(xL));
    dfU = 1/(2*sqrt(xU));
    [Ax,Ay,b] = convexhullConcave(xL,xU,fL,fU,dfL,dfU);
    remove = isinf(b) | isinf(Ax) | isnan(b);
    if any(remove)
        remove = find(remove);
        Ax(remove)=[];
        b(remove)=[];
        Ay(remove)=[];
    end
end

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?