# Differences in A \\ b for sparse and nonsparse rank-deficient A

**URL:** <https://discourse.julialang.org/t/differences-in-a-b-for-sparse-and-nonsparse-rank-deficient-a/66917>\
**Category:** General Usage\
**Tags:** linearalgebra, sparse\
**Created:** [August 24, 2021, 3:18pm UTC](https://discourse.julialang.org/t/differences-in-a-b-for-sparse-and-nonsparse-rank-deficient-a/66917 "2021-08-24T15:18:33Z")\
**Posts on this page:** 1\
**Showing post:** 5

<div class="post-metadata">

**Author:** ![stevengj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevengj/32/71_2.png) [@stevengj](https://discourse.julialang.org/u/stevengj)\
**Post date:** [August 24, 2021, 8:00pm UTC](https://discourse.julialang.org/t/differences-in-a-b-for-sparse-and-nonsparse-rank-deficient-a/66917/5 "2021-08-24T20:00:47Z")

</div>

> [@Thomas](#):
>
> `F.Q[:,Base.OneTo(rnk)]`

Unfortunately, this creates a dense matrix. (`F.Q` is not stored explicitly, but as a composition of sparse or low-rank operations so that you can compute `F.Q` times a vector efficiently. Trying to pull out a subset of the columns of `Q` discards this structure.)

Instead, I would compute `(F.Q' * b[F.prow])[1:rnk]`, which should be equivalent and efficient without constructing a dense matrix.

> [@Thomas](#):
>
> `S = sparse(R11 \ R12)`

Note that this is also not a sparse matrix in general, since `inv(R11)` is in general not sparse. In general you want to compute the action of matrices like this on vectors rather than computing the matrix itself. But it may be okay for your purposes since maybe you are interested only in the case where the rank is very low, so a dense `R11` matrix inverse is acceptable?

I’ve just skimmed your code looking for common sparse-matrix gotchas; I haven’t really looked at the structure of your algorithm. Note that there are some papers on minimum-norm solutions with sparse matrices that may be helpful; for example, [Solution of Sparse Underdetermined Systems of Linear Equations (1984)](https://epubs.siam.org/doi/abs/10.1137/0905068?journalCode=sijcd4)

See also [Finding the least norm solution of least squares problem with a sparse matrix](https://discourse.julialang.org/t/finding-the-least-norm-solution-of-least-squares-problem-with-a-sparse-matrix/30702) for iterative methods.

---

_[View the full topic](https://discourse.julialang.org/t/differences-in-a-b-for-sparse-and-nonsparse-rank-deficient-a/66917)._
