Numeric integration

begin
using HCubature
z(x, y) = exp(-x^2)
a = (0, 0)
b = (3, 3)
hcubature(z, a, b)
end

code above returns error

MethodError: no method matching z(::StaticArrays.SVector{2, Float64})

Closest candidates are:

z(::Any, !Matched::Any) at D:\Julia-1.6.3\source\ispit20220214#==#03469600-3e27-445f-aeac-dde1f92256d9:3

  1. (::HCubature.GenzMalik{2, Float64})(::typeof(Main.workspace#36.z), ::StaticArrays.SVector{2, Float64}, ::StaticArrays.SVector{2, Float64}, ::typeof(LinearAlgebra.norm))@ genz-malik.jl:121
  2. hcubature_ (::Function, ::StaticArrays.SVector{2, Float64}, ::StaticArrays.SVector{2, Float64}, ::typeof(LinearAlgebra.norm), ::Int64, ::Int64, ::Int64, ::Int64)@ HCubature.jl:60
  3. hcubature_ @ HCubature.jl:131 [inlined]
  4. #hcubature#3 @ HCubature.jl:178 [inlined]
  5. hcubature (::Function, ::Tuple{Int64, Int64}, ::Tuple{Int64, Int64})@ HCubature.jl:178
  6. top-level scope @ Local: 6

In order to use hcubature, your integrand needs to accept a single vector of length 2, not a pair of arguments. Try

z(x) = exp(-x[1]^2)

The error is telling you that the only function called z takes two arguments, and hcubature is calling it with one vector argument.

2 Likes