-
Notifications
You must be signed in to change notification settings - Fork 1
/
min_CS_example.m
55 lines (44 loc) · 1.21 KB
/
min_CS_example.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
% The goal is to demonstrate that MOSEK has a memory leak.
% In this example, a rank-1 matrix is recovered from dimension deficient data
% initialize
clear
% run /home/kliesch/.cvx/cvx_setup.m
% cvx_solver Mosek
% matrix dimension
n = 15;
% number of tests
reps = 1;
for j=1:reps
% draw rank-1 matrix and vectorize
M0 = randn([n,1])*randn([n,1])';
vecmat = reshape(M0,[n^2,1]);
% draw linear map
m = 6*n;
A = randn(m,n^2);
% y = incomplete information about M0
y = A*vecmat ;%+ .01*randn([m,1]);
%optimize
cvx_begin sdp %quiet
variable X(n,n)
variable Y(n,n)
variable M(n,n)
% minimize trace norm of M
minimize(trace(X+Y)/2)
[(X+X')/2 M ;
M' (Y+Y')/2] >= 0
% subject to y == A*M
y == A*reshape(M,[n^2,1])
cvx_end
% cvx_begin sdp quiet
% variable M(n,n)
% minimize(norm_nuc(M))
% y == A*reshape(M,[n^2,1])
% cvx_end
%y = A*reshape(X0,[n^2,1])
cvx_clear
% compare M to M0
fmat(j) = norm(reshape(M,[n^2,1]) - vecmat);
end
% largest deviation
largest = max(abs(fmat));
display(['largest deviation= ' num2str(largest)]);