0

Using R, I'm trying to verify SVD with simple 3-by-2 matrix M by calculating eigenvalues and vectors of transposed matrix, say N1 and N2 shown below.

column1 <- c(1,2,3)
column2 <- c(4,5,6)
M <- cbind(column1,column2)
N1 <- M %*% t(M)
N2 <- t(M) %*% M

> N1
     [,1] [,2] [,3]
[1,]   17   22   27
[2,]   22   29   36
[3,]   27   36   45
> N2
        column1 column2
column1      14      32
column2      32      77

Then, I made R calculate the eigenvalues of N1 and N2, which must be same each other, but it has shown me unexpected results like below.

> eigen(N1)$values
[1] 9.040267e+01 5.973275e-01 1.329470e-15
> eigen(N2)$values
[1] 90.4026725  0.5973275

The last eigenvalue of N1 is probably caused by float calculation issue. Is there any way to avoid that? Otherwise, I have to eliminate this last one and also the last column of eigenvector of N1 to reproduce SVD.

hiro7
  • 1
  • 2
  • Those outputs (the matrices `N1` and `N2`) are wrong. Please check your calculations or what you posted. – Rui Barradas May 30 '20 at 22:10
  • It seems that I firstly posted wrong matrix. Now it's modified, thanks. – hiro7 May 30 '20 at 22:21
  • Thanks. But I fail to see what you could be expecting, `N1` is a 3x3 matrix, it should have 3 eigenvalues. And `N2` only 2. – Rui Barradas May 30 '20 at 22:23
  • 1
    please clarify. @RuiBarradas is right that `eigen(N1)$values` must have length 3. You can use `zapsmall()` to set any (relatively) small values to zero ... – Ben Bolker May 30 '20 at 22:28

0 Answers0