-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))
+eigenvalues iterations matrix
+ | iterations < 0 = error "negative iterations requested"
+ | iterations == 0 = diagonal matrix
+ | otherwise =
+ diagonal (ut_approximation (iterations - 1))
+ where
+ ut_approximation :: Int -> Mat (S m) (S m) a
+ ut_approximation 0 = matrix
+ ut_approximation k = ut_next
+ where
+ ut_prev = ut_approximation (k-1)
+ (qk,rk) = qr ut_prev
+ ut_next = rk*qk
+