I have a matrix A, with the coefficients of a binary equation system.
In order to solve it, I need to know if all of those equations are linearly independent. However, rank(A) doesn't work here, because MATLAB doesn't know they're binary equations.
Here's an example:
>> A
A =
1 0 1 1
0 1 1 1
1 1 0 0
>> rank(A)
ans = 3
It's important to mention that it's a $Ax = 0 \pmod{2}$ type system.
As you can see, if you add rows 2 and 3, the result is the first one. This means the three of them aren't linearly independent, while rank(A) is saying they are.
How can I solve this?
rank(A)of Matlab works under the assuption that the matrix has elements in the field of complex numbers, so this won't work for you. But, the rank detection of a binary system is really easy (only algebra no numerical noise considerations). Just apply Gaussian algorithm with rank detection (i.e., in general with row and column permutations).In your example the first non-trivial elimination step is adding the first equation to the last. In this way you get: \begin{align*} A_2=\pmatrix{1&0&1&1\\0&1&1&1\\0&1&1&1} \end{align*} The next elimination step consists of adding the second row to the just created modified third row. In this way you get just a zero row: \begin{align*} A_2=\pmatrix{1&0&1&1\\0&1&1&1\\0&0&0&0} \end{align*} You 've got two non-zero rows of the staircase system. Therefore, $\operatorname{rank}(A)=2$.
By applying the transformation steps also to the right-hand side you can use the algorithm to solve your system if it is solvable.
There is code for Gauss' algorithm at Mathworks. For completing the answer there follows a code for Octave. Maybe it runs in Matlab too:
The following code segment shows the application of the algorithm to the problem in the question for deducing the rank of $A$:
If the size
pof the Galois field is not included in the argument list it defaults toGF(2). That means the computation is based on dual numbers. If the right-hand side is omitted an empty vectorx=[]is returned. Nevertheless, the LU-decomposition and the rank-detection are carried out.The output of the program is:
The rank information
r=2that is included in the output is most interesting in this example with respect to the question.