JuliaMath / Cubature.jl

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

Example of bivariate integration over semi-infinite domain #32

Closed lewis500 closed 4 years ago

lewis500 commented 7 years ago

Hi I was wondering if you could give an example of how to do the change-of-varaibles trick for integrating a function of two variables over a semi-infinite domain? I read this http://ab-initio.mit.edu/wiki/index.php/Cubature#Infinite_intervals but wasn't sure if I could just repeated the procedure for two variables. I am trying to integrate a joint probability distribution; it happens to be a lognormal. Here is what I did:

  qdp(p) =hcubature(x-> begin
    l = x[2]/(1-x[2])
    ɛ = x[1]/(1-x[1])
    if l*p>ɛ
      return 0
    end
    l*f(ɛ,l)/((1-x[1])*(1-x[2]))^2
  end, [0,0],[1,1])[1]
stevengj commented 7 years ago

Yes, just doing it for two variables is fine. Alternatively, you could use polar coordinates.

stevengj commented 4 years ago

Note that

if l*p>ɛ
      return 0
end

creates a discontinuity, which will greatly slow convergence. If you want a triangular domain in (l, ɛ) coordinates (which is what this is), just do a change of variables to map it to a rectangle as explained e.g. here stevengj/HCubature.jl#16 or here