# Double integration inside a function

**URL:** <https://discourse.julialang.org/t/double-integration-inside-a-function/78602>\
**Category:** New to Julia\
**Tags:** question\
**Created:** [March 28, 2022, 10:01am UTC](https://discourse.julialang.org/t/double-integration-inside-a-function/78602 "2022-03-28T10:01:17Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![eijizero](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/eijizero/32/34979_2.png) [@eijizero](https://discourse.julialang.org/u/eijizero)\
**Post date:** [March 28, 2022, 10:01am UTC](https://discourse.julialang.org/t/double-integration-inside-a-function/78602/1 "2022-03-28T10:01:18Z")

</div>

Hi

I want to perform a double integration.

```julia
using HCubature 
f(x,y) = x^2 + y^2;
I, e = hcubature(f, (0, 0), (1, 2))

```

But, why is there an error when I write it like this? could you help me solving this? thanks

```julia
function fx(a,b)
    f(x,y) = a*x^2 + b*y^2;
    a0, b0 = 0, 1;
    a1, b1 = 0, 2;
    I, e = hcubature(f, (a0, a1), (b0, b1));
    return I
end
fx(1,1)

```

error message

```julia
MethodError: no method matching (::var"#f#55"{Int64, Int64})(::StaticArrays.SVector{2, Float64})
Closest candidates are:
  (::var"#f#55")(::Any, ::Any) at In[104]:2

Stacktrace:
 [1] (::HCubature.GenzMalik{2, Float64})(f::var"#f#55"{Int64, Int64}, a::StaticArrays.SVector{2, Float64}, b::StaticArrays.SVector{2, Float64}, norm::typeof(LinearAlgebra.norm))
   @ HCubature ~/.julia/packages/HCubature/MepxP/src/genz-malik.jl:121
 [2] hcubature_(f::Function, a::StaticArrays.SVector{2, Float64}, b::StaticArrays.SVector{2, Float64}, norm::typeof(LinearAlgebra.norm), rtol_::Int64, atol::Int64, maxevals::Int64, initdiv::Int64)
   @ HCubature ~/.julia/packages/HCubature/MepxP/src/HCubature.jl:60
 [3] hcubature_
   @ ~/.julia/packages/HCubature/MepxP/src/HCubature.jl:131 [inlined]
 [4] #hcubature#3
   @ ~/.julia/packages/HCubature/MepxP/src/HCubature.jl:178 [inlined]
 [5] hcubature(f::Function, a::Tuple{Int64, Int64}, b::Tuple{Int64, Int64})
   @ HCubature ~/.julia/packages/HCubature/MepxP/src/HCubature.jl:178
 [6] fx(a::Int64, b::Int64)
   @ Main ./In[104]:5
 [7] top-level scope
   @ In[105]:1
 [8] eval
   @ ./boot.jl:373 [inlined]
 [9] include_string(mapexpr::typeof(REPL.softscope), mod::Module, code::String, filename::String)
   @ Base ./loading.jl:1196

```

---

<div class="post-metadata">

**Author:** ![josuagrw](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/josuagrw/32/1015_2.png) [@josuagrw](https://discourse.julialang.org/u/josuagrw)\
**Post date:** [March 28, 2022, 10:10am UTC](https://discourse.julialang.org/t/double-integration-inside-a-function/78602/2 "2022-03-28T10:10:48Z")

</div>

> [@eijizero](#):
>
> ` f(x,y) = a*x^2 + b*y^2;`

The integrand is ill-defined here. See the [documentation](https://github.com/JuliaMath/HCubature.jl#hcubature-1) for hcubature.

Try with

```julia
    f(x) = a*x[1]^2 + b*x[2]^2

```
