source: proiecte/pmake3d/make3d_original/Make3dSingleImageStanford_version0.1/third_party/opt/yalmip/operators/cpower.m @ 37

Last change on this file since 37 was 37, checked in by (none), 14 years ago

Added original make3d

File size: 2.8 KB
Line 
1function varargout = cpower(varargin)
2%CPOWER Power of SDPVAR variable with convexity knowledge
3%
4% CPOWER is recommended if your goal is to obtain
5% a convex model, since the function CPOWER is implemented
6% as a so called nonlinear operator. (For p/q ==2 you can
7% however just as well use the overloaded power)
8%
9% t = power(x,p/q) 
10%
11% For negative p/q, the operator is convex.
12% For positive p/q with p>q, the operator is convex.
13% For positive p/q with p<q, the operator is concave.
14%
15% A domain constraint x>0 is automatically added if
16% p/q not is an even integer.
17%
18% Note, the complexity of generating the conic representation
19% of these variables are O(2^L) where L typically is the
20% smallest integer such that 2^L >= min(p,q)
21
22% Author Johan Löfberg
23% $Id: cpower.m,v 1.1 2006/03/30 13:36:39 joloef Exp $
24
25switch class(varargin{1})
26
27    case 'double'
28        varargout{1} = power(varargin{1},varargin{2});
29    case 'sdpvar' % Overloaded operator for SDPVAR objects. Pass on args and save them.
30        X = varargin{1};
31        [n,m] = size(X);
32        if isreal(X) & n*m==1
33            varargout{1} = yalmip('addextendedvariable',mfilename,varargin{:});
34        else
35            error('CPOWER can only be applied to real vectors.');
36        end
37
38    case 'char' % YALMIP send 'model' when it wants the epigraph or hypograph
39        if isequal(varargin{1},'graph')
40            t = varargin{2}; % Second arg is the extended operator variable
41            X = varargin{3}; % Third arg and above are the args user used when defining t.
42            p = varargin{4};
43
44            if p>0
45                [p,q] = rat(abs(p));
46                F = pospower(set([]),X,t,p,q);
47                if p>q                   
48                    convexity = 'convex';
49                    monotonicity = 'increasing';
50                else
51                    convexity = 'concave';
52                    monotonicity = 'decreasing';
53                   
54                end
55            else
56                [p,q] = rat(abs(p));
57                F = negpower(set([]),X,t,p,q);
58                convexity = 'convex';
59                monotonicity = 'decreasing';
60            end           
61
62            varargout{1} = F;           
63            varargout{2} = struct('convexity',convexity,'monotonicity',monotonicity,'definiteness','positive');           
64            varargout{3} = X;
65        end
66    otherwise
67end
68
69function F = pospower(F,x,t,p,q)
70if p>q
71    l = ceil(log2(abs(p)));
72    r = 2^l-p;
73    y = [ones(r,1)*x;ones(q,1)*t;ones(2^l-r-q,1)];
74    F = detset(x,y);
75else
76    l = ceil(log2(abs(q)));
77    y = [ones(p,1)*x;ones(2^l-q,1)*t;ones(q-p,1)];
78    F = detset(t,y);
79end
80
81function F = negpower(F,x,t,p,q)
82l = ceil(log2(abs(p+q)));
83p = abs(p);
84q = abs(q);
85y = [ones(2^l-p-q,1);ones(p,1)*x;ones(q,1)*t];
86F = detset(1,y);
87
Note: See TracBrowser for help on using the repository browser.