在 R 编程中查找矩阵的特征值和特征向量 – eigen()函数
R语言中的eigen()
函数用于计算矩阵的特征值和特征向量。特征值是对特征向量进行缩放的因子。
Syntax: eigen(x)
Parameters:
x: Matrix
示例 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-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
示例 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.405125
$vectors
[, 1] [, 2]
[1, ] 0.8265324 -0.7503320
[2, ] 0.5628892 0.6610612