# JuMP: declaring a vector of PSD matrices

**URL:** <https://discourse.julialang.org/t/jump-declaring-a-vector-of-psd-matrices/126179>\
**Category:** Optimization (Mathematical)\
**Tags:** jump\
**Created:** [February 22, 2025, 10:45am UTC](https://discourse.julialang.org/t/jump-declaring-a-vector-of-psd-matrices/126179 "2025-02-22T10:45:55Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![healyp](https://avatars.discourse-cdn.com/v4/letter/h/67e7ee/32.png) [@healyp](https://discourse.julialang.org/u/healyp)\
**Post date:** [February 22, 2025, 10:45am UTC](https://discourse.julialang.org/t/jump-declaring-a-vector-of-psd-matrices/126179/1 "2025-02-22T10:45:55Z")

</div>

in JuMP it’s very straightforward to declare a PSD matrix variable. If S \succeq 0, I can simply say

```julia
@variable(m, S[1:4,1:4], PSD)

```

But if I now want a set, or vector, of them, like, S\_i \succeq 0, i \in [1,\ldots,k] I’m not sure of how to achieve this. Is it possible?

Clearly

```julia
@variable(m, S[1:k,1:4,1:4], PSD)

```

doesn’t work.

Many thanks.

---

<div class="post-metadata">

**Author:** ![odow](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/odow/32/28685_2.png) [@odow](https://discourse.julialang.org/u/odow)\
**Post date:** [February 22, 2025, 6:48pm UTC](https://discourse.julialang.org/t/jump-declaring-a-vector-of-psd-matrices/126179/2 "2025-02-22T18:48:47Z")

</div>

Hi @healyp

Do something like:

```Julia
julia> using JuMP

julia> model = Model();

julia> S = [@variable(model, [1:4,1:4], PSD, base_name = "S$k") for k in 1:3]
3-element Vector{LinearAlgebra.Symmetric{VariableRef, Matrix{VariableRef}}}:
 [S1[1,1] S1[1,2] S1[1,3] S1[1,4]; S1[1,2] S1[2,2] S1[2,3] S1[2,4]; S1[1,3] S1[2,3] S1[3,3] S1[3,4]; S1[1,4] S1[2,4] S1[3,4] S1[4,4]]
 [S2[1,1] S2[1,2] S2[1,3] S2[1,4]; S2[1,2] S2[2,2] S2[2,3] S2[2,4]; S2[1,3] S2[2,3] S2[3,3] S2[3,4]; S2[1,4] S2[2,4] S2[3,4] S2[4,4]]
 [S3[1,1] S3[1,2] S3[1,3] S3[1,4]; S3[1,2] S3[2,2] S3[2,3] S3[2,4]; S3[1,3] S3[2,3] S3[3,3] S3[3,4]; S3[1,4] S3[2,4] S3[3,4] S3[4,4]]

julia> S[1]
4×4 LinearAlgebra.Symmetric{VariableRef, Matrix{VariableRef}}:
 S1[1,1] S1[1,2] S1[1,3] S1[1,4]
 S1[1,2] S1[2,2] S1[2,3] S1[2,4]
 S1[1,3] S1[2,3] S1[3,3] S1[3,4]
 S1[1,4] S1[2,4] S1[3,4] S1[4,4]

```

A useful tip to remember is that JuMP’s built-in data structures are there to help in common cases, but you don’t need to use only them. You can, for example, build your own vector of JuMP matrices, or a dictionary, or whatever is the most appropriate data structure for your problem.
