0
$\begingroup$

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?

$\endgroup$

1 Answer 1

2
$\begingroup$
LinearSolve[(N@SparseArray)@foo, bar]
$\endgroup$
1
  • $\begingroup$ 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. $\endgroup$
    – celtschk
    Jan 14, 2016 at 19:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.