Hi, I want to minimize an objective function with expression obj=y + exp(-||x||^2/sigma^2), where y is a variable and x is a vector of variables. The objective is convex, while when I write code with CVX in matlab, as follows

variable y x(n,1);

obj = y+exp(-sum(x.^2)/sigma^2);

minimize(obj);

An error appears, saying “Illegal addition encountered (e.g., {convex} + {concave}).”

How can I solve this problem?

Your expression for obj should be accepted by CVX. However, your line

`variable y x(n,1);`

is invalid. You need to use `variables`

not `variable`

when declaring more than one variable in the statement.

If you are receiving the error you claim, please show a complete reproducible problem, with all inputs and output. If you are using CVX 3.0beta, please switch to CVX 2.1 because 3.0beta has many bugs, and incorrectly processes some code.

Thank you Mark. I don’t know why this thing happened, and can you please look through my code to see if I make any mistakes?

Here is the code:

```
cvx_begin
variables x_c(n_files_all,n_nodes);
variables x_en1(n_files_en1,n_bs1);
variables z_en1(n_files_en1,1);
variables y_en1(n_files_en1,n_bs1);
variables b_en1(n_requests_en1,1);
req_delay = [];
for req_idx = 1:n_requests_en1
request_cur = requests_idx_en1{req_idx};
n_files_req = length(request_cur);
im_diff = [];
ci_set = ci_mat_en1{n_files_req};
delay_set = delay_ci_en1{n_files_req};
for ci_idx = 1:length(ci_set)
im_set = ci_set{ci_idx};
en_delay = duration_time*delay_set(ci_idx);
for im_idx = 1:length(im_set)
im_mat = im_set{im_idx};
diff = y_en1(request_cur,:)-im_mat;
im_diff = [im_diff en_delay*exp(-sum(sum((y_en1(request_cur,:)-im_mat).^2))/sigma_^2)]; %%% errors here!!
end
end
req_delay = [req_delay sum(im_diff)];
end
obj = req_delay * prob_requests_en1;
minimize(obj);
cvx_end
```

And the error looks like this:

Error using cvx/sum (line 56)

Disciplined convex programming error:

Illegal addition encountered (e.g., {convex} + {concave}).

```
Error in cvx_test_1 (line 55)
req_delay = [req_delay sum(im_diff)];
```

The program extract in your first post is different than the program which generated the error - that is not good forum posting practice.

I don’t have time to look at this now. But please post a reproducible program, compete with all input data. And I suggest you examine all the elements in the offending sum. You can just type the element at the command line and CVX will tell you what kind of expression it is. That ought to reveal where your violation is.

Hi Mark, Thank you. Since the parameters are relatively large, so I stored them in a mat file, Please find the input parameter in this link, and the code file in this link. Thank you!

Everything on this forum is handled on this forum, nit by data posted elsewhere. Try to produce a small sized problem exhibiting the behavior and make the post self-contained. Better yet, follow my debugging instructions and look at each element of the sum prior to the error message.

for i=1:whatever

im_diff(i)

end

CVX will tell you what kind of expression each one is. Then ,more closely examine the ones which are not as expected.