# How to solve the issue "value of type 'cvx' is not convertible to 'double'."

Hello,
Kindly suggest me in following code, as I am getting a error.

Unable to perform assignment because value of type ‘cvx’ is not convertible to ‘double’.

The following is code,

## M=8; K=3; N0=10^-12; for i=1:K cvx_begin variable f(K) nonnegative; variable a_k(M,K); >>>>>>>Doubt: is this correct assignment? a_k is a matrix of M*K % Objective function R_k(i)=-rel_entr(N0,N0+f(i)*v1(i))/log(2); % v1(i) is already predetermined value. maximize : I want to maximize sum of R_k(i) i.e R_k(1)+ R_k(2)+ R_k(3) % Constraints subject to

With that code, as discussed in The Basics — CVX Users' Guide , you need to declare
`expression R_k(K)`
before first using `R_k`.

However, `rel_entr` can accept vector arguments. So you need not ever explicitly form `R_k` or use or declare it. You can just `sum(rel_entr(....)`.

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