kxcoze

canon_basis_problem4

Feb 20th, 2022 (edited)
327
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.17 KB | None | 0 0
  1. from fractions import Fraction as f    
  2.    
  3. import sympy as s    
  4. from sympy import pprint    
  5. from new_test2 import GramGauss    
  6.    
  7.    
  8. var = s.Symbol('λ')    
  9. n = int(input())    
  10. a = s.Matrix([[f(x) for x in input().split()] for i in range(n)])    
  11. b = s.matrices.eye(n, n)*var    
  12. pprint(b)    
  13. print()    
  14. pprint(a-b)    
  15. print()    
  16. equation = s.Eq(s.det(a-b), 0)    
  17. pprint(equation)    
  18. ans = s.roots(equation, var)    
  19. print(ans, '\n')    
  20. # Матрица вида 9.20    
  21. pprint(s.matrices.diag(*[x for x, i in sorted(ans.items()) for _ in range(i)]))    
  22. print()    
  23.    
  24. result = s.Matrix([])    
  25. for step, root in enumerate(sorted(ans.keys())):    
  26.     res = a - s.matrices.eye(n, n)*root    
  27.     # ФСР    
  28.     res = GramGauss(n, n, res).silent_solve()
  29.     # Ортогонализация
  30.     res = s.matrices.GramSchmidt([s.Matrix(i) for i in res])
  31.     res = [s.Matrix(i)/s.Matrix(i).norm() for i in res]
  32.     for i in res:    
  33.         result = result.col_insert(step+1, s.Matrix(i))    
  34.    
  35. print('Ортонормированный базис')    
  36. pprint(result)    
  37.    
  38. print('Проверка')    
  39. pprint(result.T*a*result)
Advertisement
Add Comment
Please, Sign In to add comment