Search code examples
rmatrixeigenvalueeigenvector

Eigen function in R programming


Consider the square of A using eigen() function in R.

We know that, for A = V x D x V^(-1) then A^n = V x D^n x V^(-1), where columns of V contains the eigenvectors of A and D is a diagonal matrix with eigenvalues of A on the diagonal.

`                [,1] [,2] [,3] [,4]
           [1,]    1    5    9   13
           [2,]    2    6   10   14
A =        [3,]    3    7   11   15
           [4,]    4    8   12   16    `            

The result should be same as A*A

`     [,1] [,2] [,3] [,4]
 [1,]   90  202  314  426
 [2,]  100  228  356  484
 [3,]  110  254  398  542
 [4,]  120  280  440  600    `      

I have tried

V <- eigen(A)$vectors
square_dia <- diag(eigen(A)$values,4,4)
D <- diag(A)*diag(A)

But I couldn't get the result I desired.


Solution

  • I do get these results matching. Perhaps you confused %*% (matrix product) with * (elementwise/Hadamard product) somewhere?

    V <- eigen(A)$vectors
    D <- diag(eigen(A)$values)
    M1 <- V %*% D^2 %*% solve(V)
    M2 <- A %*% A
    all.equal(M1, M2) ## TRUE
    

    You may be interested in the %^% (matrix power) operator from the expm package ...