Last active
August 11, 2017 21:09
-
-
Save onionmk2/2976acf1f67ec53a99754abd54fb8a90 to your computer and use it in GitHub Desktop.
固有値と固有ベクトル
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
from numpy import linalg as LA # Linear algebra の意味。 | |
A = np.array([ | |
[3, -2], | |
[1, 0] | |
]) | |
# LA.eig(A) は、「Aの固有値eigenvalues とAの固有ベクトルeigenvectors」を返す。 | |
## なお、pythonは複数値を返せる関数が作れる。 https://hydrocul.github.io/wiki/programming_languages_diff/tuple/return-tuple.html | |
eigenvalues, eigenvectors = LA.eig(A) | |
# 固有値(2つあるうちの1つ。) | |
λ0 = eigenvalues[0] | |
# 固有ベクトル(2つあるうちの、λ0 とペアになる方) | |
P0 = eigenvectors[:,0] # [:,0]は2行2列の行列の、0列目を取ってくる操作。 | |
# Ap = λp 固有値と固有ベクトルの定義の、左辺と右辺 | |
left = np.dot(A, P0) | |
right = np.dot(λ0, P0) | |
# leftとrightが行列として等しい(計算誤差を考えないでほぼ等しい)か?を返す。 | |
isSame = np.allclose(left, right) | |
print(isSame) # trueになる。 | |
print("i am break point") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment