# Finding the least norm solution of least squares problem with a sparse matrix

**URL:** <https://discourse.julialang.org/t/finding-the-least-norm-solution-of-least-squares-problem-with-a-sparse-matrix/30702>\
**Category:** Numerics\
**Tags:** linearalgebra\
**Created:** [November 4, 2019, 3:38pm UTC](https://discourse.julialang.org/t/finding-the-least-norm-solution-of-least-squares-problem-with-a-sparse-matrix/30702 "2019-11-04T15:38:03Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![gmouts](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gmouts/32/9896_2.png) [@gmouts](https://discourse.julialang.org/u/gmouts)\
**Post date:** [November 4, 2019, 3:38pm UTC](https://discourse.julialang.org/t/finding-the-least-norm-solution-of-least-squares-problem-with-a-sparse-matrix/30702/1 "2019-11-04T15:38:03Z")

</div>

I have a matrix `M` which is the transpose of the Laplacian of a graph and a vector `d` that may or may not be in the range of `M`. I want to compute `pinv(M)*d`.

I assumed that `qr(M)\d` does what I want, however it does it only when `M` is represented by a full matrix, see [my previous question](https://discourse.julialang.org/t/result-changes-depending-on-whether-matrix-is-sparse-or-not/30669/7). If `M` is represented by a sparse matrix, it gives a solution but not the least norm one.

So what is the most efficient to get `pinv(M)*d`?

---

<div class="post-metadata">

**Author:** ![ranocha](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ranocha/32/35588_2.png) [@ranocha](https://discourse.julialang.org/u/ranocha)\
**Post date:** [November 4, 2019, 4:34pm UTC](https://discourse.julialang.org/t/finding-the-least-norm-solution-of-least-squares-problem-with-a-sparse-matrix/30702/2 "2019-11-04T16:34:50Z")

</div>

That will probably depend on your matrix. The iterative solvers LSQR and LSMR compute the least norm least square solution. In particular, they approximate the least norm solution if your system is feasible. These methods are implemented in [IterativeSolvers.jl](https://github.com/JuliaMath/IterativeSolvers.jl), cf. [https://juliamath.github.io/IterativeSolvers.jl/dev/linear\_systems/lsqr/](https://juliamath.github.io/IterativeSolvers.jl/dev/linear_systems/lsqr/).

---

<div class="post-metadata">

**Author:** ![pkofod](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pkofod/32/2179_2.png) [@pkofod](https://discourse.julialang.org/u/pkofod)\
**Post date:** [November 4, 2019, 7:56pm UTC](https://discourse.julialang.org/t/finding-the-least-norm-solution-of-least-squares-problem-with-a-sparse-matrix/30702/3 "2019-11-04T19:56:10Z")

</div>

See also [https://github.com/JuliaSmoothOptimizers/Krylov.jl](https://github.com/JuliaSmoothOptimizers/Krylov.jl)
