# Inverting Large Matrices (Overflow error)

**URL:** <https://discourse.julialang.org/t/inverting-large-matrices-overflow-error/73353>\
**Category:** New to Julia\
**Tags:** linearalgebra, stackoverflow\
**Created:** [December 20, 2021, 3:21am UTC](https://discourse.julialang.org/t/inverting-large-matrices-overflow-error/73353 "2021-12-20T03:21:56Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![RandarserousRex](https://avatars.discourse-cdn.com/v4/letter/r/4491bb/32.png) [@RandarserousRex](https://discourse.julialang.org/u/RandarserousRex)\
**Post date:** [December 20, 2021, 3:21am UTC](https://discourse.julialang.org/t/inverting-large-matrices-overflow-error/73353/1 "2021-12-20T03:21:56Z")

</div>

Hi all,

I’m trying to invert a large matrix (1001 by 1001) to perform Ridge Regression in Julia. I’m running into this “Stack overflow Error:”, I’ve recreated the problem with simpler code (not my Ridge Regression code, which is much messier) to illustrate what I’m dealing with. I’m using Julia in a Jupyter Notebook if that is of any concern. Could someone help me invert a large matrix or solve Ax=b for large A? Thank you!

(in this example I show that even a 100 by 100 matrix triggers this response, but 50 by 50 works)

 ![Screen Shot 2021-12-19 at 7.17.38 PM](https://global.discourse-cdn.com/julialang/original/3X/b/7/b7b2973cbbd1ee3bb95af1389ed3870efb6c21fc.png)

---

<div class="post-metadata">

**Author:** ![Oscar\_Smith](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/oscar_smith/32/25343_2.png) [@Oscar\_Smith](https://discourse.julialang.org/u/Oscar_Smith)\
**Post date:** [December 20, 2021, 3:25am UTC](https://discourse.julialang.org/t/inverting-large-matrices-overflow-error/73353/2 "2021-12-20T03:25:00Z")

</div>

This is a known problem with Julia 1.7.0 and 1.6.4. 1.6.3 is unaffected, and 1.7.1 and 1.6.5 will fix this.

---

<div class="post-metadata">

**Author:** ![RandarserousRex](https://avatars.discourse-cdn.com/v4/letter/r/4491bb/32.png) [@RandarserousRex](https://discourse.julialang.org/u/RandarserousRex)\
**Post date:** [December 20, 2021, 3:26am UTC](https://discourse.julialang.org/t/inverting-large-matrices-overflow-error/73353/3 "2021-12-20T03:26:50Z")

</div>

Oh ok, thank you for your fast response. I apologize for bringing up the old issue, I couldn’t find it on google. I’ll update my software then.

---

<div class="post-metadata">

**Author:** ![Eric](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/eric/32/25565_2.png) [@Eric](https://discourse.julialang.org/u/Eric)\
**Post date:** [December 20, 2021, 1:10pm UTC](https://discourse.julialang.org/t/inverting-large-matrices-overflow-error/73353/4 "2021-12-20T13:10:42Z")

</div>

in version 1.6.4, you can also use:

```julia
using LinearAlgebra
x = 1001
pinv(rand(Uniform(-1, 1), x, x))

```

on my installation, it does not appear to suffer the same issue. Provided that `pinv()` is adequate in your regression context.

---

<div class="post-metadata">

**Author:** ![PeterSimon](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/petersimon/32/25193_2.png) [@PeterSimon](https://discourse.julialang.org/u/PeterSimon)\
**Post date:** [December 20, 2021, 4:29pm UTC](https://discourse.julialang.org/t/inverting-large-matrices-overflow-error/73353/5 "2021-12-20T16:29:56Z")

</div>

On my Intel processor running Julia 1.7.0,

```julia
using MKL

```

eliminates the problem, which is restricted to OpenBLAS.
