MATLAB: How to find out if singular matrix has infinite solutions or no solution

detnonlinearranksingular

>> B = [1 5 6 8; 2 10 12 1;3 15 18 9;1 2 1 2];
>> rank(B)
ans =
3
From the code above I know that my matrix is singular, but is there a function for checking if there will be one solution or infinitely many solutions?

Best Answer

(This is not really a MATLAB question, but linear algebra 101. But you did show enough MATLAB that I'll relent and answer. And you did use rank, instead of the detestable det.)
A solution to what? (Asked knowing the answer.)
Do you wish to solve the linear system
B*x = rhs
where x and rhs are 4x1 vectors, with x unknown and rhs known?
The word "solution" has no real meaning in this context otherwise, without the rest of the problem as I have stated it. So, IF your question is if a solution exists to the problem I have stated, then the answer is there will NEVER be EXACTLY ONE solution.
There can only be either zero solutions, or infinitely many solutions. How can you know which is the case?
If it is true that rank(B)==3, for a 4x4 matrix B, then test the rank of the 4x5 matrix [B,rhs]. If that matrix also has rank 3, then there will be infinitely many solutions. If that combined matrix now has rank 4, then there will be ZERO solutions. The reason is again due to linear algebra 101. Hint: if rhs does not live in the column space of B, then appending it to B will make the matrix full rank. But if it is not a linear combination of the columns of B, then no solution can exist.
There are no circumstances where there will be a unique solution for a rank deficient matrix B.