+
+
+
+-- | Determine the eigenvalues of the given @matrix@ using the
+-- iterated QR algorithm (see Golub and Van Loan, \"Matrix
+-- Computations\").
+--
+-- Examples:
+--
+-- >>> import Linear.Matrix ( Col2, Col3, Mat2, Mat3 )
+-- >>> import Linear.Matrix ( frobenius_norm, fromList, identity_matrix )
+--
+-- >>> let m = fromList [[1,1],[-2,4]] :: Mat2 Double
+-- >>> let actual = eigenvalues 1000 m
+-- >>> let expected = fromList [[3],[2]] :: Col2 Double
+-- >>> frobenius_norm (actual - expected) < 1e-12
+-- True
+--
+-- >>> let m = identity_matrix :: Mat2 Double
+-- >>> let actual = eigenvalues 10 m
+-- >>> let expected = fromList [[1],[1]] :: Col2 Double
+-- >>> frobenius_norm (actual - expected) < 1e-12
+-- True
+--
+-- >>> let m = fromList [[0,1,0],[0,0,1],[1,-3,3]] :: Mat3 Double
+-- >>> let actual = eigenvalues 1000 m
+-- >>> let expected = fromList [[1],[1],[1]] :: Col3 Double
+-- >>> frobenius_norm (actual - expected) < 1e-2
+-- True
+--
+eigenvalues :: forall m a. (Arity m, Algebraic.C a, Eq a)
+ => Int
+ -> Mat (S m) (S m) a
+ -> Mat (S m) N1 a
+eigenvalues iterations matrix =
+ diagonal (ut_approximation iterations)
+ where
+ ut_approximation :: Int -> Mat (S m) (S m) a
+ ut_approximation 0 = matrix
+ ut_approximation k = rk*qk where (qk,rk) = qr (ut_approximation (k-1))
+