def test_cf_hamilton_linear_to_quadratic_matrix(self): """Compare the results of (1) asking directly for the linear matrix for a given Hamiltonian, and (2) forming Hamilton's equations and then linearizing them.""" dof = 3 terms = {Powers((2, 0, 0, 0, 0, 0)): -0.3, Powers((1, 1, 0, 0, 0, 0)): 0.33, Powers((0, 1, 0, 1, 1, 0)): 7.2, Powers((0, 1, 0, 0, 1, 0)): 7.12, Powers((0, 0, 3, 0, 1, 0)): -4.0 } h = Polynomial(2*dof, terms=terms) alg = LieAlgebra(dof) diag = Diagonalizer(alg) lin = diag.linear_matrix(h) rhs = diag.hamiltons_equations_rhs(h) rhs_lin = tuple([alg.isograde(h_term, 1) for h_term in rhs]) for i, pol in enumerate(rhs_lin): for m, c in pol.powers_and_coefficients(): mon = alg.monomial(m, c) self.assertEquals(alg.grade(mon), 1) for j, f in enumerate(m): if f==1: self.assertEquals(lin[i, j], c)
def test_cf_hamilton_linear_to_quadratic_matrix(self): """Compare the results of (1) asking directly for the linear matrix for a given Hamiltonian, and (2) forming Hamilton's equations and then linearizing them.""" dof = 3 terms = { Powers((2, 0, 0, 0, 0, 0)): -0.3, Powers((1, 1, 0, 0, 0, 0)): 0.33, Powers((0, 1, 0, 1, 1, 0)): 7.2, Powers((0, 1, 0, 0, 1, 0)): 7.12, Powers((0, 0, 3, 0, 1, 0)): -4.0 } h = Polynomial(2 * dof, terms=terms) alg = LieAlgebra(dof) diag = Diagonalizer(alg) lin = diag.linear_matrix(h) rhs = diag.hamiltons_equations_rhs(h) rhs_lin = tuple([alg.isograde(h_term, 1) for h_term in rhs]) for i, pol in enumerate(rhs_lin): for m, c in pol.powers_and_coefficients(): mon = alg.monomial(m, c) self.assertEquals(alg.grade(mon), 1) for j, f in enumerate(m): if f == 1: self.assertEquals(lin[i, j], c)
def test_eigensystem(self): """Multiply eigenvectors and the original matrix by the eigenvalues in order to check the integrity of the eigensystem.""" dof = 3 terms = {Powers((2, 0, 0, 0, 0, 0)): -0.3, Powers((1, 1, 0, 0, 0, 0)): 0.33, Powers((0, 0, 1, 0, 1, 0)): 7.2, Powers((0, 0, 0, 0, 0, 2)): 7.2, Powers((0, 0, 0, 1, 1, 0)): 7.12 } g = Polynomial(2*dof, terms=terms) alg = LieAlgebra(dof) diag = Diagonalizer(alg) lin = diag.linear_matrix(g) val_vec_pairs = diag.eigenvalue_eigenvector_pairs(g) for p in val_vec_pairs: prod_s = p.vec*p.val prod_v = matrixmultiply(lin, p.vec) for x in prod_s-prod_v: self.assert_(abs(x)<1.0e-15)
def test_eigensystem(self): """Multiply eigenvectors and the original matrix by the eigenvalues in order to check the integrity of the eigensystem.""" dof = 3 terms = { Powers((2, 0, 0, 0, 0, 0)): -0.3, Powers((1, 1, 0, 0, 0, 0)): 0.33, Powers((0, 0, 1, 0, 1, 0)): 7.2, Powers((0, 0, 0, 0, 0, 2)): 7.2, Powers((0, 0, 0, 1, 1, 0)): 7.12 } g = Polynomial(2 * dof, terms=terms) alg = LieAlgebra(dof) diag = Diagonalizer(alg) lin = diag.linear_matrix(g) val_vec_pairs = diag.eigenvalue_eigenvector_pairs(g) for p in val_vec_pairs: prod_s = p.vec * p.val prod_v = matrixmultiply(lin, p.vec) for x in prod_s - prod_v: self.assert_(abs(x) < 1.0e-15)