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

**URL:** <https://discourse.julialang.org/t/how-to-define-a-lower-triangular-variable-without-the-main-diagonal-elements/92112>\
**Category:** Optimization (Mathematical)\
**Created:** [December 25, 2022, 8:24pm UTC](https://discourse.julialang.org/t/how-to-define-a-lower-triangular-variable-without-the-main-diagonal-elements/92112 "2022-12-25T20:24:59Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![ivzktch99](https://avatars.discourse-cdn.com/v4/letter/i/b19c9b/32.png) [@ivzktch99](https://discourse.julialang.org/u/ivzktch99)\
**Post date:** [December 25, 2022, 8:24pm UTC](https://discourse.julialang.org/t/how-to-define-a-lower-triangular-variable-without-the-main-diagonal-elements/92112/1 "2022-12-25T20:24:59Z")

</div>

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

```julia
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

---

<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:** [December 27, 2022, 6:08am UTC](https://discourse.julialang.org/t/how-to-define-a-lower-triangular-variable-without-the-main-diagonal-elements/92112/2 "2022-12-27T06:08:12Z")

</div>

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

```julia
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

```

---

<div class="post-metadata">

**Author:** ![ivzktch99](https://avatars.discourse-cdn.com/v4/letter/i/b19c9b/32.png) [@ivzktch99](https://discourse.julialang.org/u/ivzktch99)\
**Post date:** [December 27, 2022, 5:06pm UTC](https://discourse.julialang.org/t/how-to-define-a-lower-triangular-variable-without-the-main-diagonal-elements/92112/3 "2022-12-27T17:06:10Z")

</div>

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

---

<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:** [December 27, 2022, 5:53pm UTC](https://discourse.julialang.org/t/how-to-define-a-lower-triangular-variable-without-the-main-diagonal-elements/92112/4 "2022-12-27T17:53:26Z")

</div>

Eliminates. There are only 3 decision variables in the model
