from numpy import mat
from numpy.linalg import eig
A=mat([[3, 0],[0, 2]])
Eig,V=eig(A)
print 'Eigen values:',Eig
print 'Eigen vectors:\n',V[0],'\n and\n',V[1]
from __future__ import division
from numpy import mat
from numpy.linalg import eig
print 'The eigen values of a projection matrix are 1 or 0.'
P=mat([[1/2, 1/2],[1/2, 1/2]])
Eig,V=eig(P)
Eig=["%.f"%xx for xx in Eig]
print 'Eigen values:',Eig
print 'Eigen vectors:\n',V[0],'\n and\n',V[1]
from __future__ import division
from numpy import mat
from numpy.linalg import eig
P=mat([[1/2, 1/2],[1/2, 1/2]])
Val,V=eig(A)
print 'Eigenvalue matrix:',Val
print 'S=\n',V
print 'AS=S*eigenvaluematrix\n',(A*V)
print 'Therefore inv(S)*A*S=eigenvalue matrix'
from __future__ import division
from numpy import mat
from numpy.linalg import eig
print 'The eigenvalues themselves are not so clear for a rotation.'
print '90 degree rotation'
K=mat([[0, -1],[1, 0]])
print 'K=',K
Val,V=eig(K)
print 'Eigen values:',Val
print 'Eigen vectors:\n',V[0],'\n and\n',V[1]
from __future__ import division
from numpy import mat
from numpy.linalg import eig
print 'K is rotation through 90 degree,then K**2 is rotation through 180 degree and inv(k is rotation through -90 degree)'
K=mat([[0, -1],[1, 0]])
print 'K=\n',K
print 'K**2=\n',(K*K)
print 'K**3=\n',(K*K*K)
print 'K**4=\n',(K**4)
D,V=eig(K)
print 'K**4 is a complete rotation through 360 degree.'
print 'Eigen value matrix,D of K:\n',D
print 'and also D**4=\n',(D**4)
from __future__ import division
from numpy import mat
from numpy.linalg import eig
A=mat([[0, 4],[0, 1/2]])
print 'A=\n',A
Eig,zz=eig(A)
print 'Eigen values:',Eig
D,v=eig(A)
u0=v[:,0] #Taking u0 as the 1st eigen Vector.
print u0
for k in range(0,6):
print 'k=',k
u=A*u0
print 'U(k+1)(K from 0 to 5)\n',u
u0=u
u0=v[:,1] ##Taking u0 as the 2nd eigen vector.
for ki in range(0,6):
print 'k=',k
u=A*u0
print 'U(k+1)=\n',u
u0=u
from numpy import sqrt
x=3+4*1J
print 'x=',x
x_=x.conjugate()
print 'xx_=',x*x_
r=sqrt(x*x_)
print 'r=',r
from numpy import mat
i=1J
x=mat([[1, i]]).H
y=mat([[2+1*i, 2-4*i]]).H
print 'Length of x squared:',abs(x.H*x)[0,0]
print 'Length of y squared:',abs( y.H*y)[0,0]