I am trying to do some quadratic optimization with linear constraints, using CVXR
.
I have the following matrix in R
:
HL <- matrix(c(
s[2]*sqp[2]*sqq[2],0,0,0,0,0,0,0,0,0,0,0,
0,s[3]*sqp[3]*sqq[3],0,0,0,0,0,0,0,0,0,0,
0,0,s[4]*sqp[4]*sqq[4],0,0,0,0,0,0,0,0,0,
0,0,0,s[1]*sqp[1]*sqq[1],0,0,0,0,0,0,0,0,
0,0,0,0,s[3]*sqp[3]*sqq[3],0,0,0,0,0,0,0,
0,0,0,0,0,s[4]*sqp[4]*sqq[4],0,0,0,0,0,0,
0,0,0,0,0,0,s[1]*sqp[1]*sqq[1],0,0,0,0,0,
0,0,0,0,0,0,0,s[2]*sqp[2]*sqq[2],0,0,0,0,
0,0,0,0,0,0,0,0,s[4]*sqp[4]*sqq[4],0,0,0,
0,0,0,0,0,0,0,0,0,s[1]*sqp[1]*sqq[1],0,0,
0,0,0,0,0,0,0,0,0,0,s[2]*sqp[2]*sqq[2],0,
0,0,0,0,0,0,0,0,0,0,0,s[3]*sqp[3]*sqq[3]
), nrow = num_vars, ncol = num_vars);
Then, I try to construct a DCP
Ruleset-complying form:
by first defining x = Variable(num_vars)
, and then writing
fnc <- t(x) %*% HL %*% HL %*% x
, or even something like y <- HL%*%x
,
and fnc <- t(y)%*%y
. According to DCP Ruleset (see Quadratic forms section), this should be recognized as convex. However, when I load
my source code into R
, I get
Forming a non-convex expression (affine) * (affine)
How to fix this? I need CVXR
to be able to recognize my function as "following DCP rules".