Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to check if m n-sized vectors are linearly independent?

Tags:

Disclaimer
This is not strictly a programming question, but most programmers soon or later have to deal with math (especially algebra), so I think that the answer could turn out to be useful to someone else in the future.

Now the problem
I'm trying to check if m vectors of dimension n are linearly independent. If m == n you can just build a matrix using the vectors and check if the determinant is != 0. But what if m < n?

Any hints?


See also this video lecture.

like image 545
tunnuz Avatar asked Feb 10 '09 12:02

tunnuz


3 Answers

Construct a matrix of the vectors (one row per vector), and perform a Gaussian elimination on this matrix. If any of the matrix rows cancels out, they are not linearly independent.

The trivial case is when m > n, in this case, they cannot be linearly independent.

like image 155
David Hanak Avatar answered Sep 28 '22 08:09

David Hanak


Construct a matrix M whose rows are the vectors and determine the rank of M. If the rank of M is less than m (the number of vectors) then there is a linear dependence. In the algorithm to determine the rank of M you can stop the procedure as soon as you obtain one row of zeros, but running the algorithm to completion has the added bonanza of providing the dimension of the spanning set of the vectors. Oh, and the algorithm to determine the rank of M is merely Gaussian elimination.

Take care for numerical instability. See the warning at the beginning of chapter two in Numerical Recipes.

like image 34
jason Avatar answered Sep 28 '22 08:09

jason


If m<n, you will have to do some operation on them (there are multiple possibilities: Gaussian elimination, orthogonalization, etc., almost any transformation which can be used for solving equations will do) and check the result (eg. Gaussian elimination => zero row or column, orthogonalization => zero vector, SVD => zero singular number)

However, note that this question is a bad question for a programmer to ask, and this problem is a bad problem for a program to solve. That's because every linearly dependent set of n<m vectors has a different set of linearly independent vectors nearby (eg. the problem is numerically unstable)

like image 32
jpalecek Avatar answered Sep 28 '22 08:09

jpalecek