Reputation: 1102
I'm having difficulty coming up with the method by which a program can find the rank of a matrix. In particular, I don't fully understand how you can make sure the program would catch all cases of linear combinations resulting in dependencies.
The general idea of how to solve this is what I'm interested in. However, if you want to take the answer a step farther, I'm specifically looking for the solution in regards to square matrices only. Also the code would be in C++.
Thanks for your time!
Upvotes: 1
Views: 5334
Reputation: 741
General process:
matrix = 'your matrix you want to find rank of'
m2 = rref(matrix)
rank = number_non_zero_rows(m2)
where rref(matrix)
is a function that does your run-of-the-mill Gaussian elimination
number_non_zero_rows(m2)
is a function that sums the number of rows with non-zero entries
Your concern about all cases of linear combinations resulting in dependencies is taken care of with the rref
(Gaussian elimination) step. Incidentally, this works no matter what the dimensions of the matrix are.
Upvotes: 1