CVXR: addressing non-diagonal elements of a matrix of variables

218 Views Asked by At

Suppose that in CVXR I have a definition A <- Variable(3,3) and would like to maximize the function "sum of the square roots of the non-diagonal elements". However, if I write something like sum(sqrt(A))-sum(sqrt(diag(A))), the first function being concave, but the second one too, this does not comply with the DCP Ruleset and therefore rejected by the CVX engine. However, it is clear that the function is concave -- we have simply removed some of the elements in the sum, there being no ways of saying "consider non-diagonal elements, please". What can be done?

1

There are 1 best solutions below

1
On

Have you tried writing the second term (term2 below) as a sum of the actual diagonals? For example,

e <- function(i, n = 3) {
  res <- numeric(n)
  res[i] <- 1
  res
}
diag_elem <- function(A, i) quad_form(e(i), A)
diags <- lapply(seq_len(3), diag_elem, A = A)
term2 <- sum(sqrt(do.call(vstack, diags)))