1 | function varargout = SQRT(varargin) |
---|
2 | %SQRT (overloaded) |
---|
3 | % |
---|
4 | % t = sqrt(x) |
---|
5 | % |
---|
6 | % The variable t can only be used in concavity preserving |
---|
7 | % operations such as t>1, max t etc. |
---|
8 | % |
---|
9 | % When SQRT is used in a problem, the domain constraint |
---|
10 | % set(x>0) is automatically added to the problem. |
---|
11 | % |
---|
12 | % See also SDPVAR, SDPVAR/GEOMEAN |
---|
13 | |
---|
14 | % Author Johan Löfberg |
---|
15 | % $Id: sqrt.m,v 1.4 2005/09/18 16:45:24 joloef Exp $ |
---|
16 | |
---|
17 | switch class(varargin{1}) |
---|
18 | |
---|
19 | case 'double' % What is the numerical value of this argument (needed for displays etc) |
---|
20 | X = sqrt(varargin{1}); |
---|
21 | |
---|
22 | case 'sdpvar' % Overloaded operator for SDPVAR objects. Pass on args and save them. |
---|
23 | X = varargin{1}; |
---|
24 | [n,m] = size(X); |
---|
25 | if is(varargin{1},'real') & (n*m==1) |
---|
26 | varargout{1} = yalmip('addextendedvariable',mfilename,varargin{:}); |
---|
27 | else |
---|
28 | error('SQRT can only be applied to real scalars'); |
---|
29 | end |
---|
30 | |
---|
31 | case 'char' % YALMIP send 'model' when it wants the epigraph or hypograph |
---|
32 | if isequal(varargin{1},'graph') |
---|
33 | t = varargin{2}; % Second arg is the extended operator variable |
---|
34 | X = varargin{3}; % Third arg and above are the args user used when defining t. |
---|
35 | varargout{1} = set(cone([(X-1)/2;t],(X+1)/2)); |
---|
36 | varargout{2} = struct('convexity','concave','monotonicity','increasing','definiteness','positive'); |
---|
37 | varargout{3} = X; |
---|
38 | else |
---|
39 | end |
---|
40 | otherwise |
---|
41 | end |
---|