error_small_enough :: (Mat m N1 a, Mat m N1 a, b)-> Bool
error_small_enough (_,_,err) = err < epsilon
+
+
+
+-- | Compute the Rayleigh quotient of @matrix@ and @vector@.
+--
+-- Examples:
+--
+-- >>> let m = fromList [[3,1],[1,2]] :: Mat2 Rational
+-- >>> let v = vec2d (1, 1::Rational)
+-- >>> rayleigh_quotient m v
+-- 7 % 2
+--
+rayleigh_quotient :: (RealField.C a,
+ Arity m,
+ Arity n,
+ m ~ S n)
+ => (Mat m m a)
+ -> (Mat m N1 a)
+ -> a
+rayleigh_quotient matrix vector =
+ (vector `dot` (matrix * vector)) / (norm_squared vector)
+ where
+ -- We don't use the norm function here to avoid the algebraic
+ -- requirement on our field.
+ norm_squared v = ((transpose v) * v) !!! (0,0)