# Defining a lower triangular matrix as the decision variable in JuMP

**URL:** <https://discourse.julialang.org/t/defining-a-lower-triangular-matrix-as-the-decision-variable-in-jump/73372>\
**Category:** Optimization (Mathematical)\
**Tags:** jump\
**Created:** [December 20, 2021, 2:57pm UTC](https://discourse.julialang.org/t/defining-a-lower-triangular-matrix-as-the-decision-variable-in-jump/73372 "2021-12-20T14:57:06Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Shuvomoy\_Das\_Gupta](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/shuvomoy_das_gupta/32/10069_2.png) [@Shuvomoy\_Das\_Gupta](https://discourse.julialang.org/u/Shuvomoy_Das_Gupta)\
**Post date:** [December 20, 2021, 2:57pm UTC](https://discourse.julialang.org/t/defining-a-lower-triangular-matrix-as-the-decision-variable-in-jump/73372/1 "2021-12-20T14:57:06Z")

</div>

Dear All,

I am trying to define a decision variable L \in \mathbb{R}^{n\times n} in `JuMP`, which is lower triangular. As of now, I am defining this matrix as follows.

```julia
@variable(my_model, L_mat[1:n, 1:n])

# upper off-diagonal terms of L_mat are zero
for i in 1:n
       for j in 1:n
             if i < j
                 fix(L_mat[i,j], 0; force = true)
             end
        end
end

```

While this works for my purpose, I was wondering if there is a more efficient way to define this matrix in `JuMP`? The number n can be quite large for the example that I am trying to solve.

---

<div class="post-metadata">

**Author:** ![cvanaret](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/cvanaret/32/11594_2.png) [@cvanaret](https://discourse.julialang.org/u/cvanaret)\
**Post date:** [December 20, 2021, 11:58pm UTC](https://discourse.julialang.org/t/defining-a-lower-triangular-matrix-as-the-decision-variable-in-jump/73372/2 "2021-12-20T23:58:03Z")

</div>

The first thing you can do is to write your `j` loop from `i+1` to `n`.

---

<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 21, 2021, 7:34pm UTC](https://discourse.julialang.org/t/defining-a-lower-triangular-matrix-as-the-decision-variable-in-jump/73372/3 "2021-12-21T19:34:12Z")

</div>

No direct support.

But you could make a symmetric matrix and then form the lower triangle?

[https://jump.dev/JuMP.jl/stable/manual/variables/#Symmetric-variables](https://jump.dev/JuMP.jl/stable/manual/variables/#Symmetric-variables)

---

<div class="post-metadata">

**Author:** ![Shuvomoy\_Das\_Gupta](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/shuvomoy_das_gupta/32/10069_2.png) [@Shuvomoy\_Das\_Gupta](https://discourse.julialang.org/u/Shuvomoy_Das_Gupta)\
**Post date:** [December 21, 2021, 8:03pm UTC](https://discourse.julialang.org/t/defining-a-lower-triangular-matrix-as-the-decision-variable-in-jump/73372/4 "2021-12-21T20:03:49Z")

</div>

Yes, I tried that @odow , but for some reason, I got a “too few degrees of freedom” error using IPOPT for my problem when doing this (make a symmetric matrix and then form the lower triangle). Okay, for now, let me just stick to how I am defining it, I do not think this is a major issue for my problem. I was just curious to know if there is a direct way.

---

<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 21, 2021, 8:07pm UTC](https://discourse.julialang.org/t/defining-a-lower-triangular-matrix-as-the-decision-variable-in-jump/73372/5 "2021-12-21T20:07:38Z")

</div>

Too few degrees of freedom is usually when the problem is over determined. Do you have duplicate sets of constraints? It’s not a problem from the triangular matrix directly.

---

<div class="post-metadata">

**Author:** ![Shuvomoy\_Das\_Gupta](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/shuvomoy_das_gupta/32/10069_2.png) [@Shuvomoy\_Das\_Gupta](https://discourse.julialang.org/u/Shuvomoy_Das_Gupta)\
**Post date:** [December 21, 2021, 9:36pm UTC](https://discourse.julialang.org/t/defining-a-lower-triangular-matrix-as-the-decision-variable-in-jump/73372/6 "2021-12-21T21:36:35Z")

</div>

Yes, I think there are some duplicate constraints. Thanks @odow !
