Container of PSD variables in JuMP

What is the best way to create a container of PSD “variables” such that
X[i] = i-th PSD variable?

To create a vector of 10 PSD variables of size 1x1, 2x2, …, 10x1:

X = Vector{Symmetric{Matrix{VariableRef}}}(undef, 10)
for i in 1:10
    X[i] = @variable(model, [1:i, 1:i], PSD)


If you don’t want to have to infer the type of the container yourself:

using JuMP

model = Model()
X = [@variable(model, [1:i, 1:i], PSD) for i in 1:10]
1 Like