eig【numpy】
目的:
標準固有値問題を解き、固有値および固有ベクトルを求める。
$ A \mathbf{v} = \lambda \mathbf{v}, ~~~~ \mathbf{v} \neq 0
書式:
L, V = numpy.linalg.eig(A)
引数:
A : 実数や複素数で構成された正方行列
サンプル:
code:eig_np01.py
import numpy as np
from numpy.linalg import eig, inv
A = np.array(6., -2],[6, -1)
L, V = eig(A)
print(A)
print(L)
print(V)
print(V @ np.diag(L) @ inv(V))
引数Aをn x m x m の形状で与えることにより、n個のm x m行列の固有値をまとめて求めることができる。
code:eig_np01.py
import numpy as np
from numpy.linalg import eig, inv
A = np.random.random(3, 2, 2)
L, V = eig(A)
print('L =')
print(L)
print(L.shape)
print('V =')
print(V)
print(V.shape)
print('# 検算')
# print(V @ np.diag(L) @ inv(V))
for i in range(A.shape0):
print(Ai - (Vi @ np.diag(Li) @ inv(Vi)))