1 | function F = sdpvar(X) |
---|
2 | % SDPVAR Converts a block variable to standard SDPVAR |
---|
3 | |
---|
4 | % Author Johan Löfberg |
---|
5 | % $Id: sdpvar.m,v 1.4 2005/06/17 13:02:01 joloef Exp $ |
---|
6 | |
---|
7 | |
---|
8 | % first, check that we have filled everything. |
---|
9 | [n,m] = size(X.blocks); |
---|
10 | |
---|
11 | if n==m |
---|
12 | % Perform symmetric extension |
---|
13 | for i = 1:n |
---|
14 | for j = i+1:n |
---|
15 | if isempty(X.blocks{i,j}) |
---|
16 | X.blocks{i,j} = X.blocks{j,i}; |
---|
17 | elseif isempty(X.blocks{j,i}) |
---|
18 | X.blocks{j,i} = X.blocks{i,j}'; |
---|
19 | end |
---|
20 | end |
---|
21 | end |
---|
22 | end |
---|
23 | |
---|
24 | for i = 1:n |
---|
25 | for j = 1:m |
---|
26 | ns(i,j) = size(X.blocks{i,j},1); |
---|
27 | ms(i,j) = size(X.blocks{i,j},2); |
---|
28 | % Indicate zero/eye blocks (simplies code below) |
---|
29 | if ns(i,j)==1 & ms(i,j) == 1 & isequal(X.blocks{i,j},0) |
---|
30 | ns(i,j) = 0; |
---|
31 | ms(i,j) = 0; |
---|
32 | end |
---|
33 | end |
---|
34 | end |
---|
35 | |
---|
36 | newns = ns; |
---|
37 | newms = ms; |
---|
38 | |
---|
39 | % Expand missing elements |
---|
40 | for i = 1:n |
---|
41 | for j = 1:m |
---|
42 | if ns(i,j) == 0 |
---|
43 | ns(i,j) = max(ns(i,:)); |
---|
44 | end |
---|
45 | if ms(i,j) == 0 |
---|
46 | ms(i,j) = max(ms(:,j)); |
---|
47 | end |
---|
48 | end |
---|
49 | end |
---|
50 | |
---|
51 | if any(any(ns==0)) | any(any(ms==0)) |
---|
52 | error('I cannot determine the implied size of some of the blocks'); |
---|
53 | end |
---|
54 | |
---|
55 | F = []; |
---|
56 | for i = 1:n |
---|
57 | Y = []; |
---|
58 | for j = 1:m |
---|
59 | if isequal(X.blocks{i,j},0) |
---|
60 | Y = [Y zeros(ns(i,j),ms(i,j))]; |
---|
61 | elseif isequal(X.blocks{i,j},1) |
---|
62 | Y = [Y eye(ns(i,j))]; |
---|
63 | elseif isempty(X.blocks{i,j}) & isempty(X.blocks{j,i}) |
---|
64 | Y = [Y zeros(ns(i,j),ms(i,j))]; |
---|
65 | else |
---|
66 | Y = [Y X.blocks{i,j}]; |
---|
67 | end |
---|
68 | end |
---|
69 | F = [F;Y]; |
---|
70 | end |
---|