# What did I do wrong with LAPACK.potri!?

**URL:** <https://discourse.julialang.org/t/what-did-i-do-wrong-with-lapack-potri/37293>\
**Category:** General Usage\
**Tags:** linearalgebra\
**Created:** [April 9, 2020, 6:19pm UTC](https://discourse.julialang.org/t/what-did-i-do-wrong-with-lapack-potri/37293 "2020-04-09T18:19:10Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![kai](https://avatars.discourse-cdn.com/v4/letter/k/cc9497/32.png) [@kai](https://discourse.julialang.org/u/kai)\
**Post date:** [April 9, 2020, 6:19pm UTC](https://discourse.julialang.org/t/what-did-i-do-wrong-with-lapack-potri/37293/1 "2020-04-09T18:19:10Z")

</div>

Somehow potri is not giving me the inverse. What did I do wrong? Here is an example:

```julia
using LinearAlgebra, Random
Random.seed!(1)
x = rand(5, 5)
V = x'x
LinearAlgebra.copytri!(V, 'U')
Vcopy = rand(5, 5)
copyto!(Vcopy, V)

```

Then

```julia
inv(V) * Vcopy

```

gives back identity.

But

```julia
LinearAlgebra.LAPACK.potri!('U', V)
LinearAlgebra.copytri!(V, 'U')
V * Vcopy

```

gives something far from identity.

---

<div class="post-metadata">

**Author:** ![kai](https://avatars.discourse-cdn.com/v4/letter/k/cc9497/32.png) [@kai](https://discourse.julialang.org/u/kai)\
**Post date:** [April 10, 2020, 5:21pm UTC](https://discourse.julialang.org/t/what-did-i-do-wrong-with-lapack-potri/37293/2 "2020-04-10T17:21:07Z")

</div>

Turns out that I need to call `potrf` before `potri`.

The documentation

> Computes the inverse of positive-definite matrix `A` after calling `potrf!` to find its (upper if `uplo = U` , lower if `uplo = L` ) Cholesky decomposition.

made me think that `potri` would call `potrf` internally. But that is not the case.

So

```julia
LinearAlgebra.LAPACK.potrf!('U', V)
LinearAlgebra.LAPACK.potri!('U', V)
LinearAlgebra.copytri!(V, 'U')
V * Vcopy

```

would give back identity.

---

<div class="post-metadata">

**Author:** ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)\
**Post date:** [April 11, 2020, 7:15am UTC](https://discourse.julialang.org/t/what-did-i-do-wrong-with-lapack-potri/37293/3 "2020-04-11T07:15:49Z")

</div>

I am not sure why you need to call the LAPACK functions directly. I think that

```julia
inv(cholesky(V))

```

does what you want.
