# In matlab, we calculate inv(A)* B by A\B. How about Julia? note that A&B are two large sparse matrices

Does anybody have experience with the calculation of inv(A)*B in Julia, where A and B are large sparse matrices?

When I used zz = A\B in Julia. It shows the following error in Julia

``````MethodError: no method matching ldiv!(::SuiteSparse.UMFPACK.UmfpackLU{Float64,Int64}, ::SparseArrays.SparseMatrixCSC{Float64,Int64})
Closest candidates are:
ldiv!(!Matched::LinearAlgebra.LU{T,LinearAlgebra.Tridiagonal{T,V}}, ::Union{AbstractArray{T,2}, AbstractArray{T,1}} where T) where {T, V} at C:\cygwin\home\Administrator\buildbot\worker\package_win64\build\usr\share\julia\stdlib\v1.2\LinearAlgebra\src\lu.jl:523
ldiv!(!Matched::LinearAlgebra.Transpose{#s617,#s616} where #s616<:LinearAlgebra.LU{T,LinearAlgebra.Tridiagonal{T,V}} where #s617, ::Union{AbstractArray{T,2}, AbstractArray{T,1}} where T) where {T, V} at C:\cygwin\home\Administrator\buildbot\worker\package_win64\build\usr\share\julia\stdlib\v1.2\LinearAlgebra\src\lu.jl:555
...

Stacktrace:
[3] top-level scope at In[5]:1

Just make `B` dense? The result will be a dense matrix of that size anyway.

3 Likes

Thank you Iâ€™ll try. Wondering if full() command is not supported in Julia 1.2?

You can just do `Matrix(B)`.

1 Like

Unfortunately, Same error.

MethodError: no method matching ldiv!(::SuiteSparse.UMFPACK.UmfpackLU{Float64,Int64}, ::SparseArrays.SparseMatrixCSC{Float64,Int64})
Closest candidates are:
ldiv!(!Matched::LinearAlgebra.LU{T,LinearAlgebra.Tridiagonal{T,V}}, ::Union{AbstractArray{T,2}, AbstractArray{T,1}} where T) where {T, V} at C:\cygwin\home\Administrator\buildbot\worker\package_win64\build\usr\share\julia\stdlib\v1.2\LinearAlgebra\src\lu.jl:523
ldiv!(!Matched::LinearAlgebra.Transpose{#s617,#s616} where #s616<:LinearAlgebra.LU{T,LinearAlgebra.Tridiagonal{T,V}} where #s617, ::Union{AbstractArray{T,2}, AbstractArray{T,1}} where T) where {T, V} at C:\cygwin\home\Administrator\buildbot\worker\package_win64\build\usr\share\julia\stdlib\v1.2\LinearAlgebra\src\lu.jl:555
â€¦

Stacktrace:
[3] top-level scope at In[5]:1

Looks like youâ€™re stll calling `ldiv!` with the sparse matrix

Can you show the code that produces this error?

Can you give an example of what you are doing?

``````julia> A = lu(sprand(5,5,0.5) + I)
UMFPACK LU Factorization of a (5, 5) sparse matrix
Ptr{Nothing} @0x00007fbedec06620

julia> B = sprand(5,5,0.4);

julia> A \ Matrix(B)
5Ă—5 Array{Float64,2}:
-0.247253  -0.458155    0.331186   -0.179299   0.222382
-0.812489  -2.25484     1.4221     -0.251258   1.58024
1.17403    2.29645    -0.930615    0.164422  -1.03411
0.338484   0.0         0.0         0.0        0.0
-0.18574   -0.0906186   0.0367224   0.660449   0.844956
``````

I tried with another problem, it worked. However, stucked with the memory issue.

Yes, it would require a lot of memory to store that. What is the reason for doing this computation though? If this is some type of discretized problem where K is a â€śstiffness matrixâ€ť and M a â€śmass matrixâ€ť then I donâ€™t see why you are doing K \ M.

Developing formulation for modal reduction in Multiphysics problems. It works in matlab if I consider both matrix as sparse and implement K \ M .