# Solving sparse matrix using backslash, got MethodError: no method matching lu!

**URL:** <https://discourse.julialang.org/t/solving-sparse-matrix-using-backslash-got-methoderror-no-method-matching-lu/42906>\
**Category:** Numerics\
**Tags:** linearalgebra, sparse\
**Created:** [July 11, 2020, 8:07pm UTC](https://discourse.julialang.org/t/solving-sparse-matrix-using-backslash-got-methoderror-no-method-matching-lu/42906 "2020-07-11T20:07:05Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Liang\_Chen](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/liang_chen/32/9979_2.png) [@Liang\_Chen](https://discourse.julialang.org/u/Liang_Chen)\
**Post date:** [July 11, 2020, 8:07pm UTC](https://discourse.julialang.org/t/solving-sparse-matrix-using-backslash-got-methoderror-no-method-matching-lu/42906/1 "2020-07-11T20:07:05Z")

</div>

I want to solve a system of equation Ax = b using A\b where **A and b are sparse** matrix and vector. Also matrix A is symmetric positive definite. However I got an error says:

“ERROR: LoadError: MethodError: no method matching lu!(::SparseMatrixCSC{Float64,Int64}, ::Val{true}; check=true)”

I create two simple examples and try to figure why but I am confused now. Below is the examples.

```julia
using SparseArrays

# this one is ok
A1 = sparse([1,1,2],[1,2,2],[1.0,2.0,3.0])
b1 = sparsevec([2],[1.0])
c1 = A1\b1

# this one does not
A2 = sparse([1,1,2,2],[1,2,1,2],[1.0,2.0,2.0,6.0])
b2 = sparsevec([2],[1.0])
c2 = A2\b2

```

c1 = A1\b1 can be solved but A2\b2 throws an error which is the same as the one above. The A2 here is not sparse but the actual matrix I need to solve is definitely sparse. Since this example gives me the same error, so I think the sparsity is not an issue.

I am using Julia 1.4.2.  
Any suggestions will be helpful. Thank you in advance.

---

<div class="post-metadata">

**Author:** ![jlchan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jlchan/32/10958_2.png) [@jlchan](https://discourse.julialang.org/u/jlchan)\
**Post date:** [July 11, 2020, 8:15pm UTC](https://discourse.julialang.org/t/solving-sparse-matrix-using-backslash-got-methoderror-no-method-matching-lu/42906/2 "2020-07-11T20:15:40Z")

</div>

Not a solution, but is there a reason you need `b1, b2` to be sparse vectors? If they’re regular vectors, there aren’t any errors.

---

<div class="post-metadata">

**Author:** ![photor](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/photor/32/14343_2.png) [@photor](https://discourse.julialang.org/u/photor)\
**Post date:** [July 11, 2020, 8:50pm UTC](https://discourse.julialang.org/t/solving-sparse-matrix-using-backslash-got-methoderror-no-method-matching-lu/42906/3 "2020-07-11T20:50:07Z")

</div>

Weird

---

<div class="post-metadata">

**Author:** ![Liang\_Chen](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/liang_chen/32/9979_2.png) [@Liang\_Chen](https://discourse.julialang.org/u/Liang_Chen)\
**Post date:** [July 11, 2020, 10:05pm UTC](https://discourse.julialang.org/t/solving-sparse-matrix-using-backslash-got-methoderror-no-method-matching-lu/42906/4 "2020-07-11T22:05:34Z")

</div>

Thanks, this looks a solution to me. I will leave the hard part to others.
