# Block triangular matrix in Convex.jl

**URL:** <https://discourse.julialang.org/t/block-triangular-matrix-in-convex-jl/118147>\
**Category:** Optimization (Mathematical)\
**Tags:** convex-optimization, convex\
**Created:** [August 13, 2024, 4:49pm UTC](https://discourse.julialang.org/t/block-triangular-matrix-in-convex-jl/118147 "2024-08-13T16:49:39Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![jens-rataczak](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jens-rataczak/32/211309_2.png) [@jens-rataczak](https://discourse.julialang.org/u/jens-rataczak)\
**Post date:** [August 13, 2024, 4:49pm UTC](https://discourse.julialang.org/t/block-triangular-matrix-in-convex-jl/118147/1 "2024-08-13T16:49:39Z")

</div>

Hello,

Is there a straightforward way to constrain a variable in Convex.jl to be block triangular (either upper or lower)? I am looking for something like YALMIP’s `blkvar` command. It seems rather tedious to constrain the upper/lower elements of a matrix to be zero. Thank you!

---

<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:** [August 13, 2024, 10:15pm UTC](https://discourse.julialang.org/t/block-triangular-matrix-in-convex-jl/118147/2 "2024-08-13T22:15:14Z")

</div>

Hi @jens-rataczak, welcome to the forum 😄

Nope. I don’t think we have support for triangular matrices. What are you trying to model?

---

<div class="post-metadata">

**Author:** ![jens-rataczak](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jens-rataczak/32/211309_2.png) [@jens-rataczak](https://discourse.julialang.org/u/jens-rataczak)\
**Post date:** [August 13, 2024, 10:27pm UTC](https://discourse.julialang.org/t/block-triangular-matrix-in-convex-jl/118147/3 "2024-08-13T22:27:53Z")

</div>

Thanks!

I am trying to model a matrix that looks like the following  
 ![Screenshot 2024-08-13 at 4.27.00 PM](https://global.discourse-cdn.com/julialang/original/3X/d/1/d1a74a8ca67c1118a30056b236f9a2e0d5945d9c.png)

where each of the `K_ij` are matrices themselves. My approach right now is to define a fucntion

```julia
function LowerBlockTriVariable(N, m, n)
    K = []
    X = Variable(m, n)
    push!(K, X)
    L = [X zeros(m, n*N)]
    count = 2
    for j = 2:N
        X = [Variable(m, n) for k = j:j+count-1]
        push!(K, X)
        a = [hcat(X...) zeros(m, n*(N+1-j))]
        L = [L; a]
        count += 1
    end
    L, K
end

```

that inserts a matrix variable into the desired location of the whole block matrix, but I was just wondering if there was a more efficient way to do so.
