R函数eigen()返回的特征向量是否错误? [英] Are eigenvectors returned by R function eigen() wrong?

查看:749
本文介绍了R函数eigen()返回的特征向量是否错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

#eigen values and vectors
a <- matrix(c(2, -1, -1, 2), 2)

eigen(a)

我正在尝试在R中找到特征值和特征向量.函数eigen适用于特征值,但是特征向量值中有错误.有什么办法可以解决这个问题?

I am trying to find eigenvalues and eigenvectors in R. Function eigen works for eigenvalues but there are errors in eigenvectors values. Is there any way to fix that?

推荐答案

一些文书工作告诉您

    对于任何非零实数值s
  • 特征值3的特征向量为(-s, s)
  • 对于任何非零实数值t
  • 特征值1的特征向量为(t, t).
  • the eigenvector for eigenvalue 3 is (-s, s) for any non-zero real value s;
  • the eigenvector for eigenvalue 1 is (t, t) for any non-zero real value t.

将特征向量缩放为单位长度即可

Scaling eigenvectors to unit-length gives

s = ± sqrt(0.5) = ±0.7071068
t = ± sqrt(0.5) = ±0.7071068

缩放是好的,因为如果矩阵是实对称的,则特征向量的矩阵是正交的,因此其逆是其转置.以您的实对称矩阵a为例:

Scaling is good because if the matrix is real symmetric, the matrix of eigenvectors is orthonormal, so that its inverse is its transpose. Taking your real symmetric matrix a for example:

a <- matrix(c(2, -1, -1, 2), 2)
#     [,1] [,2]
#[1,]    2   -1
#[2,]   -1    2

E <- eigen(a)

d <- E[[1]]
#[1] 3 1

u <- E[[2]]
#           [,1]       [,2]
#[1,] -0.7071068 -0.7071068
#[2,]  0.7071068 -0.7071068

u %*% diag(d) %*% solve(u)  ## don't do this stupid computation in practice
#     [,1] [,2]
#[1,]    2   -1
#[2,]   -1    2

u %*% diag(d) %*% t(u)      ## don't do this stupid computation in practice
#     [,1] [,2]
#[1,]    2   -1
#[2,]   -1    2

crossprod(u)
#     [,1] [,2]
#[1,]    1    0
#[2,]    0    1

tcrossprod(u)
#     [,1] [,2]
#[1,]    1    0
#[2,]    0    1


如何使用教科书方法查找特征向量

教科书方法是求解同构系统:(A - λI)x = 0为零空间基础. 我的答案中的NullSpace功能将很有帮助.

The textbook method is to solve the homogenous system: (A - λI)x = 0 for the Null Space basis. The NullSpace function in my this answer would be helpful.

## your matrix
a <- matrix(c(2, -1, -1, 2), 2)

## knowing that eigenvalues are 3 and 1

## eigenvector for eigenvalue 3
NullSpace(a - diag(3, nrow(a)))
#     [,1]
#[1,]   -1
#[2,]    1

## eigenvector for eigenvalue 1
NullSpace(a - diag(1, nrow(a)))
#     [,1]
#[1,]    1
#[2,]    1

如您所见,它们没有被规范化".相比之下,pracma::nullspace给出归一化"的特征向量,因此您得到的结果与eigen的输出一致(直到可能的符号翻转):

As you can see, they are not "normalized". By contrasts, pracma::nullspace gives "normalized" eigenvectors, so you get something consistent with the output of eigen (up to possible sign flipping):

library(pracma)

nullspace(a - diag(3, nrow(a)))
#           [,1]
#[1,] -0.7071068
#[2,]  0.7071068

nullspace(a - diag(1, nrow(a)))
#          [,1]
#[1,] 0.7071068
#[2,] 0.7071068

这篇关于R函数eigen()返回的特征向量是否错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆