I am working on a convex optimization problem that needs to define several (e.g. 5) symmetric matrices as variables. I was wondering if it is possible to define those variables with a single line like @variable(m, x(N,N,M), Symmetric), where N is the dimension of the matrix, and M is the number of copies of symmetric matrices. Then I can access a symmetric matrix by, e.g., x[:,:,1].

The second code works for me. I also have two tips for implementing this as a future reference:

In order to make the model more readable, I set the names of the matrices as follows: x = [@variable(m, [1:N, 1:N], base_name = "x$i", Symmetric) for i in 1:M]. Then in the printed model an item in the first matrix looks like this: x1[i,j].

To access the ith matrix, use x[i][:,:]

For the first option though, I get a bug from x = Matrix{JuMP.VariableRef}(undef, 2, 2, 3), which says MethodError: no method matching Array{VariableRef,2}(::UndefInitializer, ::Int64, ::Int64, ::Int64). I assume this is because JuMP does not support 3-dimensional variables.