]> gitweb.michael.orlitzky.com - numerical-analysis.git/blobdiff - src/Integration/Trapezoid.hs
Rename 'diagonal' to 'diagonal_part'.
[numerical-analysis.git] / src / Integration / Trapezoid.hs
index c358feffec5d536f913d8e3a1c080391b17762d4..06350fcf54a70da55ac317610c1a7dca2f3b8a62 100644 (file)
@@ -6,10 +6,8 @@ where
 import Misc (partition)
 
 import NumericPrelude hiding (abs)
-import Algebra.Absolute (abs)
 import qualified Algebra.Field as Field
 import qualified Algebra.RealField as RealField
-import qualified Algebra.RealRing as RealRing
 import qualified Algebra.ToInteger as ToInteger
 import qualified Algebra.ToRational as ToRational
 
@@ -40,19 +38,22 @@ trapezoid_1 :: (Field.C a, ToRational.C a, Field.C b)
             -> a       -- ^ The \"right\" endpoint, @b@
             -> b
 trapezoid_1 f a b =
-  (((f a) + (f b)) / 2) * (fromRational' $ toRational (b - a))
-
+  (((f a) + (f b)) / 2) * coerced_interval_length
+  where
+    coerced_interval_length = fromRational' $ toRational (b - a)
 
 -- | Use the composite trapezoid rule to numerically integrate @f@
 --   over @n@ subintervals of [@a@, @b@].
 --
 --   Examples:
 --
+--   >>> import Algebra.Absolute (abs)
 --   >>> let f x = x^2
 --   >>> let area = trapezoid 1000 f (-1) 1
 --   >>> abs (area - (2/3)) < 0.00001
 --   True
 --
+--   >>> import Algebra.Absolute (abs)
 --   >>> let area = trapezoid 1000 sin 0 pi
 --   >>> abs (area - 2) < 0.0001
 --   True