stla
September 15, 2023, 1:23pm
1
Hello,
I have uploaded two new packages to Hackage:
Let me also mention another package of mine, older, for integration on a simplex: scubature (pure Haskell implementation).
4 Likes
jaror
September 15, 2023, 1:35pm
2
I wonder how it compares to the integration package. I assume it has better performance and/or precision?
stla
September 15, 2023, 2:29pm
3
Ah this is “tanh-sinh”. Yes, numerical-integration is probably better. I experimented it in R (package RcppNumerical ) and it gives good results even for highly oscillatory functions.
stla
September 15, 2023, 2:31pm
4
You gave my an idea: it would be interesting to compare the two packages on a couple of functions. Maybe I’ll do it.
1 Like
stla
September 15, 2023, 5:41pm
5
Here are two functions whose integral is hard to compute, because the functions are highly oscillatory. The exact values of the integrals are given in the code.
import Numerical.Integration
example :: IO (Double, Double, Int) -- value, error estimate, error code
example = integration (\t -> 8 * cos(2*t/(1-t)) / (64*(1-t)**2 + t**2)) 0 1 1e-4 100000
value :: Double -- approx 1.7677e-7
value = exp (-6) * pi / (2 * exp 10)
example' :: IO (Double, Double, Int) -- value, error estimate, error code
example' = integration (\t -> 6 * cos(2*t/(1-t)) / (36*(1-t)**2 + t**2)) 0 1 1e-4 50000
value' :: Double -- approx 9.6513e-6
value' = exp (-6) * pi / (2 * exp 6)
For the first one, using 100000 subdivisions of the interval (0, 1), the result (after a while) is approximately 1.756e-7
For the second one, using 50000 subdivisions of the interval (0, 1), the result is approximately 9.649e-6
.
So the results are not bad.
I didn’t try “tanh-sinh” but I would bet it provides bad results.
A note: the error code (which should be 0) is totally crazy, a huge number, I don’t know why.