Help: Cannot perform the operation: {real affine} .* {concave}

Hello guys, I had an error in my code, which is showing “Cannot perform the operation: {real affine} .* {concave}”.
For simplicity, I selected the wrong part and rewrite it as:

cvx_begin

variable x(4,4)
expression obj

obj = 0;
for k=1:4
    for n=1:4
        obj = obj + ( x(k,n)*log(x(k,n))+(1-x(k,n))*log(1-x(k,n)) );
    end
end
minimize(obj)

subject to

    for k=1:4
        for n=1:4
            x(k,n) <= 1;
            x(k,n) >= 0;
        end
    end

cvx_end


The main query is: The objective function “x*logx+(1-x)*log(1-x)” is convex, the code is supposed to find the lowest point, however, it says:

Disciplined convex programming error:
Cannot perform the operation: {real affine} .* {concave}

Thank you for your help.

cvx_begin
variable x(4,4)
minimize(sum(sum(-entr(x)-entr(1-x))))
0 <= x <= 1
cvx_end

Actually, 0 <= x <= 1 is not needed, because it is effectively imposed by entr(x) and entr(1-x)

The optimal solution has all elements of x = 0.5.

help entr

 entr   Scalar entropy.
    entr(X) returns an array of the same size as X with the unnormalized
    entropy function applied to each element:
                 { -X.*LOG(X) if X > 0,
       entr(X) = { 0          if X == 0,
                 { -Inf       otherwise.
    If X is a vector representing a discrete probability distribution, then
    SUM(entr(X)) returns its entropy.
 
    Disciplined convex programming information:
        entr(X) is concave and nonmonotonic in X. Thus when used in CVX
        expressions, X must be real and affine. Its use will effectively 
        constrain X to be nonnegative: there is no need to add an
        additional X >= 0 to your model in order to enforce this.

Thank you very much, Mark! :grin: