From 707a760eedfe9db8d107595a756271ce45c2ecb5 Mon Sep 17 00:00:00 2001 From: shugo Date: Fri, 23 Oct 2015 02:09:03 +0000 Subject: * lib/matrix/eigenvalue_decomposition.rb (tridiagonalize): fix indentation to avoid a warning when the command line option -w of ruby is specified. * lib/matrix/eigenvalue_decomposition.rb (hessenberg_to_real_schur): change the name of a block parameter to avoid a warning when the command line option -w of ruby is specified. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52235 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- test/matrix/test_matrix.rb | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'test') diff --git a/test/matrix/test_matrix.rb b/test/matrix/test_matrix.rb index e2530f7366..a578aeb1c8 100644 --- a/test/matrix/test_matrix.rb +++ b/test/matrix/test_matrix.rb @@ -582,4 +582,30 @@ class TestMatrix < Test::Unit::TestCase assert_equal @e2, @e2.vstack(@e2) assert_equal SubMatrix, SubMatrix.vstack(@e1).class end + + def test_eigenvalues_and_eigenvectors_symmetric + m = Matrix[ + [8, 1], + [1, 8] + ] + values = m.eigensystem.eigenvalues + assert_in_epsilon(7.0, values[0]) + assert_in_epsilon(9.0, values[1]) + vectors = m.eigensystem.eigenvectors + assert_in_epsilon(-vectors[0][0], vectors[0][1]) + assert_in_epsilon(vectors[1][0], vectors[1][1]) + end + + def test_eigenvalues_and_eigenvectors_nonsymmetric + m = Matrix[ + [8, 1], + [4, 5] + ] + values = m.eigensystem.eigenvalues + assert_in_epsilon(9.0, values[0]) + assert_in_epsilon(4.0, values[1]) + vectors = m.eigensystem.eigenvectors + assert_in_epsilon(vectors[0][0], vectors[0][1]) + assert_in_epsilon(-4 * vectors[1][0], vectors[1][1]) + end end -- cgit v1.2.3