# How to check if two sets of vectors span the same space in matlab/python?

In MATLAB/Python, is there a way to compare the subspaces span by two different sets of vectors and check if they are the same?

Utilizing the fact that $A$ and $rref(A)$ has the same row space, check if the two matrices (with the given vectors as row vectors) have the same Reduced Row Echelon Form.

Corrected version following a remark of @Quang Hoang

Here is another way :

If the sets of vectors are the columns of $A$ and $B$ resp., check that the new matrix $C=[A,B]$ is such that

$$rank(A)=rank(B)=rank(C)$$

Proof: Let $R(M)$ denote the column space of a matrix $M$.

Equality $rank(A)=rank(C)$ implies $R(A)=R(C)$ Equality $rank(B)=rank(C)$, implies $R(B)=R(C)$. Thus $R(A)=R(B)$. Therefore $rank(A)=rank(B)$.

• This is actually a very clever yet simple move! Don't know if it works for all cases though. – Quang Thinh Ha May 18 '16 at 10:42
• Why do you think there are cases where it doesn't work ? The only problem that might impair the method (but that would impair all methods) is the use of approximations (in particular in large dimensions). – Jean Marie May 18 '16 at 11:17
• The numerical errors is the main reasons why, but I guess I am a hypocrite worrying about numerical errors while using MATLAB/Python... – Quang Thinh Ha May 18 '16 at 11:22
• This is not true, it only guarantees that the column space of $B$ is contained in that of $A$. You need to check that $rank(C)=rank(B)=rank(A)$. – Quang Hoang May 18 '16 at 15:38
• @Quang Hoang You are perfectly right. I correct immediately my answer. – Jean Marie May 18 '16 at 16:24