Why this error,Cannot perform the operation: {real affine} .* {convex}

for example: A is a variable, B is a varizble
the goal function: A* -log(B) this is error

the goal function: A*-log(B/A) this is reeor too,but all of this is the convex

what should i do?

A*(-log(B)) is indefinite, and therefore non-convex.

A*(-log(B/A)) can be handled using rel_entr…
A*(-log(B/A)) = A*log(A/B) = rel_entr(A,B)

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.

thanks,
the 2th function is the same as the rel_entr
but the 1th function isn’t,it can’t accept this rel_entr

As i wrote above, A*(-log(B)) is indefinite, and therefore non-convex. It will not be accepted by CVX and can not be transformed into a form which will be accepted by CVX.

Thanks for answer, I have summarized my question in detail by the following codes:
clear all; clc; close all;
% load h_kn_1;

M = 4; %小区数
N = 5; %载波数,每个用户的通信速率大概是470
L = 8; %码字数(最大为24,小于N_beamK_m):L的值应该小于用户总数,否则会出现1个载波能放下所有用户的情况
K_m = 8; %每个波束的用户数(假设一致),改动1:使其小于资源(保证1个用户可占用多个sub)
P_max = 251;
delt = 3e-16
ones(M,K_m,N);
R_req_1 = randi([200,250],M,K_m); %改动2:不可太小,否则约束C5和C6冲突,CVX_status = fail

fai =10; %改动3:应该与目标函数在同一数量级,获得一个可solved的初值
cvx_begin quiet
cvx_solver sdpt3 %sedumi
variable s(M,K_m,N) %三维变量
variable mu(M,K_m,N) %三维变量
variable P(M,K_m,N)
minimize(sum(sum(sum(mu)))+ sum(sum(sum(fai*s))));
% Constraints
subject to
%s
0<= s <=1;
for n = 1:N
sum(sum(s(:,:,n)))<= L;
end
for m =1:M
for k = 1:K_m %任选一个用户,至少分配一个载波
sum(s(m,k,:)) >= 1;
end
end

%power
sum(sum(sum(mu))) <= P_max;
mu <= P_max.*s;
mu <= P;
mu >= 0;
mu >= P-(1-s).*P_max;

for m = 1:M
for k = 1:K_m
rate(m,k) = sum(- rel_entr(s(m,k,:).*delt(m,k,:),s(m,k,:).*delt(m,k,:)+mu(m,k,:).*0.3)./delt(m,k,:)./log(2));
end
end
rate >= R_req_1;

cvx_end
cvx_clear
cvx_status

and the result is
CVX Warning:
Models involving “rel_entr” or other functions in the log, exp, and entropy
family are solved using an experimental successive approximation method.
This method is slower and less reliable than the method CVX employs for
other models. Please see the section of the user’s guide entitled
The successive approximation method
for more details about the approach, and for instructions on how to
suppress this warning message in the future.

Successive approximation method to be employed.
For improved efficiency, SDPT3 is solving the dual problem.
SDPT3 will be called several times to refine the solution.
Original size: 1510 variables, 640 equality constraints
160 exponentials add 1280 variables, 800 equality constraints

Cones | Errors |
Mov/Act | Centering Exp cone Poly cone | Status
--------±--------------------------------±--------
0/ 0 | 0.000e+00 0.000e+00 0.000e+00 | Solved

Status: Solved
Optimal value (cvx_optval): +320

cvx_status =

'Solved'

Notedly, I output the value of rate, that is
rate

rate =

1.0e+05 *

5.8056    5.8054    5.8053    5.8054    5.8056    5.8054    5.8055    5.8055
5.8053    5.8053    5.8055    5.8055    5.8056    5.8054    5.8053    5.8057
5.8055    5.8054    5.8053    5.8053    5.8055    5.8056    5.8055    5.8055
5.8053    5.8053    5.8053    5.8053    5.8056    5.8053    5.8054    5.8056

However, when I re-calculate the value of rate after optimization in the command window, that is
for m = 1:M
for k = 1:K_m
ans(m,k) = sum(- rel_entr(s(m,k,:).*delt(m,k,:),s(m,k,:).*delt(m,k,:)+mu(m,k,:).*0.3)./delt(m,k,:)./log(2));
end
end

ans

ans =

22.5155 22.5155 22.5155 22.5155 22.5155 22.5155 22.5155 22.5155
22.5155 22.5155 22.5155 22.5155 22.5155 22.5155 22.5155 22.5155
22.5155 22.5155 22.5155 22.5155 22.5155 22.5155 22.5155 22.5155
22.5155 22.5155 22.5155 22.5155 22.5155 22.5155 22.5155 22.5155
Why the values of “rate” and “ans” are so different. I think the only difference between them is the former one is calculated by using “s” and “mu” during the optimization process, while the latter one is calculated by using “s” and “mu” when the optimization process solved. BUT what is value of “s” and “mu” during the optimization process? Can I see them, I wonder why the value of rate is so large.

And because the value of rate is larger than the true value(I think the value of answer is the true value), it is obvious to satisfy the constraint “rate >= R_req_1”, and the optimization stops, which may lead to wrong results.

I think you posted this in the wrong thread, I gave you the answer at The value of the variable in the optimization process is inconsistent with the calculation result of the optimization result . Although I think you needed to also declare rate as an expression (holder).