0% found this document useful (0 votes)
53 views2 pages

Zaid-LAB - 10 - Jupyter Notebook

Uploaded by

Worldly
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
53 views2 pages

Zaid-LAB - 10 - Jupyter Notebook

Uploaded by

Worldly
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

In [1]:

#LAB 10: Compute eigenvalues and corresponding eigen-vectors.Find dominant and correspond
#1.Eigenvalues and Eigenvectors
#matrix1
import numpy as np
I=np . array ([[4 ,3 , 2],[1 ,4 , 1],[3 , 10 , 4]])
print ("\n Given matrix : \n", I )
#x=np. linalg . eigvals (I)
w , v = np . linalg .eig ( I )
print ("\n Eigen values : \n", w )
print ("\n Eigen vectors : \n", v )
## To display one eigen value and correspondingeigen vector
print (" Eigen value :\n ", w[0])
print ("\n Corresponding Eigen vector :", v[:,0])

Given matrix :
[[ 4 3 2]
[ 1 4 1]
[ 3 10 4]]

Eigen values :
[8.98205672 2.12891771 0.88902557]

Eigen vectors :
[[-0.49247712 -0.82039552 -0.42973429]
[-0.26523242 0.14250681 -0.14817858]
[-0.82892584 0.55375355 0.89071407]]
Eigen value :
8.982056720677651

Corresponding Eigen vector : [-0.49247712 -0.26523242 -0.82892584]

In [2]:

#matrix2
import numpy as np
I=np . array ([[1 ,-3 , 3],[3 ,-5 , 3],[6 ,-6 , 4]])
print ("\n Given matrix : \n", I )
w , v = np . linalg .eig ( I )
print ("\n Eigen values : \n", w )
print ("\n Eigen vectors : \n", v )

Given matrix :
[[ 1 -3 3]
[ 3 -5 3]
[ 6 -6 4]]

Eigen values :
[ 4. -2. -2.]

Eigen vectors :
[[ 0.40824829 -0.40824829 -0.30502542]
[ 0.40824829 0.40824829 -0.808424 ]
[ 0.81649658 0.81649658 -0.50339858]]
In [5]:

#2.Largest eigenvalue and corresponding eigenvector by Rayleigh method


#1
import numpy as np
def normalize ( x ):
fac = abs( x ) .max ()
x_n = x / x .max ()
return fac , x_n
x = np . array ([1 , 1 , 1])
a = np . array ([[6 ,-2 , 2 ],

[-2 ,3 ,-1],[2 ,-1 , 3]])

for i in range ( 10 ):
x = np .dot(a , x )
lambda_1 , x = normalize ( x )
print (' Eigenvalue :', lambda_1 )
print (' Eigenvector :', x )

Eigenvalue : 7.999988555930031
Eigenvector : [ 1. -0.49999785 0.50000072]

In [6]:

#2
import numpy as np
def normalize ( x ):
fac = abs( x ) .max ()
x_n = x / x .max ()
return fac , x_n
x = np . array ([1 , 1 , 1])
a = np . array ([[1 ,1 , 3 ],

[1 ,5 , 1],[3 ,1 , 1]])

for i in range ( 10 ):
x = np .dot(a , x )
lambda_1 , x = normalize ( x )
print (' Eigenvalue :', lambda_1 )
print (' Eigenvector :', x )

Eigenvalue : 6.001465559355154
Eigenvector : [0.5003663 1. 0.5003663]

You might also like