Kat
Kat

Reputation: 57

How to invert a full matrix?

I have a matrix

            X1         X2        X3        X4        X5        X6           G1            G2
X1            5         0         0         0         0         0            5            0 
X2            0         5         0         0         0         0            5            0
X3            0         0         5         0         0         0            5            0
X4            0         0         0         5         0         0            0            5
X5            0         0         0         0         5         0            0            5  
X6            0         0         0         0         0         5            0            5  
G1            5         5         5         0         0         0           15            0  
G2            0         0         0         5         5         5            0           15  

There are dependence lineal in the two last rows and columns, I try to delete one row and one column (for example G1), but the resulting matrix still has a linear dependence, so I can't invert the matrix.

Can anyone help me please?

Upvotes: 1

Views: 132

Answers (1)

G. Grothendieck
G. Grothendieck

Reputation: 270020

The symmetric matrix m, shown reproducibly in the Note at the end, is singular which is implied by its having at least one zero eigenvalue (in fact, it has two):

eigen(m)$values
## [1]  2.000000e+01  2.000000e+01  5.000000e+00  5.000000e+00  5.000000e+00
## [6]  5.000000e+00 -4.671248e-24 -4.671248e-24

Thus, it cannot be inverted; however, you can take the Moore Penrose generalized inverse using ginv from the MASS package. A generalized inverse does satisfy the relation shown in the last line of code below. Note that the MASS package comes with R so you don't need to install it.

library(MASS)

gm <- ginv(m)
all.equal(m %*% gm %*% m, m)
## [1] TRUE

Note that there are two linear dependencies owing to the two zero eigenvalues. By inspection we note that the sum of the first 3 rows of m equals the 7th row and the sum of the 4th through 6th rows equals the 8th row so dropping rows 7 and 8 and the corresponding columns due to symmetry we see that the upper left 6x6 submatrix is invertible:

solve(m[-(7:8), -(7:8)])

Alternately we can find constraints by inspection of the eigenvectors of m.

Note

Lines <- "X1         X2        X3        X4        X5        X6           G1            G2
X1            5         0         0         0         0         0            5            0 
X2            0         5         0         0         0         0            5            0
X3            0         0         5         0         0         0            5            0
X4            0         0         0         5         0         0            0            5
X5            0         0         0         0         5         0            0            5  
X6            0         0         0         0         0         5            0            5  
G1            5         5         5         0         0         0           15            0  
G2            0         0         0         5         5         5            0           15"
m <- as.matrix(read.table(text = Lines))

Upvotes: 6

Related Questions