Guest User

Untitled

a guest
Dec 3rd, 2019
91
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import random
  2. import numpy as np
  3.  
  4. def GramSchmidt(*a):
  5. k=len(a[0])
  6. N=len(a)
  7. b = [[0] * k for i in range(N)]
  8. b[0]=a[0]
  9. for i in range(1,N):
  10. sum=a[i]
  11. for j in range(0,i):
  12. scolar_ab=0
  13. scolar_bb=0
  14. proj=[i for i in range(k)]
  15. for n in range(k):
  16. scolar_ab+=b[j][n]*a[i][n]
  17. scolar_bb+=b[j][n]*b[j][n]
  18. for n in range(k):
  19. proj[n]=(scolar_ab/scolar_bb)*b[j][n]
  20. for n in range(k):
  21. sum[n]-=proj[n]
  22. b[i]=sum
  23. return b
  24.  
  25. l1=np.array([1,-1,1,1])
  26. l2=np.array([3,-2,1,2])
  27. l3=np.array([-1,-2,1,2])
  28. l4=np.array([1,-2,-1,2])
  29. print('gs=',GramSchmidt(l1,l2,l3,l4))
RAW Paste Data