如何在 R 中制作对称三对角矩阵(Wilkinson 矩阵)并计算特征值?

How can I make a symmetric tridiagonal matrix (Wilkinson matrix) in R and compute the eigenvalues?

In linear algebra, Wilkinson matrices are symmetric, tridiagonal, order-N matrices with pairs of nearly, but not exactly, equal eigenvalues. Wilkinson matrices have applications in many fields, including scientific computing, numerical linear algebra, and signal processing.(Wikipedia)

根据维基百科的矩阵示例,我有这个矩阵:

     [,1] [,2] [,3] [,4] [,5] [,6] [,7]
[1,]    3    1    0    0    0    0    0
[2,]    1    2    1    0    0    0    0
[3,]    0    1    1    1    0    0    0
[4,]    0    0    1    0    1    0    0
[5,]    0    0    0    1    1    1    0
[6,]    0    0    0    0    1    2    1
[7,]    0    0    0    0    0    1    3

如何创建此矩阵并计算 R 中的特征值?

使用此脚本,您可以创建威尔金森矩阵并计算特征值

identity_6_by_7 <- diag(rep.int(1, 6), 6, 7) # create a 6x7 matrix with ones on the main diagonal
below_the_diagonal <- rbind(0, identity_6_by_7) # create a row of zeros below the diagonal 
identity_7_by_6 <- diag(rep.int(1, 6), 7, 6) # matrix with the ones offset one up from the diagonal
above_the_diagonal <- cbind(0, identity_7_by_6) # create a row of zeros above the diagonal 
on_the_diagonal <- diag(abs(seq.int(-3, 3))) # diagonal of values from abs(-3 to 3)
wilkinson_21 <- below_the_diagonal + above_the_diagonal + on_the_diagonal
eigen(wilkinson_21)$values # eigen values

你可以检查本征:

eigen(wilkinson_21)$values
[1]  3.7615572  3.7320508  2.3633282  2.0000000  1.0000000  0.2679492 -1.1248854