Numerical integration only with evaluated point

I’d like to integrate a function numerically.
I found some packages, e.g., QuadGK.jl, it seems only supports numerical integration with a given function.

In my case, suppose we cannot access the function at arbitrary points.
That is, we can access only some given data points.

Check this post out about Romberg method or NumericalIntegration.jl.

1 Like

You just need to define quadrature weights.
For example, in FastGaussQuadrature.jl

using FastGaussQuadrature
p, w = gausslegendre(10)

Let’s say you have 10 values at these points, then do an integration

vals = randn(10)
integral = sum(vals .* w)

Suppose a change of interval is required when using the Gauss-Legendre quadrature and that it will not handle arbitrary input points, as it might be the case in OP’s question?

You can always regularize your Gaussian weights according to the geometric transformation on points, right?
I have not used the library you mentioned. Maybe it provides a straightforward solution though.

Romerg, mentioned by @rafael.guerra above, is surprisingly accurate for integrating smooth functions but it requires the values being integrated be evenly sampled over the independent variable.

You can always fall back to trapezoidal integration if the points are not evenly sampled, but it’s low accuracy.

I"m not sure how the quadrature weighting method would compare in performance and accuracy. Need to try it out.