diff options
Diffstat (limited to 'lib/Numeric/GSL/Integration.hs')
-rw-r--r-- | lib/Numeric/GSL/Integration.hs | 74 |
1 files changed, 37 insertions, 37 deletions
diff --git a/lib/Numeric/GSL/Integration.hs b/lib/Numeric/GSL/Integration.hs index 7c1cdb9..5f0a415 100644 --- a/lib/Numeric/GSL/Integration.hs +++ b/lib/Numeric/GSL/Integration.hs | |||
@@ -35,16 +35,16 @@ eps = 1e-12 | |||
35 | 35 | ||
36 | {- | 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 |
37 | -} | 37 | -} |
38 | 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)) |
39 | 39 | ||
40 | -------------------------------------------------------------------- | 40 | -------------------------------------------------------------------- |
41 | {- | Numerical integration using /gsl_integration_qags/ (adaptive integration with singularities). For example: | 41 | {- | Numerical integration using /gsl_integration_qags/ (adaptive integration with singularities). For example: |
42 | 42 | ||
43 | @\> let quad = integrateQAGS 1E-9 1000 | 43 | >>> let quad = integrateQAGS 1E-9 1000 |
44 | \> let f a x = x**(-0.5) * log (a*x) | 44 | >>> let f a x = x**(-0.5) * log (a*x) |
45 | \> quad (f 1) 0 1 | 45 | >>> quad (f 1) 0 1 |
46 | (-3.999999999999974,4.871658632055187e-13)@ | 46 | (-3.999999999999974,4.871658632055187e-13) |
47 | 47 | ||
48 | -} | 48 | -} |
49 | 49 | ||
50 | integrateQAGS :: Double -- ^ precision (e.g. 1E-9) | 50 | integrateQAGS :: Double -- ^ precision (e.g. 1E-9) |
@@ -56,7 +56,7 @@ integrateQAGS :: Double -- ^ precision (e.g. 1E-9) | |||
56 | integrateQAGS prec n f a b = unsafePerformIO $ do | 56 | integrateQAGS prec n f a b = unsafePerformIO $ do |
57 | r <- malloc | 57 | r <- malloc |
58 | e <- malloc | 58 | e <- malloc |
59 | fp <- mkfun (\x _ -> f x) | 59 | fp <- mkfun (\x _ -> f x) |
60 | c_integrate_qags fp a b eps prec (fromIntegral n) r e // check "integrate_qags" | 60 | c_integrate_qags fp a b eps prec (fromIntegral n) r e // check "integrate_qags" |
61 | vr <- peek r | 61 | vr <- peek r |
62 | ve <- peek e | 62 | ve <- peek e |
@@ -73,10 +73,10 @@ foreign import ccall safe "integrate_qags" c_integrate_qags | |||
73 | ----------------------------------------------------------------- | 73 | ----------------------------------------------------------------- |
74 | {- | 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: |
75 | 75 | ||
76 | @\> let quad = integrateQNG 1E-6 | 76 | >>> let quad = integrateQNG 1E-6 |
77 | \> quad (\\x -> 4\/(1+x*x)) 0 1 | 77 | >>> quad (\x -> 4/(1+x*x)) 0 1 |
78 | (3.141592653589793,3.487868498008632e-14)@ | 78 | (3.141592653589793,3.487868498008632e-14) |
79 | 79 | ||
80 | -} | 80 | -} |
81 | 81 | ||
82 | integrateQNG :: Double -- ^ precision (e.g. 1E-9) | 82 | integrateQNG :: Double -- ^ precision (e.g. 1E-9) |
@@ -87,7 +87,7 @@ integrateQNG :: Double -- ^ precision (e.g. 1E-9) | |||
87 | integrateQNG prec f a b = unsafePerformIO $ do | 87 | integrateQNG prec f a b = unsafePerformIO $ do |
88 | r <- malloc | 88 | r <- malloc |
89 | e <- malloc | 89 | e <- malloc |
90 | fp <- mkfun (\x _ -> f x) | 90 | fp <- mkfun (\x _ -> f x) |
91 | c_integrate_qng fp a b eps prec r e // check "integrate_qng" | 91 | c_integrate_qng fp a b eps prec r e // check "integrate_qng" |
92 | vr <- peek r | 92 | vr <- peek r |
93 | ve <- peek e | 93 | ve <- peek e |
@@ -102,14 +102,14 @@ foreign import ccall safe "integrate_qng" c_integrate_qng | |||
102 | -> Double -> Double -> Ptr Double -> Ptr Double -> IO CInt | 102 | -> Double -> Double -> Ptr Double -> Ptr Double -> IO CInt |
103 | 103 | ||
104 | -------------------------------------------------------------------- | 104 | -------------------------------------------------------------------- |
105 | {- | 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). |
106 | For example: | 106 | For example: |
107 | 107 | ||
108 | @\> let quad = integrateQAGI 1E-9 1000 | 108 | >>> let quad = integrateQAGI 1E-9 1000 |
109 | \> let f a x = exp(-a * x^2) | 109 | >>> let f a x = exp(-a * x^2) |
110 | \> quad (f 0.5) | 110 | >>> quad (f 0.5) |
111 | (2.5066282746310002,6.229215880648858e-11)@ | 111 | (2.5066282746310002,6.229215880648858e-11) |
112 | 112 | ||
113 | -} | 113 | -} |
114 | 114 | ||
115 | integrateQAGI :: Double -- ^ precision (e.g. 1E-9) | 115 | integrateQAGI :: Double -- ^ precision (e.g. 1E-9) |
@@ -119,7 +119,7 @@ integrateQAGI :: Double -- ^ precision (e.g. 1E-9) | |||
119 | integrateQAGI prec n f = unsafePerformIO $ do | 119 | integrateQAGI prec n f = unsafePerformIO $ do |
120 | r <- malloc | 120 | r <- malloc |
121 | e <- malloc | 121 | e <- malloc |
122 | fp <- mkfun (\x _ -> f x) | 122 | fp <- mkfun (\x _ -> f x) |
123 | c_integrate_qagi fp eps prec (fromIntegral n) r e // check "integrate_qagi" | 123 | c_integrate_qagi fp eps prec (fromIntegral n) r e // check "integrate_qagi" |
124 | vr <- peek r | 124 | vr <- peek r |
125 | ve <- peek e | 125 | ve <- peek e |
@@ -134,14 +134,14 @@ foreign import ccall safe "integrate_qagi" c_integrate_qagi | |||
134 | -> CInt -> Ptr Double -> Ptr Double -> IO CInt | 134 | -> CInt -> Ptr Double -> Ptr Double -> IO CInt |
135 | 135 | ||
136 | -------------------------------------------------------------------- | 136 | -------------------------------------------------------------------- |
137 | {- | 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). |
138 | For example: | 138 | For example: |
139 | 139 | ||
140 | @\> let quad = integrateQAGIU 1E-9 1000 | 140 | >>> let quad = integrateQAGIU 1E-9 1000 |
141 | \> let f a x = exp(-a * x^2) | 141 | >>> let f a x = exp(-a * x^2) |
142 | \> quad (f 0.5) 0 | 142 | >>> quad (f 0.5) 0 |
143 | (1.2533141373155001,3.114607940324429e-11)@ | 143 | (1.2533141373155001,3.114607940324429e-11) |
144 | 144 | ||
145 | -} | 145 | -} |
146 | 146 | ||
147 | integrateQAGIU :: Double -- ^ precision (e.g. 1E-9) | 147 | integrateQAGIU :: Double -- ^ precision (e.g. 1E-9) |
@@ -152,7 +152,7 @@ integrateQAGIU :: Double -- ^ precision (e.g. 1E-9) | |||
152 | integrateQAGIU prec n f a = unsafePerformIO $ do | 152 | integrateQAGIU prec n f a = unsafePerformIO $ do |
153 | r <- malloc | 153 | r <- malloc |
154 | e <- malloc | 154 | e <- malloc |
155 | fp <- mkfun (\x _ -> f x) | 155 | fp <- mkfun (\x _ -> f x) |
156 | c_integrate_qagiu fp a eps prec (fromIntegral n) r e // check "integrate_qagiu" | 156 | c_integrate_qagiu fp a eps prec (fromIntegral n) r e // check "integrate_qagiu" |
157 | vr <- peek r | 157 | vr <- peek r |
158 | ve <- peek e | 158 | ve <- peek e |
@@ -167,14 +167,14 @@ foreign import ccall safe "integrate_qagiu" c_integrate_qagiu | |||
167 | -> Double -> CInt -> Ptr Double -> Ptr Double -> IO CInt | 167 | -> Double -> CInt -> Ptr Double -> Ptr Double -> IO CInt |
168 | 168 | ||
169 | -------------------------------------------------------------------- | 169 | -------------------------------------------------------------------- |
170 | {- | 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). |
171 | For example: | 171 | For example: |
172 | 172 | ||
173 | @\> let quad = integrateQAGIL 1E-9 1000 | 173 | >>> let quad = integrateQAGIL 1E-9 1000 |
174 | \> let f a x = exp(-a * x^2) | 174 | >>> let f a x = exp(-a * x^2) |
175 | \> quad (f 0.5) 0 | 175 | >>> quad (f 0.5) 0 |
176 | (1.2533141373155001,3.114607940324429e-11)@ | 176 | (1.2533141373155001,3.114607940324429e-11) |
177 | 177 | ||
178 | -} | 178 | -} |
179 | 179 | ||
180 | integrateQAGIL :: Double -- ^ precision (e.g. 1E-9) | 180 | integrateQAGIL :: Double -- ^ precision (e.g. 1E-9) |
@@ -185,7 +185,7 @@ integrateQAGIL :: Double -- ^ precision (e.g. 1E-9) | |||
185 | integrateQAGIL prec n f b = unsafePerformIO $ do | 185 | integrateQAGIL prec n f b = unsafePerformIO $ do |
186 | r <- malloc | 186 | r <- malloc |
187 | e <- malloc | 187 | e <- malloc |
188 | fp <- mkfun (\x _ -> f x) | 188 | fp <- mkfun (\x _ -> f x) |
189 | c_integrate_qagil fp b eps prec (fromIntegral n) r e // check "integrate_qagil" | 189 | c_integrate_qagil fp b eps prec (fromIntegral n) r e // check "integrate_qagil" |
190 | vr <- peek r | 190 | vr <- peek r |
191 | ve <- peek e | 191 | ve <- peek e |
@@ -212,10 +212,10 @@ routines in QUADPACK, yet fails less often for difficult integrands.@ | |||
212 | 212 | ||
213 | For example: | 213 | For example: |
214 | 214 | ||
215 | @\> let quad = integrateCQUAD 1E-12 1000 | 215 | >>> let quad = integrateCQUAD 1E-12 1000 |
216 | \> let f a x = exp(-a * x^2) | 216 | >>> let f a x = exp(-a * x^2) |
217 | \> quad (f 0.5) 2 5 | 217 | >>> quad (f 0.5) 2 5 |
218 | (5.7025405463957006e-2,9.678874441303705e-16,95)@ | 218 | (5.7025405463957006e-2,9.678874441303705e-16,95) |
219 | 219 | ||
220 | Unlike other quadrature methods, integrateCQUAD also returns the | 220 | Unlike other quadrature methods, integrateCQUAD also returns the |
221 | number of function evaluations required. | 221 | number of function evaluations required. |