# Error:illegal operation: {invalid} + {mixed real affine/constant}

hello,professor.
I would like to ask what causes this error(Error message such as title). The problems are as follows
cvx begin sdp
variable x;
variable y;
min (Ax+b)'q(Ax+b)+(Cx-Dy)'r(Cx-Dy)
Where A,b,C,D,q,r are satisfactory constants
3Q very much

I’m not sure what you mean by “satisfactory” constants, but apparently, they are not all satisfactory. The error message might be because one or more of the constants are `NaN`,. You should check the values of all constants in order to diagnose the error.

I’m sorry, maybe I made a mistake. Maybe it’s another expression. The program is as follows. Do you know how to express it in CVX？
variable x;
min trace(x’qx)
Where q is constants

Do you mean that `x` is a vector, and `q` is a psd matrix? Then `x'*q*x` is a convex expression, which CVX accepts Because it is a scalar `trace(x'*q*x)` is the same as 'x’qx. So perhaps you mean something else? In which case I don’t know what you intend.

If `x` is a vector of length `n`, it should be declared as
`variable x(n)`

If you declare `x` and `y` as vectors, your original program should be accepted by CVX if `q` and `r` are psd matrices.

``````q= rand(3);
q=q*q';
r=rand(3);
r=r*r';
A=rand(3);
b=rand(3,1);
C=rand(3);
D=rand(3);
cvx_begin
variables x(3) y(3)
minimize((A*x+b)'*q*(A*x+b)+(C*x-D*y)'*r*(C*x-D*y))
cvx_end``````

x is not a vector, it’s a matrix,More detailed definition of the following procedures, and its error is as follows

``````R=rand(3,3);
G=rand(6,3);
W=rand(3,3);
cvx_begin
variable M(3,6);
minimize trace(R*M*G*W*G'*M'*R')
cvx_end
``````

error:Disciplined convex programming error:
Only scalar quadratic forms can be specified in CVX

Presuming `W` is psd, you can reformulate
`trace(R*M*G*W*G'*M'*R')`
as
`square_pos(norm(chol(W)*G'*M'*R','fro'))`

Given that this is the objective function, there is no need to square, so just use
`minimize(norm(chol(W)*G'*M'*R','fro'))`

If `W` is not psd, I think this is non-convex.

Thank you professor. My problem has been solved. Your selfless help has solved a big problem for me. Thank you very much

A more generally applicable solution, in case `W` is psd, but might be singular, in which case `chol(W)` does not exist, is to use `sqrtm(W)` in place of `chol(W`), in my reformulation above.

Not a prof, just an ordinary Joe.