# Need help with sum of max terms in cvx

Hi! I am trying to code the following constraint in cvx:

d^Tu + sum_{k=1}^K max_{j \in I_k} {V_j^Td + b_j} \leq tau

Can somebody help me please? I thought of using an epigraph formulation and code it in the following way (note: only the part of the code concerning this constraint is shown, but it contains more constraints like these):

Ivert = 5;
K = 10;
n = 5;
A = -5 + 10rand(IvertK,5);
Ivert = 5;
K = 10;
I = [];
for k = 1:K
I(:,k) = [1+5*(k-1):Ivert+5*(k-1)];
end
D1 = eye(5);
D2 = -eye(5);
D = cat(1,D1,D2);
ub = [5/1,5/2,5/3,5/4,5/5]’;
lb = [1/5,2/5,3/5,4/5,5/5]’;
d = cat(1,ub,-lb);

cvx_begin

variable tau;
variable V(size(D,1),K*Ivert)
variable u(size(D,1))
variable epi1(K,1)
variable epi2(K,n)
variable epi3(K,size(D,1))

minimize(tau)
subject to

for k = 1:K
for j = I(1,k):I(end,k)
epi1(k) <= V(:,j)’*d;
end
end

constraint1term = d’*u;
for k = 1:K
constraint1term = constraint1term + max(epi1(k));
end

constraint1term <= tau;

cvx_end

But I do not think this is correct since using the whole code I get -infinity as optimal value while this should not be the case. Thank you in advance!

 max(epi1(k)) is just  epi1(k) because epi1(k) is a scalar.
max(epi1) is the maximum of al elements in the vector epi1.

Hopefully this gives you enough of a clue that you can fix your program.

You are right. I also changed epi1(k) <= V(:,j)'d* to epi1(k) >= V(:,j)'d*. Thank you!