-
Notifications
You must be signed in to change notification settings - Fork 195
/
Eigen.py
24 lines (18 loc) · 868 Bytes
/
Eigen.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
""" From "COMPUTATIONAL PHYSICS" & "COMPUTER PROBLEMS in PHYSICS"
by RH Landau, MJ Paez, and CC Bordeianu (deceased)
Copyright R Landau, Oregon State Unv, MJ Paez, Univ Antioquia,
C Bordeianu, Univ Bucharest, 2017.
Please respect copyright & acknowledge our work."""
# Eigen.py Solution of matrix eigenvalue problem
from numpy import*
from numpy.linalg import eig
I = array( [[2./3,-1./4,-1./4], [-1./4,2./3,-1./4], [-1./4,-1./4,2./3]] )
print('\n I =\n', I)
Es, evectors = eig(I) # Solves eigenvalue problem
print('\n Eigenvalues = \n', Es)
print('\n Matrix of Eigenvectors =\n', evectors)
Vec = array([ evectors[0, 0], evectors[0, 1], evectors[0, 2] ] )
print('\n A single eigenvector to test RHS vs LHS =', Vec, '\n')
LHS = dot(I, Vec)
RHS = dot(Vec, Es[0])
print('LHS - RHS =\n', LHS-RHS)