I was trying to find a way to numerically integrate an array of values phi1::Vector{Float64}
of y-values, and the input space is given by the three arrays x,y,z
all defined as range(-1,stop=1,length=100)
.
I tried using HCubature.jl
package, but it requires a ::Function
and all I have is the array. It's like there is some function phi(x,y,z) which we do not know analytically. Thus we we have an array phi
where phi1[i]
stores the value of phi(x[i],y[i],z[i])
The integration has to be performed in an entirely numeric fashion without any idea of the origin of the phi1
values.
Packages like HCubature are designed to integrate functions f(p)
that you can evaluate at arbitrary points p (e.g. you have an analytic expression for f(p)
, or more generally some program that can compute f(p)
at arbitrary p
). This is by far the most efficient way to do numerical integration.
If, instead, you have data for the function evaluated on some fixed set of points, e.g. a Cartesian grid, then typically people use low-order methods like the trapezoidal rule — you can use the Trapz.jl package, for example, which already supports the multi-dimensional trapezoidal rule.
(The best method depends on where your data came from. If it's from a finite-difference algorithm, for example, ideally you would use a integration algorithm of the same order of accuracy as your FD method.)