integration 0.1.1 → 0.2
raw patch · 2 files changed
+6/−8 lines, 2 files
Files
- Numeric/Integration/TanhSinh.hs +5/−7
- integration.cabal +1/−1
Numeric/Integration/TanhSinh.hs view
@@ -24,7 +24,7 @@ -- gained quadratically in the number of digits. -- -- > ghci> absolute 1e-6 $ parTrap sin (pi/2) pi--- > Result {result = 0.9999999999999312, errorEstimate = 2.721789573237518e-10, evalutions = 25}+-- > Result {result = 0.9999999999999312, errorEstimate = 2.721789573237518e-10, evaluations = 25} -- -- > ghci> confidence $ absolute 1e-6 $ trap sin (pi/2) pi -- > (0.9999999997277522,1.0000000002721101)@@ -33,7 +33,7 @@ -- singularities at the end points. -- -- > ghci> absolute 1e-6 $ trap (recip . sqrt . sin) 0 1--- > Result {result = 2.03480500404275, errorEstimate = 6.349514558579017e-8, evalutions = 49}+-- > Result {result = 2.03480500404275, errorEstimate = 6.349514558579017e-8, evaluations = 49} -- -- See <http://www.johndcook.com/blog/2012/02/21/care-and-treatment-of-singularities/> -- for a sense of how more naive quadrature schemes fare.@@ -67,7 +67,7 @@ data Result = Result { result :: {-# UNPACK #-} !Double , errorEstimate :: {-# UNPACK #-} !Double- , evalutions :: {-# UNPACK #-} !Int+ , evaluations :: {-# UNPACK #-} !Int } deriving (Read,Show,Eq,Ord) -- | Convert a Result to a confidence interval@@ -105,15 +105,13 @@ -- | Integrate from -inf to inf using tanh-sinh quadrature after using the change of variables @x = tan t@ ----- > everywhere trap (\x -> x*x*exp(-x))+-- > everywhere trap (\x -> exp(-x*x)) -- -- This works /much/ better than just clipping the interval at arbitrary large and small numbers. -- TODO: build a custom set of change of variable tables everywhere :: ((Double -> Double) -> Double -> Double -> r) -> (Double -> Double) -> r-everywhere method f = method (\t -> f (tan t) * (1 + square (sec t))) (-1) 1- where sec x = recip (cos x)- square x = x * x+everywhere method f = method (\t -> let tant = tan t in f tant * (1 + tant * tant)) (-pi/2) (pi/2) -- | Integration using a truncated trapezoid rule and tanh-sinh quadrature with a specified evaluation strategy trap' :: Strategy [Double] -> (Double -> Double) -> Double -> Double -> [Result]
integration.cabal view
@@ -1,5 +1,5 @@ name: integration-version: 0.1.1+version: 0.2 stability: experimental synopsis: Fast robust numeric integration via tanh-sinh quadrature description: Fast robust numeric integration via tanh-sinh quadrature