function grad = grad_cond_bd(n,A,lb,ub,t)

grad = 0;
for i = 1:n
  for j = 1:n
    if A(i,j) > ub(i,j)*t
      grad = grad - ub(i,j)*(A(i,j) - ub(i,j)*t);
    end
    if A(i,j) < lb(i,j)*t
      grad = grad - lb(i,j)*(A(i,j) - lb(i,j)*t);
    end
  end
end