source: proiecte/pmake3d/make3d_original/Make3dSingleImageStanford_version0.1/third_party/opt/yalmip/demos/complexex.m @ 37

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

Added original make3d

File size: 4.9 KB
Line 
1clc
2echo on
3%*********************************************************
4%
5% Complex-valued problems
6%
7%*********************************************************
8%
9% YALMIP deals with complex-valued problems as easy as
10% standard problems
11pause % Strike any key to continue.
12clc
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
19pause % Strike any key to continue.
20
21% Data given
22i=sqrt(-1);
23P = [4 1+2*i 3-i;1-2*i 3.5 0.8+2.3*i;3+i 0.8-2.3*i 4];
24pause % Strike any key to continue.
25
26% Define a complex Toeplitz matrix
27Z = 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.
32pause % 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
36Z = Z-sqrt(-1)*diag(imag(diag(Z)));
37pause % Strike any key to continue.
38
39% An alternative way to accomplish the same thing is
40Z = sdpvar(3,3,'toeplitz','complex');
41Z = replace(Z,imag(diag(Z)),[0;0;0]);
42pause % 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
51pause % Strike any key to continue.
52t = sdpvar(1,1);
53e = Z(:)-P(:);
54F = set(Z > 0);
55F = F+set('||e||<t');
56pause % Strike any key to continue.
57
58% Solve!
59solvesdp(F,t);
60pause % Strike any key to continue.
61
62% Check the result
63double(Z)
64
65% and compare with result in SeDuNi manual
66Zmanual = toeplitz([4.2827,0.8079+1.7342*sqrt(-1) 2.5574-0.7938*i])
67pause % Strike any key to continue.
68
69clc
70% More convenient, use the overloaded norm operator!
71solvesdp(set(Z > 0),norm(e));
72pause
73
74clc
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
81pause % Strike any key to continue.
82F = set(Z);
83F = F+set([t e';e eye(9)]);
84pause % Strike any key to continue.
85
86% Solve!
87solvesdp(F,t);
88pause % Strike any key to continue.
89
90% Check the result
91double(Z)
92
93% and compare with result in SeDuNi manual
94Zmanual = toeplitz([4.2827,0.8079+1.7342*sqrt(-1) 2.5574-0.7938*i])
95pause % Strike any key to continue.
96
97clc
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
105pause % Strike any key to continue.
106
107p = sdpvar(1,1,'full','complex');      % A complex scalar (4 arguments necessary)
108s = sdpvar(1,1)+sqrt(-1)*sdpvar(1,1);  % Alternativ definition
109F = set('0.9>imag(p)');
110F = F+set('0.01>real(p)');
111F = F+set('0.1+0.5*sqrt(-1)>p');
112F = F+set('s+p==2+4*sqrt(-1)');
113
114pause % Strike any key to continue.
115% If we display the set, we see which constraints that are complex
116F
117pause % Strike any key to continue.
118
119% And solve...
120solvesdp(F,-real(p)-imag(p));
121
122double(s+p)
123double(s)
124double(p)
125pause % Strike any key to continue.
126
127
128clc
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
135pause % Strike any key to continue.
136Z = sdpvar(3,3,'toeplitz')+i*sdpvar(3,3,'toeplitz');
137pause % 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)
141see(Z,'full')
142pause % Strike any key to continue.
143
144clc
145
146% Another bad idea is the following piece of code
147x = sdpvar(1,3);
148y = sdpvar(1,3);
149Z = toeplitz(x)+i*toeplitz(y);
150pause % Strike any key to continue.
151% We see once again that this is not a complex Toeplitz
152see(Z,'full')
153pause % Strike any key to continue.
154
155clc
156
157% One way to do it correctly is to write it as we did above
158Z = sdpvar(3,3,'toeplitz','complex');
159pause % Strike any key to continue.
160% ... complex Toeplitz matrices
161% (notice the diagonal complex terms that we took care of earlier)
162see(Z,'full')
163pause % Strike any key to continue.
164
165clc
166% As a final remark, remember that the common functions
167% for complex algebra is available for sdpvar objects.
168pause % Strike any key to continue.
169Z = sdpvar(3,3,'toeplitz','complex');
170
171real(Z)
172imag(Z)
173conj(Z)
174isreal(Z)
175isreal(Z-sqrt(-1)*imag(Z))
176
177pause % Strike any key to continue.
178echo off
Note: See TracBrowser for help on using the repository browser.