How to Check for Existence of Solution to Matrix Equations
There was a great question on the newsgroup this past week asking how to determine if a system of equations had a solution. The poster wasn't (at least yet) concerned with what the solution was.
Contents
First Solution
The first recommendation was to use det, the determinant. While this is pedagogically correct for some cases, it is insufficient since it doesn't correctly account for non-singular systems which do have solutions. John D'Errico followed up with some examples and some smart math.
Use rank
John points out that using det would not give the correct answer for this problem.
A = ones(2); b = [2;2];
Does a solution exist for A*x = b? It does despite the singularity of A. det(A) is zero of course.
det(A)
ans = 0
Yet the answer is just x = [1;1]. Find it using pinv.
pinv(A)*b
ans = 1 1
Using rank, check to see if the rank([A,b]) == rank(A)
rank([A,b]) == rank(A)
ans = 1
If the result is true, then a solution exists.
Let's try it for a problem that has no solution.
c = [1;2]; rank([A,c]) == rank(A)
ans = 0
Did You Know...?
I had a previous post about collinearity in which we tried a bunch of solutions, and the superior solution again was rank vs. det. Did you know that some singular systems had valid solutions? Have you had similar instances where what the textbooks sometimes recommend isn't ideal for the full spectrum of possible conditions. Post your thoughts here.