矩阵中的R个独立列 [英] R independent columns in matrix
问题描述
我试图找到独立的列来求解线性方程组.这是我的简化示例:
I am trying to find independent columns to solve the system of linear equations. Here 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
矩阵为满分:
qr(mat)$rank
给我4,并且由于有6列,所以应该有6-4 = 2个独立的列,从中我可以计算其他列. 我知道列v4和v6是独立的...我的第一个问题是,如何找到这些列(也许使用qr(mat)$ pivot)?
gives me 4, and since there are 6 columns, there should be 6-4=2 independent columns from which I can calculate the others. I know that columns v4 and v6 are independent... My first question is, how can I find these columns (maybe with qr(mat)$pivot)?
通过在纸上重新排列线性方程,我看到了
[v1,v2,v3,v4,v5,v6] = [v4,v4-v6,v4-v6,v4,v4,v6,v6]
By rearranging the linear equations on paper, I see that
[v1, v2, v3, v4, v5, v6] = [v4, v4-v6, v4-v6, v4, v4, v6, v6]
因此,我可以通过将v4和v6乘以以下向量,从v4和v6的任意值中找到一个位于空空间中的向量:
and thus I can find from arbitrary values for v4 and v6 a vector that lies in the null space by multiplying v4 and v6 with the vectors below:
v4 * [1,1,1,1,0,0] + v6 * [0,-1,-1,0,1,1]
我的第二个问题是:如何找到这些向量,这意味着如何求解v4和v6的矩阵? 例如
My second question is: How do I find these vectors, meaning how do I solve the matrix for v4 and v6? For example
qr.solve(mat, cbind(c(0,0,0,0), c(0,0,0,0)))
给我两个长度为6的矢量,它们只有零.
gives me two vectors of length 6 with only zeros.
感谢您的帮助,在此先感谢您!
Any help is appreciated, many thanks in advance!
-H-
推荐答案
使用数据透视信息查找一组独立的列:
Use the pivot information to find a set of independent columns:
q <- qr(mat)
mmat <- mat[,q$pivot[seq(q$rank)]]
mmat
## v1 v2 v3 v5
## A 1 -1 0 -1
## B 0 1 -1 0
## C 0 0 1 0
## D 0 0 0 1
qr(mmat)$rank
## [1] 4
为什么这样做? pivot
的含义在?qr.Q
带来的QR.Auxiliaries {base}
中给出.特别是:
Why does this work? The meaning of pivot
is given in QR.Auxiliaries {base}
brought up with ?qr.Q
. In particular:
qr.R returns R. This may be pivoted, e.g., if a <- qr(x) then x[, a$pivot] = QR.
The number of rows of R is either nrow(X) or ncol(X) (and may depend on whether
complete is TRUE or FALSE).
进行枢轴旋转以使特征值按递减的绝对值排序,以实现数值稳定性.这也意味着,任何0
特征值都位于末尾,超出了q$pivot
中的q$rank
(并且在当前示例中不存在,其中Q
是4x4正交矩阵).
Pivoting is done to order the eigenvalues in decreasing absolute value, for numerical stability. This also means that any 0
eigenvalues are at the end, beyond q$rank
in q$pivot
(and nonexistent in the current example, where Q
is a 4x4 orthogonal matrix).
QR.Auxiliaries {base}
中的最后几行显示了这种关系:
The final lines in the QR.Auxiliaries {base}
show this relationship:
pivI <- sort.list(a$pivot) # the inverse permutation
stopifnot(
all.equal(x[, a$pivot], qr.Q(a) %*% qr.R(a)), # TRUE
all.equal(x , qr.Q(a) %*% qr.R(a)[, pivI])) # TRUE too!
这篇关于矩阵中的R个独立列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!