summaryrefslogtreecommitdiff
path: root/lib/Numeric/GSL/Integration.hs
diff options
context:
space:
mode:
Diffstat (limited to 'lib/Numeric/GSL/Integration.hs')
-rw-r--r--lib/Numeric/GSL/Integration.hs104
1 files changed, 103 insertions, 1 deletions
diff --git a/lib/Numeric/GSL/Integration.hs b/lib/Numeric/GSL/Integration.hs
index a0e922b..2330fc6 100644
--- a/lib/Numeric/GSL/Integration.hs
+++ b/lib/Numeric/GSL/Integration.hs
@@ -17,7 +17,10 @@ Numerical integration routines.
17 17
18module Numeric.GSL.Integration ( 18module Numeric.GSL.Integration (
19 integrateQNG, 19 integrateQNG,
20 integrateQAGS 20 integrateQAGS,
21 integrateQAGI,
22 integrateQAGIU,
23 integrateQAGIL
21) where 24) where
22 25
23import Foreign.C.Types 26import Foreign.C.Types
@@ -94,3 +97,102 @@ integrateQNG prec f a b = unsafePerformIO $ do
94foreign import ccall "gsl-aux.h integrate_qng" 97foreign import ccall "gsl-aux.h integrate_qng"
95 c_integrate_qng :: FunPtr (Double-> Ptr() -> Double) -> Double -> Double -> Double 98 c_integrate_qng :: FunPtr (Double-> Ptr() -> Double) -> Double -> Double -> Double
96 -> Ptr Double -> Ptr Double -> IO CInt 99 -> Ptr Double -> Ptr Double -> IO CInt
100
101--------------------------------------------------------------------
102{- | Numerical integration using /gsl_integration_qagi/ (integration over the infinite integral -Inf..Inf using QAGS).
103For example:
104
105@\> let quad = integrateQAGI 1E-9 1000
106\> let f a x = exp(-a * x^2)
107\> quad (f 0.5)
108(2.5066282746310002,6.229215880648858e-11)@
109
110-}
111
112integrateQAGI :: Double -- ^ precision (e.g. 1E-9)
113 -> Int -- ^ size of auxiliary workspace (e.g. 1000)
114 -> (Double -> Double) -- ^ function to be integrated on the interval (-Inf,Inf)
115 -> (Double, Double) -- ^ result of the integration and error
116integrateQAGI prec n f = unsafePerformIO $ do
117 r <- malloc
118 e <- malloc
119 fp <- mkfun (\x _ -> f x)
120 c_integrate_qagi fp prec (fromIntegral n) r e // check "integrate_qagi"
121 vr <- peek r
122 ve <- peek e
123 let result = (vr,ve)
124 free r
125 free e
126 freeHaskellFunPtr fp
127 return result
128
129foreign import ccall "gsl-aux.h integrate_qagi"
130 c_integrate_qagi :: FunPtr (Double-> Ptr() -> Double) -> Double -> CInt
131 -> Ptr Double -> Ptr Double -> IO CInt
132
133--------------------------------------------------------------------
134{- | Numerical integration using /gsl_integration_qagiu/ (integration over the semi-infinite integral a..Inf).
135For example:
136
137@\> let quad = integrateQAGIU 1E-9 1000
138\> let f a x = exp(-a * x^2)
139\> quad (f 0.5) 0
140(1.2533141373155001,3.114607940324429e-11)@
141
142-}
143
144integrateQAGIU :: Double -- ^ precision (e.g. 1E-9)
145 -> Int -- ^ size of auxiliary workspace (e.g. 1000)
146 -> (Double -> Double) -- ^ function to be integrated on the interval (a,Inf)
147 -> Double -- ^ a
148 -> (Double, Double) -- ^ result of the integration and error
149integrateQAGIU prec n f a = unsafePerformIO $ do
150 r <- malloc
151 e <- malloc
152 fp <- mkfun (\x _ -> f x)
153 c_integrate_qagiu fp a prec (fromIntegral n) r e // check "integrate_qagiu"
154 vr <- peek r
155 ve <- peek e
156 let result = (vr,ve)
157 free r
158 free e
159 freeHaskellFunPtr fp
160 return result
161
162foreign import ccall "gsl-aux.h integrate_qagiu"
163 c_integrate_qagiu :: FunPtr (Double-> Ptr() -> Double) -> Double -> Double -> CInt
164 -> Ptr Double -> Ptr Double -> IO CInt
165
166--------------------------------------------------------------------
167{- | Numerical integration using /gsl_integration_qagil/ (integration over the semi-infinite integral -Inf..b).
168For example:
169
170@\> let quad = integrateQAGIL 1E-9 1000
171\> let f a x = exp(-a * x^2)
172\> quad (f 0.5) 0
173(1.2533141373155001,3.114607940324429e-11)@
174
175-}
176
177integrateQAGIL :: Double -- ^ precision (e.g. 1E-9)
178 -> Int -- ^ size of auxiliary workspace (e.g. 1000)
179 -> (Double -> Double) -- ^ function to be integrated on the interval (a,Inf)
180 -> Double -- ^ b
181 -> (Double, Double) -- ^ result of the integration and error
182integrateQAGIL prec n f b = unsafePerformIO $ do
183 r <- malloc
184 e <- malloc
185 fp <- mkfun (\x _ -> f x)
186 c_integrate_qagil fp b prec (fromIntegral n) r e // check "integrate_qagil"
187 vr <- peek r
188 ve <- peek e
189 let result = (vr,ve)
190 free r
191 free e
192 freeHaskellFunPtr fp
193 return result
194
195foreign import ccall "gsl-aux.h integrate_qagil"
196 c_integrate_qagil :: FunPtr (Double-> Ptr() -> Double) -> Double -> Double -> CInt
197 -> Ptr Double -> Ptr Double -> IO CInt
198