[37] | 1 | clc |
---|
| 2 | echo on |
---|
| 3 | %********************************************************* |
---|
| 4 | % |
---|
| 5 | % Complex-valued problems |
---|
| 6 | % |
---|
| 7 | %********************************************************* |
---|
| 8 | % |
---|
| 9 | % YALMIP deals with complex-valued problems as easy as |
---|
| 10 | % standard problems |
---|
| 11 | pause % Strike any key to continue. |
---|
| 12 | clc |
---|
| 13 | % As an example, let us study the example on "Toeplitz |
---|
| 14 | % covariance estimation" in the SeDuMi manual. |
---|
| 15 | % |
---|
| 16 | % We are given a complex matrix P, and the goal |
---|
| 17 | % is to find a (possibly complex) Toeplitz matrix |
---|
| 18 | % Z that minimizes the Frobenious norm of Z-P |
---|
| 19 | pause % Strike any key to continue. |
---|
| 20 | |
---|
| 21 | % Data given |
---|
| 22 | i=sqrt(-1); |
---|
| 23 | P = [4 1+2*i 3-i;1-2*i 3.5 0.8+2.3*i;3+i 0.8-2.3*i 4]; |
---|
| 24 | pause % Strike any key to continue. |
---|
| 25 | |
---|
| 26 | % Define a complex Toeplitz matrix |
---|
| 27 | Z = sdpvar(3,3,'toeplitz','complex'); |
---|
| 28 | % Warning : Be careful and note that this |
---|
| 29 | % is not the same as Z = toeplitz(sdpvar(1,3))+i*toeplitz(sdpvar(1,3)) |
---|
| 30 | % or Z = sdpvar(3,3,'toeplitz')+sdpvar(3,3,'toeplitz') |
---|
| 31 | % We will later use the command "see" to understand the difference. |
---|
| 32 | pause % Strike any key to continue. |
---|
| 33 | |
---|
| 34 | % The Toeplitz matrix is not Hermitian, since it has got complex |
---|
| 35 | % elements on the diagonal. These can be removed with the following code |
---|
| 36 | Z = Z-sqrt(-1)*diag(imag(diag(Z))); |
---|
| 37 | pause % Strike any key to continue. |
---|
| 38 | |
---|
| 39 | % An alternative way to accomplish the same thing is |
---|
| 40 | Z = sdpvar(3,3,'toeplitz','complex'); |
---|
| 41 | Z = replace(Z,imag(diag(Z)),[0;0;0]); |
---|
| 42 | pause % Strike any key to continue. |
---|
| 43 | |
---|
| 44 | % Now use the fact that the Frobenious norm of Z-P |
---|
| 45 | % equals the 2-norm of Z(:)-P(:) |
---|
| 46 | % |
---|
| 47 | % Hence, we define e = Z(:)-P(:) and minimize ||e|| |
---|
| 48 | % Write this as min t |
---|
| 49 | % s.t ||e|| < t |
---|
| 50 | % Z > 0 |
---|
| 51 | pause % Strike any key to continue. |
---|
| 52 | t = sdpvar(1,1); |
---|
| 53 | e = Z(:)-P(:); |
---|
| 54 | F = set(Z > 0); |
---|
| 55 | F = F+set('||e||<t'); |
---|
| 56 | pause % Strike any key to continue. |
---|
| 57 | |
---|
| 58 | % Solve! |
---|
| 59 | solvesdp(F,t); |
---|
| 60 | pause % Strike any key to continue. |
---|
| 61 | |
---|
| 62 | % Check the result |
---|
| 63 | double(Z) |
---|
| 64 | |
---|
| 65 | % and compare with result in SeDuNi manual |
---|
| 66 | Zmanual = toeplitz([4.2827,0.8079+1.7342*sqrt(-1) 2.5574-0.7938*i]) |
---|
| 67 | pause % Strike any key to continue. |
---|
| 68 | |
---|
| 69 | clc |
---|
| 70 | % More convenient, use the overloaded norm operator! |
---|
| 71 | solvesdp(set(Z > 0),norm(e)); |
---|
| 72 | pause |
---|
| 73 | |
---|
| 74 | clc |
---|
| 75 | % The problem we solved above was a complex SOCP. Let us |
---|
| 76 | % now solve a complex LMI. We solve the same problem, but by |
---|
| 77 | % first applying a Schur complement to obtain |
---|
| 78 | % min t |
---|
| 79 | % s.t [t e';e I] > 0 |
---|
| 80 | % Z > 0 |
---|
| 81 | pause % Strike any key to continue. |
---|
| 82 | F = set(Z); |
---|
| 83 | F = F+set([t e';e eye(9)]); |
---|
| 84 | pause % Strike any key to continue. |
---|
| 85 | |
---|
| 86 | % Solve! |
---|
| 87 | solvesdp(F,t); |
---|
| 88 | pause % Strike any key to continue. |
---|
| 89 | |
---|
| 90 | % Check the result |
---|
| 91 | double(Z) |
---|
| 92 | |
---|
| 93 | % and compare with result in SeDuNi manual |
---|
| 94 | Zmanual = toeplitz([4.2827,0.8079+1.7342*sqrt(-1) 2.5574-0.7938*i]) |
---|
| 95 | pause % Strike any key to continue. |
---|
| 96 | |
---|
| 97 | clc |
---|
| 98 | |
---|
| 99 | % We should also mention that complex linear constraints are interpreted |
---|
| 100 | % just as they are stated, i.e. in the complex domain (there are some |
---|
| 101 | % alternatives in SeDuMi). |
---|
| 102 | % |
---|
| 103 | % Let us solve a simple linear complex problem to illustrate how |
---|
| 104 | % complex constraints are used |
---|
| 105 | pause % Strike any key to continue. |
---|
| 106 | |
---|
| 107 | p = sdpvar(1,1,'full','complex'); % A complex scalar (4 arguments necessary) |
---|
| 108 | s = sdpvar(1,1)+sqrt(-1)*sdpvar(1,1); % Alternativ definition |
---|
| 109 | F = set('0.9>imag(p)'); |
---|
| 110 | F = F+set('0.01>real(p)'); |
---|
| 111 | F = F+set('0.1+0.5*sqrt(-1)>p'); |
---|
| 112 | F = F+set('s+p==2+4*sqrt(-1)'); |
---|
| 113 | |
---|
| 114 | pause % Strike any key to continue. |
---|
| 115 | % If we display the set, we see which constraints that are complex |
---|
| 116 | F |
---|
| 117 | pause % Strike any key to continue. |
---|
| 118 | |
---|
| 119 | % And solve... |
---|
| 120 | solvesdp(F,-real(p)-imag(p)); |
---|
| 121 | |
---|
| 122 | double(s+p) |
---|
| 123 | double(s) |
---|
| 124 | double(p) |
---|
| 125 | pause % Strike any key to continue. |
---|
| 126 | |
---|
| 127 | |
---|
| 128 | clc |
---|
| 129 | % Let us go back to the discussion earlier on how to construct |
---|
| 130 | % a complex Toeplitz matrix. |
---|
| 131 | % |
---|
| 132 | % Since YALMIP supports Toeplitz as a standard matrix in sdpvar, |
---|
| 133 | % an easily made mistake is to belive that the following code |
---|
| 134 | % would generate a complex Toeplitz |
---|
| 135 | pause % Strike any key to continue. |
---|
| 136 | Z = sdpvar(3,3,'toeplitz')+i*sdpvar(3,3,'toeplitz'); |
---|
| 137 | pause % Strike any key to continue. |
---|
| 138 | |
---|
| 139 | % If we look at the base matrices, we see that this is not the case |
---|
| 140 | % (the complex matrices are not complex Toeplitz) |
---|
| 141 | see(Z,'full') |
---|
| 142 | pause % Strike any key to continue. |
---|
| 143 | |
---|
| 144 | clc |
---|
| 145 | |
---|
| 146 | % Another bad idea is the following piece of code |
---|
| 147 | x = sdpvar(1,3); |
---|
| 148 | y = sdpvar(1,3); |
---|
| 149 | Z = toeplitz(x)+i*toeplitz(y); |
---|
| 150 | pause % Strike any key to continue. |
---|
| 151 | % We see once again that this is not a complex Toeplitz |
---|
| 152 | see(Z,'full') |
---|
| 153 | pause % Strike any key to continue. |
---|
| 154 | |
---|
| 155 | clc |
---|
| 156 | |
---|
| 157 | % One way to do it correctly is to write it as we did above |
---|
| 158 | Z = sdpvar(3,3,'toeplitz','complex'); |
---|
| 159 | pause % Strike any key to continue. |
---|
| 160 | % ... complex Toeplitz matrices |
---|
| 161 | % (notice the diagonal complex terms that we took care of earlier) |
---|
| 162 | see(Z,'full') |
---|
| 163 | pause % Strike any key to continue. |
---|
| 164 | |
---|
| 165 | clc |
---|
| 166 | % As a final remark, remember that the common functions |
---|
| 167 | % for complex algebra is available for sdpvar objects. |
---|
| 168 | pause % Strike any key to continue. |
---|
| 169 | Z = sdpvar(3,3,'toeplitz','complex'); |
---|
| 170 | |
---|
| 171 | real(Z) |
---|
| 172 | imag(Z) |
---|
| 173 | conj(Z) |
---|
| 174 | isreal(Z) |
---|
| 175 | isreal(Z-sqrt(-1)*imag(Z)) |
---|
| 176 | |
---|
| 177 | pause % Strike any key to continue. |
---|
| 178 | echo off |
---|