log_det for Hermitian Matrices

Hello Friends,

I am trying to calculate the following function:

log( eye(N) + H*X*H' )

where N=1 and H is a 1 by 2 matrix and X is a 2 by 2 matrix. When I change the dimensions of H and X to 1 by 3 and 3 by 3 respectively, I get an error saying that:

Error using cvx/log (line 64)
Disciplined convex programming error:
Illegal operation: log( {complex affine} ).

I have studied the CVX user guide, but I still cannot find the source of the problem.

Thank you in advance.

The problem is likely that there is a very small imaginary portion in your argument, due to roundoff error. Try doing

log( real( eye(N) + H*X*H' ) )

to see if that fixes things for you.

Keep in mind that logarithms require the use of CVX’s successive approximation algorithm and are less reliable and slower. I suggest that you avoid the use of log if you can reformulate your problem in an equivalent fashion without it. For instance, if this is the objective function for your model, you can simply drop the log altogether.

NOTE: once you get N > 1, you will be using log_det, and you do not want to use real there. Instead use something like this:

log_det( eye(N) + H*X*H' )

If CVX complains that the quantity eye(N) + H*X*H' is not symmetric due to roundoff errors, try this:

log_det( eye(N) + 0.5* ( H*X*H' + (H*X*H')' ) )

Dear Michael,

using the real operator solves the error; however, I have tested that using real operator changes the answer. I am not sure if using the real operator be the answer. May be when the imaginary part is very small this works, I have also seen in some cases the imaginary part is very small, so using the real operator will solve the problem. In conclusion, I think we must first avoid using the real operator especially when it comes to “log_det”.

Well, you cannot take the logarithm of a complex number in CVX. So I’m really not sure what you mean when you say that real changes the answer. In this case, the imaginary part should be 0 in perfect arithmetic. But if in other cases the imaginary part is non-trivial, there is a model problem.

Alright, I agree with you about the log function. However, when I am using the log_det built-in function, using the “real” operator like “log_det( real(A) )” changes the answer, may be we should apply it after the “det” operator which does not seem to be possible for the “log_det” function.

Ah, yes, that’s different. In that case, you’d want to do log_det( A ) or perhaps log_det( 0.5*(A+A') ). The trick here is not to get a real value, but a Hermitian value.