source: proiecte/pmake3d/make3d_original/Make3dSingleImageStanford_version0.1/third_party/opt/yalmip/@sdpvar/power.m @ 37

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

Added original make3d

File size: 2.6 KB
Line 
1function y = power(x,d)
2%POWER (overloaded)
3
4% Author Johan Löfberg
5% $Id: power.m,v 1.10 2006/07/26 20:17:58 joloef Exp $   
6
7
8% Sanity check
9if prod(size(x))==1 & (prod(size(d))>1)
10    x = x.*ones(size(d));
11end
12if prod(size(d))>1
13    if any(size(d)~=size(x))
14        error('Matrix dimensions must agree.');
15    end
16else
17    d = ones(x.dim(1),x.dim(2))*d;
18end
19
20% Trivial cases
21if all(all(d==0))
22    if x.dim(1)~=x.dim(2)
23        error('Matrix must be square.')
24    end
25    y = eye(x.dim(1),x.dim(2)).^0;
26    return
27end
28if all(all(d==1))
29    y = x;
30    return
31end
32
33% Fractional, negative or different powers are
34% treated less efficiently using simple code.
35fractional = any(any((ceil(d)-d>0)));
36negative = any(any(d<0));
37different = ~all(all(d==d(1)));
38if fractional | negative | different
39    if x.dim(1)>1 | x.dim(2)>1
40        [n,m] = size(x);       
41        y = [];
42        for i = 1:n % FIX : Vectorize!
43            temp = [];
44            for j = 1:m
45                temp = [temp extsubsref(x,i,j).^d(i,j)];
46            end
47            y = [y;temp];
48        end
49        return
50    else
51        base = getbase(x);
52        if isequal(base,[0 1])
53            mt = yalmip('monomtable');
54            var = getvariables(x);
55            previous_var = find((mt(:,var)==d)  & (sum(mt~=0,2)==1));
56            if isempty(previous_var)
57                mt(end+1,:) = mt(getvariables(x),:)*d;
58                yalmip('setmonomtable',mt);
59                y = recover(size(mt,1));
60            else
61                y = recover(previous_var);
62            end
63        elseif (size(base,2) == 2) & base(1)==0
64            % Something like a*t^-d
65            y = base(2)^d*recover(getvariables(x))^d;
66        else
67            error('Only unit scalars can have negative or non-integer powers.');
68        end
69    end
70    return
71end
72
73% Back to scalar power...
74d = d(1,1);
75if x.dim(1)>1 | x.dim(2)>1
76    switch d
77        case 0
78            y = 1;
79        case 1
80            y = x;
81        otherwise
82            y = x.*power(x,d-1);
83    end
84else
85    base = getbase(x);
86    if isequal(base,[0 1])
87        mt = yalmip('monomtable');
88        var = getvariables(x);
89        previous_var = find((mt(:,var)==d)  & (sum(mt~=0,2)==1));
90        if isempty(previous_var)
91            mt(end+1,:) = mt(getvariables(x),:)*d;
92            yalmip('setmonomtable',mt);
93            y = x;
94            y.lmi_variables = size(mt,1);           
95        else
96            y = x;
97            y.lmi_variables = previous_var;           
98        end
99    else
100        switch d
101            case 0
102                y = 1;
103            case 1
104                y = x;
105            otherwise
106                y = x.*power(x,d-1);
107        end
108    end
109end
Note: See TracBrowser for help on using the repository browser.