Incorrect solving cvx!


(helena.bbzd) #1

Hello everyone,

I am trying to solve the following cvx optimization problem:

clear all
clc
A=[0 1;-2 3];B=[0;1];Qc=[100 0;0 1];Rc=10;
h=0.05;tav=0.08;

Q2=[[4.9915 0.1284;0.1284 0.0629] [1.1616e-04;2.3852e-04] [0.0019;0.0013] zeros(2,1);…
[1.1616e-04;2.3852e-04]’ .2000 6.7902e-06 0;…
[0.0019;0.0013]’ 6.7902e-06 .2000 0;zeros(1,2) 0 0 0];

fi2=[expm(A*h) [2.0405e-04;.0206] [.0011;.0333];zeros(1,2) 0 0;zeros(1,2) 1 0];

sigma=0.01;

landa2=[0;1;0;0];
%% cvx

cvx_begin
cvx_solver sedumi
variable S(4,4) symmetric
variable w2(1,4)
variable alfa2

minimize(trace_inv(S))
subject to

[S zeros(4,4) (fi2*S+landa2*w2).’ S.’ (sqrtm(Q2)*[S;w2]).’;…
zeros(4,4) 2S-alfa2eye(4,4) (landa2w2).’ zeros(4,4) (sqrtm(Q2)[zeros(4,4);w2]).’;…
fi2S+landa2w2 landa2w2 S zeros(4,4) zeros(4,5);…
S zeros(4,4) zeros(4,4) eye(4,4)alfa2/(sigma^2) zeros(4,5);…
sqrtm(Q2)
[S;w2] sqrtm(Q2)
[zeros(4,4);w2] zeros(5,4) zeros(5,4) eye(5,5)]>= 0

alfa2>=0;
S>=0;

cvx_end
K2=w2*(S^-1)

status is solved, but in fact after solving ,when I check eigenvalue of the matrix:
[S zeros(4,4) (fi2*S+landa2*w2).’ S.’ (sqrtm(Q2)*[S;w2]).’;…
zeros(4,4) 2S-alfa2eye(4,4) (landa2w2).’ zeros(4,4) (sqrtm(Q2)[zeros(4,4);w2]).’;…
fi2S+landa2w2 landa2w2 S zeros(4,4) zeros(4,5);…
S zeros(4,4) zeros(4,4) eye(4,4)alfa2/(sigma^2) zeros(4,5);…
sqrtm(Q2)
[S;w2] sqrtm(Q2)
[zeros(4,4);w2] zeros(5,4) zeros(5,4) eye(5,5)]>= 0

values are negative!!! ( this matrix should be PD)
I have been at this issue for a while.
Help and comments are much appreciated.


(Mark L. Stone) #2

You have constrained the matrix to have non-negative elements. You did not constrain it to be positive semidefinite.

Your program would be what you intended if you had been in CVX’s semidefinite programming mode http://cvxr.com/cvx/doc/sdp.html , which is invoked by using cvx_begin sdp instead of cvx_begin,

Alternatively, you could have used the == semidefinite(dimension of matrix) discussed at http://cvxr.com/cvx/doc/basics.html#set-membership .

I believe that constraining S to be psd is unnecessary (but is not “wrong”) given that it must be psd in order for the larger matrix to be psd. Also, given that S is symmetric, which you have declared it to be, trace_inv will enforce its argument to be psd without requiring explicit declaration or constraint to that effect.


(helena.bbzd) #3

Thanks for the answer, your comments help me,but also after correction,status is solved and eignvalues of the big matrix are negative (matrix is symmetric)
clc
clear all
A=[0 1;-2 3];B=[0;1];Qc=[100 0;0 1];Rc=10;
h=0.05;tav=0;

Q1=[[4.9915 0.1284;0.1284 0.0629] zeros(2,1) [.0067;.0019];…
zeros(1,2) 0 0;…
[.0067;.0019]’ 0 .5001];
fi1=[[0.9974 0.0539;-0.1078 1.1591] zeros(2,1);zeros(1,2) 0];
sigma=0.01;
landa1=[.0013;0.0539;1];

%%
cvx_begin
cvx_solver sedumi

variable S(3,3) symmetric
%S == semidefinite(3);
variable w(1,3)
variable alfa
alfa == semidefinite(1);
minimize(trace_inv(S))
subject to

[S zeros(3,3) (fi1*S+landa1*w).’ S.’ (sqrtm(Q1)*[S;w]).’;…
zeros(3,3) (2S-alfaeye(3,3)) (landa1w).’ zeros(3,3) (sqrtm(Q1)[zeros(3,3);w]).’;…
fi1S+landa1w landa1w S zeros(3,3) zeros(3,4);…
S zeros(3,3) zeros(3,3) eye(3,3)alfa/(sigma^2) zeros(3,4);…
sqrtm(Q1)
[S;w] (sqrtm(Q1)
[zeros(3,3);w]) zeros(4,3) zeros(4,3) eye(4,4)]==hermitian_semidefinite(16);

cvx_end
K=w*(S^-1)

Do you have any suggestions to deal with this problem?
Thanks a lot.


(Mark L. Stone) #4

Can you please show the output when CVX was run? What is S? What are the eigenvalues of the 16 by 16 matrix using this value of S? The solver might have allowed a (slightly) negative eigenvalue that is within numerical tolerance of being non-negative - that is allowed by the solver and CVX.

I am not sure I correctly input your data, but when I ran it, i got optimal S

   0.005207508798331  -0.001390406776616   0.001689749770110
  -0.001390406776616   0.015079016506942  -0.077603724194984
   0.001689749770110  -0.077603724194984   8.445670386947404

and min eigenvalue of 16 by 16 matrix = 1.766e-07. CVX/Sedumi appears to have correctly solved the problem I entered, although I am not positive I entered the problem correctly.


(helena.bbzd) #5

Hello
thank for your answer,but my problem has not been solved yet.
output is K
problem is to find S and alfa, provided that this big symmetric matrix is positive:

[S zeros(3,3) (fi1*S+landa1*w)’ S’ (sqrtm(Q1)*[S;w])’;…
zeros(3,3) (2S-alfaeye(3,3)) (landa1w)’ zeros(3,3) (sqrtm(Q1)[zeros(3,3);w])’;…
fi1S+landa1w landa1w S zeros(3,3) zeros(3,4);…
S zeros(3,3) zeros(3,3) eye(3,3)alfa/(sigma^2) zeros(3,4);…
sqrtm(Q1)
[S;w] (sqrtm(Q1)
[zeros(3,3);w]) zeros(4,3) zeros(4,3) eye(4,4)]

because of eigenvalue of the symmetric matrix is real…problem in cvx toolbax is solved,but when I check the eigenvalues:

84.2734 - 0.0000i
84.2410 + 0.0000i
84.2410 + 0.0000i
3.4118 - 0.0000i
2.0033 - 0.0000i
1.3105 - 0.0000i
0.7916 + 0.0000i
1.0001 + 0.0000i
0.9999 - 0.0000i
0.0212 - 0.0000i
0.0099 + 0.0000i
0.0064 - 0.0000i
0.0011 - 0.0000i
0.0000 - 0.0000i
0.0000 - 0.0000i
1.0000 - 0.0000i
eigenvalues have imaginary part!!!
I sent you m.file (in your email), the problem is so easy,however I can not solve it…

may you help me, I am really in difficult situation.
thanks


(Mark L. Stone) #6

What is the value of norm(imag(eig(big_matrix)),'inf') ?

I suspect the imaginary part is just due to roundoff-level asymmetry and can be ignored. If you want, you can symmetrize any matrix Q by setting Q = 0.5*(Q + Q’); which should eliminate roundoff-level asymmetry, and eliminate the imaginary part of its eigenvalues