Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from fractions import Fraction as f
- import sympy as s
- from sympy import pprint
- from new_test2 import GramGauss
- var = s.Symbol('λ')
- n = int(input())
- a = s.Matrix([[f(x) for x in input().split()] for i in range(n)])
- b = s.matrices.eye(n, n)*var
- pprint(b)
- print()
- pprint(a-b)
- print()
- equation = s.Eq(s.det(a-b), 0)
- pprint(equation)
- ans = s.roots(equation, var)
- print(ans, '\n')
- # Матрица вида 9.20
- pprint(s.matrices.diag(*[x for x, i in sorted(ans.items()) for _ in range(i)]))
- print()
- result = s.Matrix([])
- for step, root in enumerate(sorted(ans.keys())):
- res = a - s.matrices.eye(n, n)*root
- # ФСР
- res = GramGauss(n, n, res).silent_solve()
- # Ортогонализация
- res = s.matrices.GramSchmidt([s.Matrix(i) for i in res])
- res = [s.Matrix(i)/s.Matrix(i).norm() for i in res]
- for i in res:
- result = result.col_insert(step+1, s.Matrix(i))
- print('Ортонормированный базис')
- pprint(result)
- print('Проверка')
- pprint(result.T*a*result)
Advertisement
Add Comment
Please, Sign In to add comment