I am trying to find independent columns to solve a system of linear equations. Here is my simplified example:
> mat = matrix(c(1,0,0,0,-1,1,0,0,0,-1,1,0,0,0,-1,0,-1,0,0,1,0,0,1,-1), nrow=4, ncol=6, dimnames=list(c("A", "B", "C", "D"), paste("v", 1:6, sep="")))
> mat
v1 v2 v3 v4 v5 v6
A 1 -1 0 0 -1 0
B 0 1 -1 0 0 0
C 0 0 1 -1 0 1
D 0 0 0 0 1 -1
The matrix has a full rank:
qr(mat)$rank
gives me 4, and since there are 6 columns, there should be 6-4 = 2 independent columns from which I can calculate the rest. I know that v4 and v6 columns are independent ... My first question is: how can I find these columns (possibly with qr (mat) $ pivot)?
Rearranging linear equations on paper, I see that [v1, v2, v3, v4, v5, v6] = [v4, v4-v6, v4-v6, v4, v4, v6, v6]
and, therefore, I can find from arbitrary values for v4 and v6 a vector lying in zero space by multiplying v4 and v6 by the vectors below:
v4 * [1,1,1,1,0,0] + v6 * [0,-1,-1,0,1,1]
My second question: how to find these vectors, which means how to solve the matrix for v4 and v6? for instance
qr.solve(mat, cbind(c(0,0,0,0), c(0,0,0,0)))
gives me two vectors of length 6 with zeros.
, !
-H -