# Solve function for non full rank systems of equations

**URL:** <https://discourse.julialang.org/t/solve-function-for-non-full-rank-systems-of-equations/54611>\
**Category:** Numerics\
**Tags:** question, linearalgebra\
**Created:** [February 4, 2021, 10:58am UTC](https://discourse.julialang.org/t/solve-function-for-non-full-rank-systems-of-equations/54611 "2021-02-04T10:58:10Z")\
**Posts on this page:** 1\
**Showing post:** 3

<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:** [February 4, 2021, 7:52pm UTC](https://discourse.julialang.org/t/solve-function-for-non-full-rank-systems-of-equations/54611/3 "2021-02-04T19:52:31Z")

</div>

You should generally use `qr(X, Val(true)) \ y` to get a least-square solution (defaulting to the minimum-norm solution if it is not unique, IIRC). For non-square `X`, it is equivalent to simply do `X \ y`.

You almost certainly do **not** want to form `X'X` **at all** if it is nearly singular (i.e. if `X` is badly conditioned), although this is deceptively the way least-squares problems are usually taught. See also [this post](https://discourse.julialang.org/t/efficient-way-of-doing-linear-regression/31232/33).

---

_[View the full topic](https://discourse.julialang.org/t/solve-function-for-non-full-rank-systems-of-equations/54611)._
