X-Git-Url: http://gitweb.michael.orlitzky.com/?p=numerical-analysis.git;a=blobdiff_plain;f=src%2FIntegration%2FSimpson.hs;h=afa932b672cee04075a43c52ccacba1e9f56be2c;hp=f0f57f29245db1a7db7bd10bd05a39a87c2347df;hb=e529722143189fe05de5a054784e22cc2a27a522;hpb=b32831b5dde3440b85cbef62f4c47fcce0ee974f diff --git a/src/Integration/Simpson.hs b/src/Integration/Simpson.hs index f0f57f2..afa932b 100644 --- a/src/Integration/Simpson.hs +++ b/src/Integration/Simpson.hs @@ -1,4 +1,5 @@ {-# LANGUAGE NoImplicitPrelude #-} +{-# LANGUAGE ScopedTypeVariables #-} {-# LANGUAGE RebindableSyntax #-} module Integration.Simpson ( @@ -40,16 +41,16 @@ import qualified Algebra.ToRational as ToRational ( C ) -- >>> simpson_1 f 0 1 -- 0.25 -- -simpson_1 :: (RealField.C a, ToRational.C a, RealField.C b) +simpson_1 :: forall a b. (RealField.C a, ToRational.C a, RealField.C b) => (a -> b) -- ^ The function @f@ -> a -- ^ The \"left\" endpoint, @a@ -> a -- ^ The \"right\" endpoint, @b@ -> b -simpson_1 f a b = - coefficient * ((f a) + 4*(f midpoint) + (f b)) +simpson_1 f x y = + coefficient * ((f x) + 4*(f midpoint) + (f y)) where - coefficient = fromRational' $ (toRational (b - a)) / 6 - midpoint = (a + b) / 2 + coefficient = fromRational' $ (toRational (y - x)) / 6 :: b + midpoint = (x + y) / 2 -- | Use the composite Simpson's rule to numerically integrate @f@