0% found this document useful (0 votes)
10 views

Lab 3 Eigen Values and Eigen Vectors

Uploaded by

1pubglover456
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views

Lab 3 Eigen Values and Eigen Vectors

Uploaded by

1pubglover456
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

11/4/24, 11:54 PM Lab 3

Eigen values and Eigen vectors


library:numpy

syntax:np.linalg.eig(A)

1. Obtain the eigen values and eigen vectors for the given matrix [4,3,2 ; 1,4,1 ; 3,10,4]

In [1]: import numpy as np


A=np.array([[4,3,2],[1,4,1],[3,10,4]])
w,v=np.linalg.eig(A)
print("\n Eigen values:\n",w)
print("\n Eigen vectors:\n",v)
print("Eigen value :\n", w[0])
print("\n Corresponding Eigen vector:",v[:,0])

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]

2. Obtain the eigen values and eigen vectors for the given matrix [1,-3,3 ; 3,-5,3 ; 6,-6,4]

In [3]: import numpy as np


A=np.array([[1,-3,3],[3,-5,3],[6,-6,4]])
w,v=np.linalg.eig(A)
print("\n Eigen values:\n",w)
print("\n Eigen vectors:\n",v)
print("Eigen value :\n", w[0])
print("\n Corresponding Eigen vector:",v[:,0])

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]]
Eigen value :
4.000000000000001

Corresponding Eigen vector: [0.40824829 0.40824829 0.81649658]

localhost:8888/doc/tree/Lab 3.ipynb? 1/2


11/4/24, 11:54 PM Lab 3

B) RAYLEIGH POWER METHOD

Library: numpy

Syntax:np.dot(a,x)

1. Compute the numerically largest eigenvalue of P=[6,-2,2 ;-2,3,-1; 2,-1,3] by power


method

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

2. Compute the numerically largest eigenvalue of P=[1,1,3 ; 1,5,1 ;3,1,1] by power method

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

In [ ]:

localhost:8888/doc/tree/Lab 3.ipynb? 2/2

You might also like