JuliaMath / Cubature.jl

One- and multi-dimensional adaptive integration routines for the Julia language
Other
126 stars 21 forks source link

Example for hcubature_v / pcubature_v? #29

Closed ghost closed 7 years ago

ghost commented 7 years ago

Would it be possible to get an example for the _v integration routines?

Alternatively, is there a way to "retrieve", as an array, the points where the integrand was evaluated (and the corresponding integrand values)?

stevengj commented 7 years ago

There is an example in the test script: https://github.com/stevengj/Cubature.jl/blob/7ebc6bbed8aec1a5a7da84b16048e6a60db0c585/test/runtests.jl#L43-L52

Even with hcubature_v, it calls your integrand multiple times. If you want to keep track of where the integrand was evaluated, just store it in an array. e.g.:

function myintegrand(x, xsave)
    push!(xsave, x)
    return sin(3x + 2*cos(4x))
end
xsave = Float64[]
hquadrature(x -> myintegrand(x, xsave), 0, 2, abstol=1e-8)

stores the quadrature points in xsave. (Similarly, you could use an additional array to save the integrand values.)

The _v routines are mainly useful if you can parallelize the integrand evaluations.

stevengj commented 7 years ago

(A pull request to add an example to the README would be welcome.)

ghost commented 7 years ago

thanks!