# Inverse of symmetric Matrix does not give proper output

**URL:** https://discourse.julialang.org/t/inverse-of-symmetric-matrix-does-not-give-proper-output/40173
**Category:** Performance
**Tags:** question
**Created:** [May 26, 2020, 8:27am UTC](https://discourse.julialang.org/t/inverse-of-symmetric-matrix-does-not-give-proper-output/40173 "2020-05-26T08:27:33Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![morkip](https://avatars.discourse-cdn.com/v4/letter/m/35a633/32.png) [@morkip](https://discourse.julialang.org/u/morkip)
#### Post date: [May 26, 2020, 8:27am UTC](https://discourse.julialang.org/t/inverse-of-symmetric-matrix-does-not-give-proper-output/40173/1 "2020-05-26T08:27:33Z")

</div>

I am trying to achieve better performance in my Matrix Inversion by tagging the Matrix as ‘symmetric’.  
The Matrix is medium sized (200x200) Parameters and complex valued (it is indeed symmetric and not hermitian). The norm of the outputs in the tagged and untagged case are wildly different; Only the untagged one gives the correct result. Also, the matrix is regularized, i.e. the inverse exists.  
I seem to get the same problem for real matrices as well. I’m on Julia 1.1.  
What is the proper way to tell the inv() function that the input is symmetric?

---

<div class="post-metadata">

### Author: ![marius311](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/marius311/32/3953_2.png) [@marius311](https://discourse.julialang.org/u/marius311)
#### Post date: [May 26, 2020, 8:43am UTC](https://discourse.julialang.org/t/inverse-of-symmetric-matrix-does-not-give-proper-output/40173/2 "2020-05-26T08:43:20Z")

</div>

Is it possible you meant `A = randn(n,n) + 1im * randn(n,n)` ? Otherwise `randn(n)` creates a length-n vector, and then you’re taking its outer product, creating a singular matrix.

---

<div class="post-metadata">

### Author: ![morkip](https://avatars.discourse-cdn.com/v4/letter/m/35a633/32.png) [@morkip](https://discourse.julialang.org/u/morkip)
#### Post date: [May 26, 2020, 9:05am UTC](https://discourse.julialang.org/t/inverse-of-symmetric-matrix-does-not-give-proper-output/40173/3 "2020-05-26T09:05:11Z")

</div>

Sorry, you’re right of course, however the question remains. The example was not applicable for my problem, I took it out.

I increased the regularization and now `norm(inv(A) - inv(Symmetric(A)))` goes to zero (for higher Regularization). Clearly, this is not desired as higher regularization means more imprecise results. Is there a way to speed up matrix inversions of close to singular, symmetric matrices?

---

<div class="post-metadata">

### Author: ![ctkelley](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ctkelley/32/10684_2.png) [@ctkelley](https://discourse.julialang.org/u/ctkelley)
#### Post date: [May 26, 2020, 10:47am UTC](https://discourse.julialang.org/t/inverse-of-symmetric-matrix-does-not-give-proper-output/40173/4 "2020-05-26T10:47:00Z")

</div>

This looks like a problem with conditioning. Are

inv(A)

and

inv(Symmetric(A))

using the same algorithm to compute inv? If not, poor conditioning could lead to different results. This would explain your observations as the regularization increases.
