I am at loss here: I am integrating the functions ρ*cos(ϕ)
and ρ*sin(ϕ)
on a disk using pcubature and hcubature and obtain two different results that are not within the error (top is integrals, bottom is errors)
Here is the code: the integrand is the square function.
using Cubature
using Plots
pyplot()
function test_cuba_method(field, reltol, abstol, f, method)
ρ0 = 2e-1
inv_vol = 1.0 / (π * ρ0^2)
integr(polar_point, v) = begin
ρ_norm = polar_point[1] * inv_vol
v[:] = ρ_norm * (f - field(polar_point)).^2
end
method == :hcuba && return hcubature(length(f), integr, [0.0, 0.0], [ρ0, 2π], reltol=reltol, abstol=abstol)
method == :pcuba && return pcubature(length(f), integr, [0.0, 0.0], [ρ0, 2π], reltol=reltol, abstol=abstol)
end
function test()
freq_range = linspace(-0.5, +0.5, 101)
field_sin = p -> 5 * p[1] * sin(p[2])
field_cos = p -> 5 * p[1] * cos(p[2])
@time line_cm1, err_cm1 = test_cuba_method(field_cos, 1e-6, 1e-4, freq_range, :hcuba)
@time line_cm2, err_cm2 = test_cuba_method(field_sin, 1e-6, 1e-4, freq_range, :hcuba)
@time line_cm3, err_cm3 = test_cuba_method(field_cos, 1e-6, 1e-4, freq_range, :pcuba)
@time line_cm4, err_cm4 = test_cuba_method(field_sin, 1e-6, 1e-4, freq_range, :pcuba)
plot(plot(freq_range, hcat(line_cm1, line_cm2, line_cm3, line_cm4),
label=["cos, hcuba", "cos, hcuba", "cos, hcuba", "cos, hcuba"]'),
plot(freq_range, hcat(err_cm1, err_cm2, err_cm3, err_cm4),
label=["cos, hcuba", "cos, hcuba", "cos, hcuba", "cos, hcuba"]'),
reuse=false, layout=(2,1))
end