# Cholesky decomposition of low-rank positive-semidefinite matrix

**URL:** <https://discourse.julialang.org/t/cholesky-decomposition-of-low-rank-positive-semidefinite-matrix/70397>\
**Category:** General Usage\
**Tags:** linearalgebra, numerics\
**Created:** [October 26, 2021, 10:47am UTC](https://discourse.julialang.org/t/cholesky-decomposition-of-low-rank-positive-semidefinite-matrix/70397 "2021-10-26T10:47:20Z")\
**Posts on this page:** 1\
**Showing post:** 3

<div class="post-metadata">

**Author:** ![stevengj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevengj/32/71_2.png) [@stevengj](https://discourse.julialang.org/u/stevengj)\
**Post date:** [October 26, 2021, 12:34pm UTC](https://discourse.julialang.org/t/cholesky-decomposition-of-low-rank-positive-semidefinite-matrix/70397/3 "2021-10-26T12:34:51Z")

</div>

For example, here is a rank-3 5x5 positive semidefinite matrix:

```julia
julia> B = rand(3,5); A = Hermitian(B'B);

```

`cholesky(A)` throws `PosDefException`, and `cholesky(A, Val(true))` throws `RankDeficientException`. However, passing `check=false` forces the factorization to proceed even if it is rank-deficient:

```julia
julia> F = cholesky(A, Val(true); check=false)
CholeskyPivoted{Float64, Matrix{Float64}}
U factor with rank 4:
5×5 UpperTriangular{Float64, Matrix{Float64}}:
 1.26174 0.830057 1.04195 0.862304 0.981338
  ⋅ 0.708177 0.242843 -0.34719 -0.0424352
  ⋅ ⋅ 0.573781 0.122706 0.375544
  ⋅ ⋅ ⋅ 1.05367e-8 -1.05367e-8
  ⋅ ⋅ ⋅ ⋅ -2.22045e-16
permutation:
5-element Vector{Int64}:
 3
 1
 4
 5
 2

```

Notice the slightly negative pivot due to roundoff errors, as well as the small 4th pivot (on the order of the square root of the precision — recall that Cholesky takes square roots of pivots). This is still a factorization of `A` (up to roundoff), taking into account the permutation `F.p`:

```julia
julia> F.L * F.L' - A[F.p, F.p]
5×5 Matrix{Float64}:
  0.0 0.0 -2.22045e-16 0.0 0.0
  0.0 0.0 0.0 0.0 0.0
 -2.22045e-16 0.0 0.0 0.0 0.0
  0.0 0.0 0.0 0.0 0.0
  0.0 0.0 0.0 0.0 2.22045e-16

```

However, in general the pivoted-Cholesky algorithm only factorizes a submatrix of `A[F.p, F.p]`, up to the point where the algorithm terminates.

---

_[View the full topic](https://discourse.julialang.org/t/cholesky-decomposition-of-low-rank-positive-semidefinite-matrix/70397)._
