LoginSignup
2
2

More than 5 years have passed since last update.

行列の固有値を求める

Posted at

多変量解析で固有値を求める必要があったのでRubyでやってみた。

ソース
require 'matrix'

m = Matrix[
        [1.000,0.808,-0.208,-0.012],
        [0.808,1.000,-0.246,-0.055],
        [-0.208,-0.246,1.000,0.661],
        [-0.012,-0.055,0.661,1.000]
    ]

p m.eigensystem.eigenvalues
結果
[0.19083052601878409, 0.31309768615199585, 1.47622476791168, 2.019847019917539]

Matrix#eigensystemはMatrix::EigenvalueDecompositionという固有情報を含んだクラスを返すらしい。
そこからeigenvaluesメソッドで固有値を配列に格納して返す。
いやぁ便利だ。

2
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
2