Find Eigenvalues and Eigenvectors of a Matrix in R Programming – eigen() Function
eigen()
function in R Language is used to calculate eigenvalues and eigenvectors of a matrix. Eigenvalue is the factor by which a eigenvector is scaled.
Syntax: eigen(x)
Parameters:
x: Matrix
Example 1:
# R program to illustrate # Eigenvalues and eigenvectors of matrix # Create a 3x3 matrix A = matrix(c( 1 : 9 ), 3 , 3 ) cat( "The 3x3 matrix:\n" ) print (A) # Calculating Eigenvalues and eigenvectors print (eigen(A)) |
Output:
The 3x3 matrix: [, 1] [, 2] [, 3] [1, ] 1 4 7 [2, ] 2 5 8 [3, ] 3 6 9 eigen() decomposition $values [1] 1.611684e+01 -1.116844e+00 -5.700691e-16 $vectors [, 1] [, 2] [, 3] [1, ] -0.4645473 -0.8829060 0.4082483 [2, ] -0.5707955 -0.2395204 -0.8164966 [3, ] -0.6770438 0.4038651 0.4082483
Example 2:
# R program to illustrate # Eigenvalues and eigenvectors of matrix # Create a 3x3 matrix A = matrix(c( 2 , 3 , 5 , 1 ), 2 , 2 ) A # Calculating Eigenvalues and eigenvectors print (eigen(A)) |
Output:
[, 1] [, 2] [1, ] 2 5 [2, ] 3 1 eigen() decomposition $values [1] 5.405125 -2.405125 $vectors [, 1] [, 2] [1, ] 0.8265324 -0.7503320 [2, ] 0.5628892 0.6610612
Please Login to comment...