Problem about rel_entr

Hi. i try to use

K>> -(rel_entr(alpha1(i),alpha1(i) + (E(i)*(abs(g_du(i)))^2)/(P_cu_1*(abs(g_cu_du(1,(i))))^2 + P_cu_2*(abs(g_cu_du(2,(i))))^2 + sigma2_w)))

instead of

> K>> alpha1(i)*log10(1 + (E(i)*(abs(g_du(i)))^2)/(alpha1(1)*(P_cu_1*(abs(g_cu_du(1,i)))^2 + P_cu_2*(abs(g_cu_du(2,i)))^2 + sigma2_w)))

in my cvx problem and when the problem is solved for my variables like E and alpha1, i put these variables in rel_entr and i see the final value is different with alpha1*log2(1+...) as i wrote above. i mean rel_entr value is different from simple form and is less.

You mention log2, but your “instead of” code has log10. Furthermore, rel_entr is based on log base e, i.e., ln. i.e. what is log in MATLAB

log10(x) = -rel_entr(1,x)/log(10)
log2(x) = -rel_entr(1,x)/log(2)

For example,

 x=1.234; % made up number for illustrative purposes
disp([log10(x) -rel_entr(1,x)/log(10)])
   0.091315159697223   0.091315159697223

I don’t have the energy to verify everything with your parentheses, so I will just say that you should use the formula
alpha(i)*log(1+a/(b*alpha(i))) = -rel_entr(alpha(i),alpha(i)+a/b)
Perhaps that is what you have, other than missing the log conversion factor which you need to fix, depending on what log base you are actually trying to use.

1 Like

Thank you for your patience. you really helped me a lot.

What’s the problem with this? Can you help me see

maximize( -rel_entr(t2,1+lo1*(tao1/t2))/log(2));
错误使用 .* (line 173)
Disciplined convex programming error:
Cannot perform the operation: {positive constant} ./ {real affine}

The arguments of rel_entr apparently are not in compliance with the rules stated below. If lo1*tao < 0, you can use inv_pos

Please show us the mathematical expression which you wish to maximize, making clear what the optimization variables are.

help rel_entr

rel_entr Scalar relative entropy.
rel_entr(X,Y) returns an array of the same size as X+Y with the
relative entropy function applied to each element:
{ X.*LOG(X./Y) if X > 0 & Y > 0,
rel_entr(X,Y) = { 0 if X == 0 & Y >= 0,
{ +Inf otherwise.
X and Y must either be the same size, or one must be a scalar. If X and
Y are vectors, then SUM(rel_entr(X,Y)) returns their relative entropy.
If they are PDFs (that is, if X>=0, Y>=0, SUM(X)==1, SUM(Y)==1) then
this is equal to their Kullback-Liebler divergence SUM(KL_DIV(X,Y)).
-SUM(rel_entr(X,1)) returns the entropy of X.

Disciplined convex programming information:
    rel_entr(X,Y) is convex in both X and Y, nonmonotonic in X, and
    nonincreasing in Y. Thus when used in CVX expressions, X must be
    real and affine and Y must be concave. The use of rel_entr(X,Y) in
    an objective or constraint will effectively constrain both X and Y 
    to be nonnegative, hence there is no need to add additional
    constraints X >= 0 or Y >= 0 to enforce this.

Dear expert, Thanks for your time. The following are my optimization goals and variables, I don’t know where the problem is, how to rewrite it.

            variable t1
            variable t2
            variable tao1
            variable tao2
            variable W
            variable V2
            maximize ((-rel_entr(t2,(t2+lo1/1*tao1))+log(1)*t2)/log(2)) % maximize( t2*log2(1+lo1*(tao1/t2)) )  %lo1=trace(V2*Fa2)/noisepow_Bob;
            subject to

Thank you for helping me answer it, thank you very much!

I’ll assume maximize( t2*log2(1+lo1*(tao1/t2)) is what you really want.

That is

The argmax won’t be affected if you don’;t bother with /log(2)

Thank you for answering me, I have encountered another problem, please help me to see it again.

从 cvx 转换为 double 时出现以下错误:
无法从 cvx 转换为 double。

出错 main (line 101)
a(logical(eye(size(W))))=t1; %Represents the W matrix with n rows and n columns as t1

A pro tip. Start a new thread if your topic is unrelated the rest of the thread.

I have no idea what you are trying to do with a(logical(eye(size(W))))=t1;
I.e. what purpose it serves. I have no idea what a is.

But in any event, in order to be valid CVX syntax (whether or not it makes any sense for your problem), you either need == instead of =. Or don’t declare t a variable, and change it to t1 being the LHS of the =.

Dear expert,
Thanks for your time. I still have this problem.
错误使用 cvx/rel_entr (line 71)
Disciplined convex programming error:
Illegal operation: rel_entr( {real affine}, {complex affine} ).

出错 main (line 98)
maximize (-rel_entr(t2,t2+lo1*tao1)/log(2))

Thank you for helping me answer it, thank you very much!

Is lo1 a complex number? If so, the objective function would not evaluate to a real scalar, which would not make any sense.

I want to show the W matrix with n rows and n columns as t1,logical(eye(size(W)))==t1,

lo1 a complex number. Is there any way to solve it?

I still have no idea what you’re trying to do. W was declared a scalar variable.

As I wrote before, the objective function must evaluate to a real scalar.

What if the objective function were allowed to evaluate to a complex number? Which is a bigger (better) objective value, 2 + i or 3 - i? Of course that doesn’t make sense. You need to formulate an optimization problem whose objective function evaluates to a real scalar. If you wish to use CVX, it must be a convex optimization problem following CVX’s rules.

Dear expert, Thanks for your time. I want to consult a question.
Status: Infeasible
Optimal value (cvx_optval): -Inf

错误使用 + (line 83)
Disciplined convex programming error:
Illegal operation: {invalid} + {real affine}

出错 main (line 155)

What’s the problem with this? Can you help me see.

This looks like one CVX problem was infeasible. Therefore, the CVX variable values had value “NaN”. You perhaps then used variable values from this CVX problem as input data into a new CVX problem. CVX then issued an error because NaN values were used in a CVX expression.

Dear expert, Thanks for your time. I want to consult a question.
错误使用 .* (line 262)
Disciplined convex programming error:
Invalid quadratic form(s): not a square.

出错 * (line 36)
z = feval( oper, x, y );

出错 Untitled (line 122)
What’s the problem with this? Can you help me see.

cvx_begin quiet
            variable t1
            variable t2
            variable tao1
            variable tao2
            variable V1(length(V1),length(V1)) 
            subject to