使用eigne()求 矩阵的特征值Eigenvalues 和特征向量Eigenvectors

简介:
矩阵的特征值和特征向量的含义请参考
引用知乎 : 
  特征值首先是描述特征的。比如你的图片是有特征的,并且图片是存在某个坐标系的。特征向量就代表这个坐标系,特征值就代表这个特征在这个坐标方向上的贡献。总之,就是代表在对应坐标轴上的特征大小的贡献.

在R中如何计算特征值和特征向量?
可以通过对矩阵A进行谱分解来得到矩阵的特征值和特征向量。矩阵A的谱分解如下:A=UΛU’,其中U的列为A的特征值 所对应的特征向量,在R中可以用eigen()函数得到U和Λ。例如:
eigen函数参数如下 : 
> args(eigen)
function (x, symmetric, only.values = FALSE, EISPACK = FALSE)
NULL


其中,x参数输入矩阵;symmetric参数判断矩阵是否为对称矩阵,如果参数为空,系统将自动检测矩阵的对称性。例如:
> A=matrix(1:9,nrow=3,ncol=3)

> A
     [,1] [,2] [,3]
[1,]    1    4    7
[2,]    2    5    8
[3,]    3    6    9


eigen(A)得到一个list, 存储特征值和特征向量.
> class(eigen(A))
[1] "list"

> Aeigen=eigen(A)
> Aeigen
$values
[1]  1.611684e+01 -1.116844e+00 -4.054214e-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

得到矩阵A的特征值:
> Aeigen$values
[1]  1.611684e+01 -1.116844e+00 -4.054214e-16


得到矩阵A的特征向量:
> Aeigen$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



[参考]
4. > help(eigen)

eigen                   package:base                   R Documentation

Spectral Decomposition of a Matrix

Description:

     Computes eigenvalues and eigenvectors of numeric (double, integer,
     logical) or complex matrices.

Usage:

     eigen(x, symmetric, only.values = FALSE, EISPACK = FALSE)
     
Arguments:

       x: a numeric or complex matrix whose spectral decomposition is
          to be computed.  Logical matrices are coerced to numeric.

symmetric: if ‘TRUE’, the matrix is assumed to be symmetric (or
          Hermitian if complex) and only its lower triangle (diagonal
          included) is used.  If ‘symmetric’ is not specified, the
          matrix is inspected for symmetry.

only.values: if ‘TRUE’, only the eigenvalues are computed and returned,
          otherwise both eigenvalues and eigenvectors are returned.

 EISPACK: logical. Defunct and ignored.

Details:

     If ‘symmetric’ is unspecified, the code attempts to determine if
     the matrix is symmetric up to plausible numerical inaccuracies.
     It is faster and surer to set the value yourself.

     Computing the eigenvectors is the slow part for large matrices.

     Computing the eigendecomposition of a matrix is subject to errors
     on a real-world computer: the definitive analysis is Wilkinson
     (1965).  All you can hope for is a solution to a problem suitably
     close to ‘x’.  So even though a real asymmetric ‘x’ may have an
     algebraic solution with repeated real eigenvalues, the computed
     solution may be of a similar matrix with complex conjugate pairs
     of eigenvalues.

Value:

     The spectral decomposition of ‘x’ is returned as components of a
     list with components

  values: a vector containing the p eigenvalues of ‘x’, sorted in
          _decreasing_ order, according to ‘Mod(values)’ in the
          asymmetric case when they might be complex (even for real
          matrices).  For real asymmetric matrices the vector will be
          complex only if complex conjugate pairs of eigenvalues are
          detected.

 vectors: either a p * p matrix whose columns contain the eigenvectors
          of ‘x’, or ‘NULL’ if ‘only.values’ is ‘TRUE’.  The vectors
          are normalized to unit length.

          Recall that the eigenvectors are only defined up to a
          constant: even when the length is specified they are still
          only defined up to a scalar of modulus one (the sign for real
          matrices).
     If ‘r <- eigen(A)’, and ‘V <- r$vectors; lam <- r$values’, then

                              A = V Lmbd V^(-1)                         
     
     (up to numerical fuzz), where Lmbd =‘diag(lam)’.

Source:

     By default ‘eigen’ uses the LAPACK routines ‘DSYEVR’, ‘DGEEV’,
     ‘ZHEEV’ and ‘ZGEEV’ whereas

     LAPACK is from <URL: http://www.netlib.org/lapack> and its guide
     is listed in the references.

References:

     Anderson. E. and ten others (1999) _LAPACK Users' Guide_.  Third
     Edition.  SIAM.
     Available on-line at <URL:
     http://www.netlib.org/lapack/lug/lapack_lug.html>.

     Becker, R. A., Chambers, J. M. and Wilks, A. R. (1988) _The New S
     Language_.  Wadsworth & Brooks/Cole.  Springer-Verlag Lecture
     Notes in Computer Science *6*.

     Wilkinson, J. H. (1965) _The Algebraic Eigenvalue Problem._
     Clarendon Press, Oxford.

See Also:

     ‘svd’, a generalization of ‘eigen’; ‘qr’, and ‘chol’ for related
     decompositions.

     To compute the determinant of a matrix, the ‘qr’ decomposition is
     much more efficient: ‘det’.

Examples:

     eigen(cbind(c(1,-1), c(-1,1)))
     eigen(cbind(c(1,-1), c(-1,1)), symmetric = FALSE)
     # same (different algorithm).
     
     eigen(cbind(1, c(1,-1)), only.values = TRUE)
     eigen(cbind(-1, 2:1)) # complex values
     eigen(print(cbind(c(0, 1i), c(-1i, 0)))) # Hermite ==> real Eigenvalues
     ## 3 x 3:
     eigen(cbind( 1, 3:1, 1:3))
     eigen(cbind(-1, c(1:2,0), 0:2)) # complex values

目录
相关文章
LaTeX中的多行数学公式
LaTeX中的多行数学公式
3000 0
LaTeX中的多行数学公式
|
存储
matlab求解方程和多元函数方程组
matlab求解方程和多元函数方程组
1347 0
|
机器学习/深度学习 Web App开发 算法
如何寻找论文及其相关代码?
如何寻找论文及其相关代码?
1466 1
|
数据可视化 Linux 数据中心
服务器版Rstudio-server初体验丨随时随地云端处理数据,不再担心电脑崩盘重启了!
服务器版Rstudio-server初体验丨随时随地云端处理数据,不再担心电脑崩盘重启了!
|
机器学习/深度学习 算法 C语言
线性代数与编程语言结合 基础
线性代数与编程语言结合 基础
436 0
|
8月前
|
JSON JavaScript 前端开发
处理从API返回的JSON数据时返回Unicode编码字符串怎么处理
在处理API返回的JSON数据时,遇到类似`\u7f51\u7edc\u8fde\u63a5\u9519\u8bef`的Unicode编码字符串,可使用JavaScript内置方法转换为可读文字。主要方法包括:1. 使用`JSON.parse`自动解析;2. 使用`decodeURIComponent`和`escape`组合解码;3. 在API调用中直接处理响应数据。这些方法能有效处理多语言内容,确保正确显示非ASCII字符。
|
C++ Python
探索Python与C/C++混合编程的艺术
探索Python与C/C++混合编程的艺术
299 1
|
算法 Perl
【光波电子学】基于MATLAB的多模光纤模场分布的仿真分析
本文介绍了基于MATLAB的多模光纤模场分布仿真分析,详细阐述了多模光纤的概念、实现方法、仿真技术,并利用模式耦合方程分析方法,通过理论和仿真模型设计,展示了不同模式下的光场分布及其受光纤参数影响的分析结果。
596 4
【光波电子学】基于MATLAB的多模光纤模场分布的仿真分析
|
索引 Python
python pandas 把数据保存成csv文件,以及读取csv文件获取指定行、指定列数据
该文档详细介绍了如何使用Python的Pandas库处理图像数据集,并将其保存为CSV文件。示例数据集位于`test_data`目录中,包含5张PNG图片,每张图片名中的数字代表其标签。文档提供了将这些数据转换为CSV格式的具体步骤,包括不同格式的数据输入方法(如NumPy数组、嵌套列表、嵌套元组和字典),以及如何使用`pd.DataFrame`和`to_csv`方法保存数据。此外,还展示了如何读取CSV文件并访问其中的每一行和每一列数据,包括获取列名、指定列数据及行数据的操作方法。
640 1
|
人工智能 数据可视化 定位技术
【工具使用】QGIS导入csv文件进行数据可视化
【工具使用】QGIS导入csv文件进行数据可视化
822 0