X-Git-Url: http://gitweb.michael.orlitzky.com/?a=blobdiff_plain;f=src%2FIntegration%2FTrapezoid.hs;h=807bbc5839cb70e303dbc47d1bbf986305780b19;hb=refs%2Fheads%2Fmaster;hp=06350fcf54a70da55ac317610c1a7dca2f3b8a62;hpb=cc93d648089344338030a9b79cd7bea7c6e8c997;p=numerical-analysis.git diff --git a/src/Integration/Trapezoid.hs b/src/Integration/Trapezoid.hs index 06350fc..807bbc5 100644 --- a/src/Integration/Trapezoid.hs +++ b/src/Integration/Trapezoid.hs @@ -1,15 +1,20 @@ +{-# LANGUAGE NoImplicitPrelude #-} +{-# LANGUAGE ScopedTypeVariables #-} {-# LANGUAGE RebindableSyntax #-} -module Integration.Trapezoid +module Integration.Trapezoid ( + trapezoid, + trapezoid_1 ) where -import Misc (partition) +import Misc ( partition ) + +import NumericPrelude hiding ( abs ) +import qualified Algebra.Field as Field ( C ) +import qualified Algebra.RealField as RealField ( C ) +import qualified Algebra.ToInteger as ToInteger ( C ) +import qualified Algebra.ToRational as ToRational ( C ) -import NumericPrelude hiding (abs) -import qualified Algebra.Field as Field -import qualified Algebra.RealField as RealField -import qualified Algebra.ToInteger as ToInteger -import qualified Algebra.ToRational as ToRational -- | Use the trapezoid rule to numerically integrate @f@ over the -- interval [@a@, @b@]. @@ -32,15 +37,15 @@ import qualified Algebra.ToRational as ToRational -- >>> trapezoid_1 f (-1) 1 -- 2.0 -- -trapezoid_1 :: (Field.C a, ToRational.C a, Field.C b) +trapezoid_1 :: forall a b. (Field.C a, ToRational.C a, Field.C b) => (a -> b) -- ^ The function @f@ -> a -- ^ The \"left\" endpoint, @a@ -> a -- ^ The \"right\" endpoint, @b@ -> b -trapezoid_1 f a b = - (((f a) + (f b)) / 2) * coerced_interval_length +trapezoid_1 f x y = + (((f x) + (f y)) / 2) * coerced_interval_length where - coerced_interval_length = fromRational' $ toRational (b - a) + coerced_interval_length = fromRational' $ toRational (y - x) :: b -- | Use the composite trapezoid rule to numerically integrate @f@ -- over @n@ subintervals of [@a@, @b@].