# Cholesky factorization in JuMP

**URL:** https://discourse.julialang.org/t/cholesky-factorization-in-jump/82227
**Category:** Optimization (Mathematical)
**Created:** [June 4, 2022, 3:16am UTC](https://discourse.julialang.org/t/cholesky-factorization-in-jump/82227 "2022-06-04T03:16:48Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![horvetz](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/horvetz/32/31993_2.png) [@horvetz](https://discourse.julialang.org/u/horvetz)
#### Post date: [June 4, 2022, 3:16am UTC](https://discourse.julialang.org/t/cholesky-factorization-in-jump/82227/1 "2022-06-04T03:16:48Z")

</div>

I want to solve a SDP optimization problem using a nonlinear solver. Specifically I want to use Cholesky factorization to enforce positive definiteness of some decision variable A. That is I want to find a lower triangular matrix L such that A = LL’ and diag(L) \> 0. How do I write these variables in JuMP?

What I have so far is the following

> using JuMP  
> model = Model()  
> n = 5  
> @variable(model, A[1:n, 1:n])  
> @variable(model, L[1:n, 1:n]) # How to force this to be lower triangular?  
> @constraint(model, const1, A == L \* L’)  
> @constraint(model, const2, minimum(diag(L)) \> 0)

---

<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: [June 4, 2022, 5:39am UTC](https://discourse.julialang.org/t/cholesky-factorization-in-jump/82227/2 "2022-06-04T05:39:00Z")

</div>

Using the example problem from: [The correlation problem · JuMP](https://jump.dev/JuMP.jl/stable/tutorials/conic/corr_sdp/)

```julia
using JuMP
import Ipopt
import LinearAlgebra

function example_corr_sdp()
    model = Model(Ipopt.Optimizer)
    set_silent(model)

    # Instead of
    # @variable(model, X[1:3, 1:3], PSD)
    # do
    @variable(model, L[1:3, 1:3], Symmetric)
    @constraint(model, [i=1:3], L[i, i] >= 0)
    l = LinearAlgebra.LowerTriangular(L)
    @expression(model, X, l * l')

    # Diagonal is 1s
    @constraint(model, X[1, 1] == 1)
    @constraint(model, X[2, 2] == 1)
    @constraint(model, X[3, 3] == 1)
    # Bounds on the known correlations
    @constraint(model, X[1, 2] >= -0.2)
    @constraint(model, X[1, 2] <= -0.1)
    @constraint(model, X[2, 3] >= 0.4)
    @constraint(model, X[2, 3] <= 0.5)
    # Find upper bound
    @objective(model, Max, X[1, 3])
    optimize!(model)
    println("An upper bound for X[1, 3] is $(value(X[1, 3]))")
    # Find lower bound
    @objective(model, Min, X[1, 3])
    optimize!(model)
    println("A lower bound for X[1, 3] is $(value(X[1, 3]))")
    return
end
example_corr_sdp()

```

Why do you want to use a nonlinear solver though? There might be numerical issues with the quadratic equality constraint (which is non-convex).

---

<div class="post-metadata">

### Author: ![horvetz](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/horvetz/32/31993_2.png) [@horvetz](https://discourse.julialang.org/u/horvetz)
#### Post date: [June 8, 2022, 3:31pm UTC](https://discourse.julialang.org/t/cholesky-factorization-in-jump/82227/4 "2022-06-08T15:31:30Z")

</div>

@odow Is there any necessary reason to require L to be symmetric (unless it is in the problem statement)?
