module Quant.Math.Integration (
Integrator
, midpoint
, trapezoid
, simpson
) where
type Integrator = (Double -> Double) -> Double -> Double -> Double
midpoint :: Int -> Integrator
midpoint intervals f lBound uBound = dx * sum (map f points)
where
dx = (uBound lBound) / fromIntegral intervals
points = take intervals $ iterate (+dx) (lBound+dx/2)
trapezoid :: Int -> Integrator
trapezoid intervals f lBound uBound = dx * ((f lBound + f uBound) / 2 + sum (map f points))
where
dx = (uBound lBound) / fromIntegral intervals
points = take (intervals1) $ iterate (+dx) (lBound+dx)
simpson :: Int -> Integrator
simpson intervals f l u =( 2 * midpoint intervals f l u + trapezoid intervals f l u ) / 3