To implement QR decomposition algorithm using the Gram-Schmidt method.
- Hardware – PCs
- Anaconda – Python 3.7 Installation / Moodle-Code Runner
-
Intialize the matrix Q and u
-
The vector u and e is given by
'''
Program to QR decomposition using the Gram-Schmidt method
Developed by: jeeva abishake
RegisterNumber: 21500568
'''
#A=QR e1,e2,e3 e1=u1/||u1|| u1=a1 u2=a2-(a2.e1)e1
import numpy as np
def QRDecomposition(A):
n,m= A.shape
Q = np.empty((n,n))
u= np.empty((n,n))
u[:,0]=A[:,0]
Q[:,0]=u[:,0]/ np.linalg.norm(u[:,0])
for i in range(1,n):
u[:,i]=A[:,i]
for j in range(i):
u[:,i] -= (A[:,i]@Q[:,j])*Q[:,j]
Q[:,i]= u[:,i]/np.linalg.norm(u[:,i])
R= np.zeros((n,m))
for i in range(n):
for j in range(i,m):
R[i,j]=A[:,j]@Q[:,i]
print(Q)
print(R)
a=np.array(eval(input()))
QRDecomposition(a)
Thus the QR decomposition algorithm using the Gram-Schmidt process is written and verified the result.