R语言 查找矩阵的特征值和特征向量 – eigen()函数
R语言中的 eigen() 函数用于计算一个矩阵的特征值和特征向量。特征值是特征向量被缩放的因素。
语法: eigen(x)
参数:
x: 矩阵
例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))
输出
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-16vectors
[, 1] [, 2] [, 3]
[1, ] -0.4645473 -0.8829060 0.4082483
[2, ] -0.5707955 -0.2395204 -0.8164966
[3, ] -0.6770438 0.4038651 0.4082483
例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))
输出
[, 1] [, 2]
[1, ] 2 5
[2, ] 3 1
eigen() decomposition
values
[1] 5.405125 -2.405125vectors
[, 1] [, 2]
[1, ] 0.8265324 -0.7503320
[2, ] 0.5628892 0.6610612