I'm trying to determine only if a solution to a linear system of equations exists. I have been using LinearSolve, which works fine, but it solves the system as well. Is there another more efficient method for only checking the existence of a solution?
|
|
|||
|
==== Update ==== Please consider important discussion in the comments. ==== Original answer ==== If the matrix m has determinant zero, then there may be either no vector, or an infinite number of vectors x which satisfy m.x==b for a particular b. This occurs when the linear equations embodied in m are not independent. If you are interested only in well-defined systems, then, generally, confirming that you have a non-zero determinant is faster:
Some timing tests:
|
|||||||||||||||||||
|
|
The upshot of Vitaliy's note to check for a zero determinant is that
Thus, to safely determine if a matrix is singular, you can do any of two things:
|
|||||
|
|
Odd. If you get a solution, you know that a solution exists, isn't it? Anyway, what you can do is suppress the output by adding a
returns nothing, while
returns
|
|||||||||||
|


LinearSolveis very fast and (for general-purpose work involving non-square matrices) provides solutions an order of magnitude faster than other methods using (say)MatrixRank,RowReduce, orMinors. As an example of how extra info can help, if it's known the coefficient matrix is orthogonal, then you already know a solution exists. – whuber Sep 26 '12 at 19:07