# Chapter 5 Eigenvalues and Eigenvectors¶

## Ex:5.1.1 Pg: 238¶

In [1]:
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]

Eigen values: [ 3.  2.]
Eigen vectors:
[[ 1.  0.]]
and
[[ 0.  1.]]


## Ex:5.1.2 Pg: 238¶

In [2]:
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]

The eigen values of a projection matrix are 1 or 0.
Eigen values: ['1', '0']
Eigen vectors:
[[ 0.70710678 -0.70710678]]
and
[[ 0.70710678  0.70710678]]


## Ex:5.2.1 Pg: 238¶

In [3]:
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'

Eigenvalue matrix: [ 3.  2.]
S=
[[ 1.  0.]
[ 0.  1.]]
AS=S*eigenvaluematrix
[[ 3.  0.]
[ 0.  2.]]
Therefore inv(S)*A*S=eigenvalue matrix


## Ex:5.2.2 Pg: 238¶

In [4]:
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]

The eigenvalues themselves are not so clear for a rotation.
90 degree rotation
K= [[ 0 -1]
[ 1  0]]
Eigen values: [ 0.+1.j  0.-1.j]
Eigen vectors:
[[ 0.70710678+0.j  0.70710678-0.j]]
and
[[ 0.-0.70710678j  0.+0.70710678j]]


## Ex:5.2.3 Pg: 249¶

In [5]:
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)

K is rotation through 90 degree,then K**2 is rotation through 180 degree and inv(k is rotation through -90 degree)
K=
[[ 0 -1]
[ 1  0]]
K**2=
[[-1  0]
[ 0 -1]]
K**3=
[[ 0  1]
[-1  0]]
K**4=
[[1 0]
[0 1]]
K**4 is a complete rotation through 360 degree.
Eigen value matrix,D of K:
[ 0.+1.j  0.-1.j]
and also D**4=
[ 1.+0.j  1.+0.j]


## Ex:5.3.1 Pg: 249¶

In [6]:
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

A=
[[ 0.   4. ]
[ 0.   0.5]]
Eigen values: [ 0.   0.5]
[[ 1.]
[ 0.]]
k= 0
U(k+1)(K from 0 to 5)
[[ 0.]
[ 0.]]
k= 1
U(k+1)(K from 0 to 5)
[[ 0.]
[ 0.]]
k= 2
U(k+1)(K from 0 to 5)
[[ 0.]
[ 0.]]
k= 3
U(k+1)(K from 0 to 5)
[[ 0.]
[ 0.]]
k= 4
U(k+1)(K from 0 to 5)
[[ 0.]
[ 0.]]
k= 5
U(k+1)(K from 0 to 5)
[[ 0.]
[ 0.]]
k= 5
U(k+1)=
[[ 0.49613894]
[ 0.06201737]]
k= 5
U(k+1)=
[[ 0.24806947]
[ 0.03100868]]
k= 5
U(k+1)=
[[ 0.12403473]
[ 0.01550434]]
k= 5
U(k+1)=
[[ 0.06201737]
[ 0.00775217]]
k= 5
U(k+1)=
[[ 0.03100868]
[ 0.00387609]]
k= 5
U(k+1)=
[[ 0.01550434]
[ 0.00193804]]


## Ex:5.5.1 Pg:282¶

In [8]:
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

x= (3+4j)
xx_= (25+0j)
r= (5+0j)


## Ex:5.5.2 Pg:282¶

In [9]:
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]

Length of x squared: 2.0
Length of y squared: 25.0