# LinearSolve on non-square matrices?

I just came across a strange behaviour for LinearSolve (on Mathematica 8.0.0.0). Consider the following definitions:

foo = {{0, 0}, {0, 1}, {1, 1}};
bar = {0, 0, 1};


Then LinearSolve[foo, bar] gives the expected {1,0}. The same is true for LinearSolve[SparseArray@foo, bar]. Moreover, LinearSolve[N@foo, bar] gives a numeric approximation of that vector, as expected.

However LinearSolve[N@SparseArray@foo, bar] does not work, but gives me an error message

LinearSolve::sqmat: The matrix SparseArray[Automatic,{3,2},0.,{1,{{0,0,1,3},{{2},{1},{2}}},{1.,1.,1.}}] is not square. A square matrix is needed to compute a factorization. >>

Unfortunately my actual problem is exactly of the latter case: A non-square numeric sparse matrix.

Now my question is: Why do I get that error, and more importantly, what can I do about it?

LinearSolve[(N@SparseArray)@foo, bar]

• That applies N only to the symbol SparseArray and thus is equivalent to SparseArray@foo. You can easily verify that by noting that the result consists of integers, not of m,achine-precision numbers. Note that the point is not the application of N, but the fact that I have a sparse array with numeric values; Applying N is just a convenient way to get that. – celtschk Jan 14 '16 at 19:46