Show HN: Rust library for numerical integration of real-valued functions (github.com)
Integrate is a fast, small, lightweight Rust library for performing numerical integration of real-valued functions. It is designed to integrate functions, providing a simple and efficient way to approximate definite integrals using various numerical methods.
Integrate supports a variety of numerical integration techniques: - Newton-Cotes methods:
- Rectangle Rule.
- Trapezoidal Rule.
- Simpson's Rule.
- Newton's 3/8 Rule.
- Gauss quadrature methods: - Gauss-Legendre.
- Gauss-Laguerre.
- Gauss-Hermite.
- Gauss-Chebyshev First Kind.
- Gauss-Chebyshev Second Kind.
- Adaptive Methods: - Adaptive Simpson's method
- Romberg’s method.
48 comments
[ 2.8 ms ] story [ 100 ms ] threadAdditionally, compile time floating-point evaluation is limited. When I looked around recently, I didn't see a rust equivalent of gcem; any kind of transcendental function evaluation (which finding Gaussian quadrature points absolutely would require) would not allow compile-time evaluation.
this method is much faster and simpler.
Or, probably, dnorm is a probability distribution which includes a likeliness function, and a cumulative likeliness function, etc. I bet it doesn't work on arbitrary functions.
For what it's worth,
prints Result: Ok(1.000000000053865)It does seem to be a usability hazard that the function being integrated is defined as a fn, rather than a Fn, as you can't pass closures that capture variables, requiring the weird dnorm definition
https://reference.wolfram.com/language/tutorial/NIntegrateOv...
https://docs.rs/integrate/latest/integrate/adaptive_quadratu...
https://docs.rs/integrate/latest/integrate/gauss_quadrature/...
https://docs.rs/integrate/latest/integrate/romberg/fn.romber...
BTW, that is not a serious suggestion; it is just that Wolfram Language (aka Mathematica) has both `Integrate` and `NIntegrate` for symbolic and numeric integration, respectively.
You can email me if you want to, I'll be happy to help.
There are common library extensions for that.
I didn't check, but I wonder if it is not better to do x = a + (i+0.5)*h... My reasoning is that if "i" is very big, then i * h can be much bigger than h/2 and thus h/2 may be eaten by numerical precision when added to i*h... And then you have to convince the optimizer to do it the way you want. But well, it's late...
Nyquist limit, but for numerical integration?