# A simple question of cvx

I study the noise source identification.
recently， l meet the problem that l defined d as a nonnegative vector ，but the solution was always nonpositive.just like this:

cvx_begin;
variable d(N) nonnegative ;
B - diag(d,0)== hermitian_semidefinite(N);
maximize(sum(d));
cvx_end;

the B is an hermitian_semidefinite matrix.My goal is to make sum(d） positive and maximum,with constrain B is maintaining the positive semidefinite.
Think you in advance! I can’t reproduce what you’ve done because you haven’t provided B.

You haven’t shown us the optimal d returned by CVX. Given that cvx_optval = -4.44932e-9, there must be some at least slightly negative elements in the optimal d. My guess is that they are within solver tolerance of being non-negative. For instance, on a random B I generated, the minimum element of the optimal d = -5.88e-8, which is within solver tolerance of being non-negative.

You could specify a small positive number small_positive_number as the minimum value, such as 1e-6, and then use the constraint
`d >= small_positive_number`
instead of declaring d(N) to be nonnegative.
Then the optimal d should not be negative. Alternatively, you could adjust any slightly negative elements of d to be nonnegative, but then you might make the semidefinite constraint be not quite satisfied.

Thank you for your answers！According to your suggestion，l specify a small positive number,and the solution turns to be nonnegative,which is +0.24e-3, but it is too small to eliminate the elements of diag(B). Is there anything wrong with the configuration of CVX ?
the B is a NN hermitian matrix,which N =49. B=PalPal '
Pal=
0.866701761916501 + 1.80139375969769i
-1.95750656766746 + 0.408902519796787i
-1.17400115275834 - 1.61955607543657i
-0.465872019046931 - 1.94451929053861i
-1.17348902384097 - 1.61553278706199i
-1.95979641030267 + 0.403452074257526i
0.868412729350765 + 1.80296201780184i
-1.95806018402192 + 0.407055161328690i
0.324421572911668 - 1.97465311501604i
1.97153086319872 - 0.340575175496189i
1.93729472698983 + 0.501676138080329i
1.97310911632796 - 0.342673786698576i
0.325943122537453 - 1.97544579374486i
-1.95759510120595 + 0.407180924057807i
-1.17844734060293 - 1.61635899413986i
1.97109883682816 - 0.337660794916104i
0.860668560069558 + 1.80704746657220i
-0.00945409605482716 + 1.99753675686199i
0.856860436391387 + 1.80664619754998i
1.97392469519793 - 0.341425623880660i
-1.17403534028238 - 1.61869656114536i
-0.465757360751684 - 1.94543344277092i
1.93439100895036 + 0.502937454306510i
-0.00968698459525739 + 1.99278618899876i
-0.887150436083951 + 1.78965853981927i
-0.00820327013399770 + 1.99896343930284i
1.93651223589906 + 0.500689402400361i
-0.466595908708565 - 1.94581601234234i
-1.17863469871563 - 1.61862643515129i
1.97115289820515 - 0.342705938998719i
0.863085626474800 + 1.81281120385290i
-0.0107496529080428 + 1.99802883160638i
0.857158563503044 + 1.80370807782384i
1.97024442630021 - 0.341498016974731i
-1.17582050814011 - 1.62052275529432i
-1.95463208094277 + 0.409654258883881i
0.323774389815719 - 1.97378588967247i
1.96940885043145 - 0.342407172015919i
1.93473148370300 + 0.499674094664398i
1.97090076168027 - 0.342947026987810i
0.325974676322496 - 1.97404154198249i
-1.95836761459166 + 0.407989368694832i
0.868765370788883 + 1.80384895712247i
-1.95669056897114 + 0.401349441264875i
-1.17764867701844 - 1.61616070625235i
-0.464366144404880 - 1.94803324687166i
-1.17221712098120 - 1.61768945395217i
-1.96140364842845 + 0.406560444727349i
0.868776223482654 + 1.80426234383104i

I don’t know what you mean by

but it is too small to eliminate the elements of diag(B).

I read in Pal, formed B, then executed

N=49;
cvx_begin
variable d(N)
d >=1e-8
B - diag(d,0) == hermitian_semidefinite(N)
maximize(sum(d))
cvx_solver sdpt3
cvx_end

Result is
cvx_optval = +3.28872e-07, min(d) = 6.711493410820829e-09.

Using SeDuMi, cvx_optval =: +3.91062e-09, min(d) = 7.861089211967724e-11.

So this is as I predicted in my first post.
Note that you need to pay attention to Status returned by CVX. When I used d >= 1e-6, Status was Inaccurate/Solved for both SDPT3 and SeDuMi.