Reputation: 31
I am trying to integrate in Julia:
I have tried both QuadGK and Cubature with no success. This was my attempt with Cubature:
function h_10(K, i)
function integrand(x, v)
return f_X_opt(K, i, x) * g_V_sub(K, i, v)
end
result, _ = hcubature(x->integrand.(x[1],x[2]),[-Inf,-Inf], [Inf, Inf])
return 1 - result
end
res = h_10(K, i)
print(res)
But when I run this code my result is NaN... I assume I am incorrectly defining the integral limits but after some research I am unclear on how to define the integral limits with a variable?
Update: I believe I've made some progress by seeing that a change of variables is needed in order to integrate over infinite integrals.. My revised code is now:
transform(t)= t/(1-(t)^2)
dtransform(t)= (1+ t^2)/(1-t^2)^2
function h_10(K, i)
function integrand(x, v)
return f_X_opt(K, i, transform(x)) * g_V_sub(K, i, transform(v))* dtransform(x)* dtransform(v)
end
result, _ = hcubature(x->integrand.(x[1],x[2]),[-1,-1], [1, 1])
return 1 - result
end
res = h_10(K, i)
print(res)
However, I now get an incorrect value. I believe that this is once again due to the limits of the integral because I am not passing x into the upper limit of the inner integral.
Upvotes: 0
Views: 110