1 | function X=ctranspose(X) |
---|
2 | %CTRANSPOSE (overloaded) |
---|
3 | |
---|
4 | % Author Johan Löfberg |
---|
5 | % $Id: ctranspose.m,v 1.2 2006/08/28 13:48:38 joloef Exp $ |
---|
6 | |
---|
7 | if isa(X,'blkvar') |
---|
8 | X = sdpvar(X); |
---|
9 | end |
---|
10 | |
---|
11 | n = X.dim(1); |
---|
12 | m = X.dim(2); |
---|
13 | ind = reshape(reshape(1:n*m,n,m)',n*m,1); |
---|
14 | if isreal(X.basis) |
---|
15 | X.basis = X.basis(ind,:); |
---|
16 | else |
---|
17 | X.basis = conj(X.basis(ind,:)); |
---|
18 | end |
---|
19 | X.dim(1) = m; |
---|
20 | X.dim(2) = n; |
---|
21 | % Reset info about conic terms |
---|
22 | X.conicinfo = [0 0]; |
---|
23 | |
---|
24 | % Flip noncommuting terms |
---|
25 | % Get all the tables, and expand them so that they correspond to the same |
---|
26 | % number of variables globally (nonCommutingTable is not up to date after a |
---|
27 | % new commuting variables has been defined, to save flops) |
---|
28 | nonCommutingTable = yalmip('nonCommutingTable'); |
---|
29 | [monomtable,variabletype] = yalmip('monomtable'); |
---|
30 | if size(monomtable,1)>size(nonCommutingTable,1) |
---|
31 | nonCommutingTable((1+size(nonCommutingTable,1)):(size(monomtable,1)),1) = (1+size(nonCommutingTable,1)):(size(monomtable,1)); |
---|
32 | end |
---|
33 | % Cast commutative variables as nc temporarily by adding them to the table |
---|
34 | commuting = find(~any(nonCommutingTable,2)); |
---|
35 | nonCommutingTable(commuting,1) = commuting; |
---|
36 | |
---|
37 | for i = 1:length(X.lmi_variables) |
---|
38 | if nonCommutingTable(X.lmi_variables(i),2) |
---|
39 | monoms = nonCommutingTable(X.lmi_variables(i),2:end); |
---|
40 | monoms(find(monoms)) = fliplr( monoms(find(monoms))); |
---|
41 | monoms = [nonCommutingTable(X.lmi_variables(i),1) monoms]; |
---|
42 | old = findrows(nonCommutingTable,monoms); |
---|
43 | old = findrows(nonCommutingTable(:,2:end),monoms(2:end)); |
---|
44 | if ~isempty(old) |
---|
45 | old = old(find((monoms(1) == nonCommutingTable(old,1)) | isnan(monoms(1)) & isnan(nonCommutingTable(old,1)))); |
---|
46 | end |
---|
47 | if isempty(old) |
---|
48 | % Create a new monomial |
---|
49 | monomtable(end+1,end+1) = 0; |
---|
50 | variabletype(end+1) = variabletype(X.lmi_variables(i)); |
---|
51 | nonCommutingTable = [nonCommutingTable;monoms]; |
---|
52 | X.lmi_variables(i) = size(nonCommutingTable,1); |
---|
53 | else |
---|
54 | X.lmi_variables(i) = old; |
---|
55 | end |
---|
56 | end |
---|
57 | end |
---|
58 | % Fucked up order (lmi_variables should be sorted and unique) |
---|
59 | if any(diff(X.lmi_variables)<0) |
---|
60 | [i,j]=sort(X.lmi_variables); |
---|
61 | X.basis = [X.basis(:,1) X.basis(:,j+1)]; |
---|
62 | X.lmi_variables = X.lmi_variables(j); |
---|
63 | end |
---|
64 | [un_Z_vars2] = uniquestripped(X.lmi_variables); |
---|
65 | if length(un_Z_vars2) < length(X.lmi_variables) |
---|
66 | [un_Z_vars,hh,jj] = unique(X.lmi_variables); |
---|
67 | if length(X.lmi_variables) ~=length(un_X_vars) |
---|
68 | X.basis = Z.basis*sparse([1 1+jj],[1 1+(1:length(jj))],ones(1,1+length(jj)))'; |
---|
69 | X.lmi_variables = un_Z_vars; |
---|
70 | end |
---|
71 | end |
---|
72 | if size(monomtable,2) < size(monomtable,1) |
---|
73 | monomtable(size(monomtable,1),size(monomtable,1)) = 0; |
---|
74 | end |
---|
75 | yalmip('nonCommutingTable',nonCommutingTable); |
---|
76 | yalmip('setmonomtable',monomtable,variabletype); |
---|