diff options
author | Alberto Ruiz <aruiz@um.es> | 2014-02-05 20:11:43 +0100 |
---|---|---|
committer | Alberto Ruiz <aruiz@um.es> | 2014-02-05 20:11:43 +0100 |
commit | 3adf82b7ee54b5866013449bda49cb545c13ee47 (patch) | |
tree | a6e8402ed32e4a2c2b6636e5d3a6c7d4f59247d8 | |
parent | 8dc7f16f02f71894c40fb7eae26c416b1893c0d4 (diff) |
zero absolute tolerance in the integration routines provisionally changed to 1E-12
-rw-r--r-- | lib/Numeric/GSL/Integration.hs | 51 |
1 files changed, 27 insertions, 24 deletions
diff --git a/lib/Numeric/GSL/Integration.hs b/lib/Numeric/GSL/Integration.hs index d1f552d..7c1cdb9 100644 --- a/lib/Numeric/GSL/Integration.hs +++ b/lib/Numeric/GSL/Integration.hs | |||
@@ -31,6 +31,8 @@ import Foreign.Storable(peek) | |||
31 | import Data.Packed.Internal(check,(//)) | 31 | import Data.Packed.Internal(check,(//)) |
32 | import System.IO.Unsafe(unsafePerformIO) | 32 | import System.IO.Unsafe(unsafePerformIO) |
33 | 33 | ||
34 | eps = 1e-12 | ||
35 | |||
34 | {- | conversion of Haskell functions into function pointers that can be used in the C side | 36 | {- | conversion of Haskell functions into function pointers that can be used in the C side |
35 | -} | 37 | -} |
36 | foreign import ccall safe "wrapper" mkfun:: (Double -> Ptr() -> Double) -> IO( FunPtr (Double -> Ptr() -> Double)) | 38 | foreign import ccall safe "wrapper" mkfun:: (Double -> Ptr() -> Double) -> IO( FunPtr (Double -> Ptr() -> Double)) |
@@ -55,7 +57,7 @@ integrateQAGS prec n f a b = unsafePerformIO $ do | |||
55 | r <- malloc | 57 | r <- malloc |
56 | e <- malloc | 58 | e <- malloc |
57 | fp <- mkfun (\x _ -> f x) | 59 | fp <- mkfun (\x _ -> f x) |
58 | c_integrate_qags fp a b prec (fromIntegral n) r e // check "integrate_qags" | 60 | c_integrate_qags fp a b eps prec (fromIntegral n) r e // check "integrate_qags" |
59 | vr <- peek r | 61 | vr <- peek r |
60 | ve <- peek e | 62 | ve <- peek e |
61 | let result = (vr,ve) | 63 | let result = (vr,ve) |
@@ -64,9 +66,9 @@ integrateQAGS prec n f a b = unsafePerformIO $ do | |||
64 | freeHaskellFunPtr fp | 66 | freeHaskellFunPtr fp |
65 | return result | 67 | return result |
66 | 68 | ||
67 | foreign import ccall safe "gsl-aux.h integrate_qags" | 69 | foreign import ccall safe "integrate_qags" c_integrate_qags |
68 | c_integrate_qags :: FunPtr (Double-> Ptr() -> Double) -> Double -> Double -> Double -> CInt | 70 | :: FunPtr (Double-> Ptr() -> Double) -> Double -> Double |
69 | -> Ptr Double -> Ptr Double -> IO CInt | 71 | -> Double -> Double -> CInt -> Ptr Double -> Ptr Double -> IO CInt |
70 | 72 | ||
71 | ----------------------------------------------------------------- | 73 | ----------------------------------------------------------------- |
72 | {- | Numerical integration using /gsl_integration_qng/ (useful for fast integration of smooth functions). For example: | 74 | {- | Numerical integration using /gsl_integration_qng/ (useful for fast integration of smooth functions). For example: |
@@ -86,7 +88,7 @@ integrateQNG prec f a b = unsafePerformIO $ do | |||
86 | r <- malloc | 88 | r <- malloc |
87 | e <- malloc | 89 | e <- malloc |
88 | fp <- mkfun (\x _ -> f x) | 90 | fp <- mkfun (\x _ -> f x) |
89 | c_integrate_qng fp a b prec r e // check "integrate_qng" | 91 | c_integrate_qng fp a b eps prec r e // check "integrate_qng" |
90 | vr <- peek r | 92 | vr <- peek r |
91 | ve <- peek e | 93 | ve <- peek e |
92 | let result = (vr,ve) | 94 | let result = (vr,ve) |
@@ -95,9 +97,9 @@ integrateQNG prec f a b = unsafePerformIO $ do | |||
95 | freeHaskellFunPtr fp | 97 | freeHaskellFunPtr fp |
96 | return result | 98 | return result |
97 | 99 | ||
98 | foreign import ccall safe "gsl-aux.h integrate_qng" | 100 | foreign import ccall safe "integrate_qng" c_integrate_qng |
99 | c_integrate_qng :: FunPtr (Double-> Ptr() -> Double) -> Double -> Double -> Double | 101 | :: FunPtr (Double-> Ptr() -> Double) -> Double -> Double |
100 | -> Ptr Double -> Ptr Double -> IO CInt | 102 | -> Double -> Double -> Ptr Double -> Ptr Double -> IO CInt |
101 | 103 | ||
102 | -------------------------------------------------------------------- | 104 | -------------------------------------------------------------------- |
103 | {- | Numerical integration using /gsl_integration_qagi/ (integration over the infinite integral -Inf..Inf using QAGS). | 105 | {- | Numerical integration using /gsl_integration_qagi/ (integration over the infinite integral -Inf..Inf using QAGS). |
@@ -118,7 +120,7 @@ integrateQAGI prec n f = unsafePerformIO $ do | |||
118 | r <- malloc | 120 | r <- malloc |
119 | e <- malloc | 121 | e <- malloc |
120 | fp <- mkfun (\x _ -> f x) | 122 | fp <- mkfun (\x _ -> f x) |
121 | c_integrate_qagi fp prec (fromIntegral n) r e // check "integrate_qagi" | 123 | c_integrate_qagi fp eps prec (fromIntegral n) r e // check "integrate_qagi" |
122 | vr <- peek r | 124 | vr <- peek r |
123 | ve <- peek e | 125 | ve <- peek e |
124 | let result = (vr,ve) | 126 | let result = (vr,ve) |
@@ -127,9 +129,9 @@ integrateQAGI prec n f = unsafePerformIO $ do | |||
127 | freeHaskellFunPtr fp | 129 | freeHaskellFunPtr fp |
128 | return result | 130 | return result |
129 | 131 | ||
130 | foreign import ccall safe "gsl-aux.h integrate_qagi" | 132 | foreign import ccall safe "integrate_qagi" c_integrate_qagi |
131 | c_integrate_qagi :: FunPtr (Double-> Ptr() -> Double) -> Double -> CInt | 133 | :: FunPtr (Double-> Ptr() -> Double) -> Double -> Double |
132 | -> Ptr Double -> Ptr Double -> IO CInt | 134 | -> CInt -> Ptr Double -> Ptr Double -> IO CInt |
133 | 135 | ||
134 | -------------------------------------------------------------------- | 136 | -------------------------------------------------------------------- |
135 | {- | Numerical integration using /gsl_integration_qagiu/ (integration over the semi-infinite integral a..Inf). | 137 | {- | Numerical integration using /gsl_integration_qagiu/ (integration over the semi-infinite integral a..Inf). |
@@ -151,7 +153,7 @@ integrateQAGIU prec n f a = unsafePerformIO $ do | |||
151 | r <- malloc | 153 | r <- malloc |
152 | e <- malloc | 154 | e <- malloc |
153 | fp <- mkfun (\x _ -> f x) | 155 | fp <- mkfun (\x _ -> f x) |
154 | c_integrate_qagiu fp a prec (fromIntegral n) r e // check "integrate_qagiu" | 156 | c_integrate_qagiu fp a eps prec (fromIntegral n) r e // check "integrate_qagiu" |
155 | vr <- peek r | 157 | vr <- peek r |
156 | ve <- peek e | 158 | ve <- peek e |
157 | let result = (vr,ve) | 159 | let result = (vr,ve) |
@@ -160,9 +162,9 @@ integrateQAGIU prec n f a = unsafePerformIO $ do | |||
160 | freeHaskellFunPtr fp | 162 | freeHaskellFunPtr fp |
161 | return result | 163 | return result |
162 | 164 | ||
163 | foreign import ccall safe "gsl-aux.h integrate_qagiu" | 165 | foreign import ccall safe "integrate_qagiu" c_integrate_qagiu |
164 | c_integrate_qagiu :: FunPtr (Double-> Ptr() -> Double) -> Double -> Double -> CInt | 166 | :: FunPtr (Double-> Ptr() -> Double) -> Double -> Double |
165 | -> Ptr Double -> Ptr Double -> IO CInt | 167 | -> Double -> CInt -> Ptr Double -> Ptr Double -> IO CInt |
166 | 168 | ||
167 | -------------------------------------------------------------------- | 169 | -------------------------------------------------------------------- |
168 | {- | Numerical integration using /gsl_integration_qagil/ (integration over the semi-infinite integral -Inf..b). | 170 | {- | Numerical integration using /gsl_integration_qagil/ (integration over the semi-infinite integral -Inf..b). |
@@ -184,7 +186,7 @@ integrateQAGIL prec n f b = unsafePerformIO $ do | |||
184 | r <- malloc | 186 | r <- malloc |
185 | e <- malloc | 187 | e <- malloc |
186 | fp <- mkfun (\x _ -> f x) | 188 | fp <- mkfun (\x _ -> f x) |
187 | c_integrate_qagil fp b prec (fromIntegral n) r e // check "integrate_qagil" | 189 | c_integrate_qagil fp b eps prec (fromIntegral n) r e // check "integrate_qagil" |
188 | vr <- peek r | 190 | vr <- peek r |
189 | ve <- peek e | 191 | ve <- peek e |
190 | let result = (vr,ve) | 192 | let result = (vr,ve) |
@@ -193,9 +195,9 @@ integrateQAGIL prec n f b = unsafePerformIO $ do | |||
193 | freeHaskellFunPtr fp | 195 | freeHaskellFunPtr fp |
194 | return result | 196 | return result |
195 | 197 | ||
196 | foreign import ccall safe "gsl-aux.h integrate_qagil" | 198 | foreign import ccall safe "gsl-aux.h integrate_qagil" c_integrate_qagil |
197 | c_integrate_qagil :: FunPtr (Double-> Ptr() -> Double) -> Double -> Double -> CInt | 199 | :: FunPtr (Double-> Ptr() -> Double) -> Double -> Double |
198 | -> Ptr Double -> Ptr Double -> IO CInt | 200 | -> Double -> CInt -> Ptr Double -> Ptr Double -> IO CInt |
199 | 201 | ||
200 | 202 | ||
201 | -------------------------------------------------------------------- | 203 | -------------------------------------------------------------------- |
@@ -231,7 +233,7 @@ integrateCQUAD prec n f a b = unsafePerformIO $ do | |||
231 | e <- malloc | 233 | e <- malloc |
232 | neval <- malloc | 234 | neval <- malloc |
233 | fp <- mkfun (\x _ -> f x) | 235 | fp <- mkfun (\x _ -> f x) |
234 | c_integrate_cquad fp a b prec (fromIntegral n) r e neval // check "integrate_cquad" | 236 | c_integrate_cquad fp a b eps prec (fromIntegral n) r e neval // check "integrate_cquad" |
235 | vr <- peek r | 237 | vr <- peek r |
236 | ve <- peek e | 238 | ve <- peek e |
237 | vneval <- peek neval | 239 | vneval <- peek neval |
@@ -242,6 +244,7 @@ integrateCQUAD prec n f a b = unsafePerformIO $ do | |||
242 | freeHaskellFunPtr fp | 244 | freeHaskellFunPtr fp |
243 | return result | 245 | return result |
244 | 246 | ||
245 | foreign import ccall safe "gsl-aux.h integrate_cquad" | 247 | foreign import ccall safe "integrate_cquad" c_integrate_cquad |
246 | c_integrate_cquad :: FunPtr (Double-> Ptr() -> Double) -> Double -> Double -> Double -> CInt | 248 | :: FunPtr (Double-> Ptr() -> Double) -> Double -> Double |
247 | -> Ptr Double -> Ptr Double -> Ptr Int -> IO CInt | 249 | -> Double -> Double -> CInt -> Ptr Double -> Ptr Double -> Ptr Int -> IO CInt |
250 | |||