# Minimizing variables rather than scalars?

Hello all. I’m pretty new to programming and SDP programming in general, and am getting the error
“ValueError: The ‘minimize’ objective must resolve to a scalar.” I know this is due to the fact that I am only using variables and not scalars and was wondering if anyone could give any advice on the subject. The problem I am trying to solve is

find: X,
subject to: trace(AₘX) = bₘ for 0 ≤ m ≤ M, and X is positive semi-definite.

and X = x*x_star, where x_star is the hermetian conjugate of x.

Is there any way that I can solve this minimization problem using variables rather than numbers? Here is some of the code that I did:

import cvxpy as cp
import numpy as np

# Vector variable with shape (4,).

x = cp.Variable((4,1))

#x_star = cp.Variable((1,4))
x_star = x.H

X = x @ x_star

cp.trace(X)

A1 = np.matrix([[0, 0, 0 , 0], [1, 0, 0 , 0],[0, 0, 0 , 0],[0, 0, 0 , 0]])
A2 = np.matrix([[1, 0, 0 , 0], [0, 1, 0 , 0],[0, 0, 0 , 0],[0, 0, 0 , 0]])
A3 = np.matrix([[0, 1, 0 , 0], [0, 0, 0 , 0],[0, 0, 0 , 0],[0, 0, 0 , 0]])
A4 = np.matrix([[0, 0, 0 , 0], [0, 0, 0 , 0],[0, 0, 0 , 0],[0, 0, 1 , 0]])
A5 = np.matrix([[0, 0, 0 , 0], [0, 0, 0 , 0],[0, 0, 1 , 0],[0, 0, 0 , 1]])
A6 = np.matrix([[0, 0, 0 , 0], [0, 0, 0 , 0],[0, 0, 0 , 1],[0, 0, 0 , 0]])
A7 = np.matrix([[0, 0, 0 , 0], [0, 0, 1 , 0],[0, 0, 0 , 0],[0, 0, 0 , 0]])
A8 = np.matrix([[0, 0, 1 , 0], [0, 0, 0 , 1],[0, 0, 0 , 0],[0, 0, 0 , 0]])
A9 = np.matrix([[0, 0, 0 , 1], [0, 0, 0 , 0],[0, 0, 0 , 0],[0, 0, 0 , 0]])
A10 = np.matrix([[0, 0, 0 , 0], [0, 0, 0 , 0],[0, 0, 0 , 0],[1, 0, 0 , 0]])
A11 = np.matrix([[0, 0, 0 , 0], [0, 0, 0 , 0],[1, 0, 0 , 0],[0, 1, 0 , 0]])
A12 = np.matrix([[0, 0, 0 , 0], [0, 0, 0 , 0],[0, 1, 0 , 0],[0, 0, 0 , 0]])

cp.trace(A1@X)

b1 = 1
b2 = 2
b3 = 3
b4 = 4
b5 = 5
b6 = 6
b7 = 7
b8 = 8
b9 = 9
b10 = 10
b11 = 11
b12 = 12

constraints = [cp.trace(A1@X) == b1,
cp.trace(A2@X) == b2,
cp.trace(A3@X) == b3,
cp.trace(A4@X) == b4,
cp.trace(A5@X) == b5,
cp.trace(A6@X) == b6,
cp.trace(A7@X) == b7,
cp.trace(A8@X) == b8,
cp.trace(A9@X) == b9,
cp.trace(A10@X) == b10,
cp.trace(A11@X) == b11,
cp.trace(A12@X) == b12]

#Semi-definite
constraints = [X>>0]

# Form objective.

obj = cp.Minimize(X)

# Form and solve problem.

prob = cp.Problem(obj, constraints)
prob.solve() # Returns the optimal value.
print(“status:”, prob.status)
print(“optimal value”, prob.value)
print(“optimal var”, x.value, y.value)

CVXPY is a different tool than CVX. I think you are now encouraged to post CVXPY help requests at https://discord.com/invite/SWUSgBu3Yz .