How to define a lower triangular variable WITHOUT the main diagonal elements

Searching here I found the following way of defining a lower triangular variable in JuMP:

using JuMP
import LinearAlgebra
model = Model()
@variable(model, A[1:3,1:3], Symmetric)
Al = LinearAlgebra.LowerTriangular(A)

julia> @expression(model, Al * [1, 2, 3])
3-element Vector{AffExpr}:
 A[1,1]
 A[1,2] + 2 A[2,2]
 A[1,3] + 2 A[2,3] + 3 A[3,3]

I would like to know if there is any way to additionally eliminate the main diagonal elements (i.e., A_11,A_22,A_33, …) rather than setting them to zero. That is to define Strictly Lower Triangular Matrix

1 Like

There’s no specialized support, but you could do:

julia> using JuMP

julia> import LinearAlgebra

julia> model = Model();

julia> @variable(model, x[i=1:3, j=(i+1):3])
JuMP.Containers.SparseAxisArray{VariableRef, 2, Tuple{Int64, Int64}} with 3 entries:
  [1, 2]  =  x[1,2]
  [1, 3]  =  x[1,3]
  [2, 3]  =  x[2,3]

julia> X = LinearAlgebra.LowerTriangular(
           [i < j ? x[i, j] : 0 for j in 1:3, i in 1:3]
       )
3×3 LinearAlgebra.LowerTriangular{Any, Matrix{Any}}:
 0         ⋅        ⋅
  x[1,2]  0         ⋅
  x[1,3]   x[2,3]  0
1 Like

Thank you! Does that eliminate the diagonal variables or equate them to zeros (I can’t tell)?

1 Like

Eliminates. There are only 3 decision variables in the model