How to change support of multivariate integral to [0,1]^k using scipy.integrate.quad?

∥☆過路亽.° 提交于 2021-01-29 05:21:08

问题


The following k-dimension integral has dependent limits (a support dependent on gamma):

from  scipy.integrate import nquad
import numpy as np

def func(*args):
    gamma = args[-1]
    var = np.array(args[:-1])

    return (1-1/(1+gamma-np.sum(var)))*np.prod(((1+var)**-2))

def range_func(*args):
    gamma = args[-1]
    return (0, gamma-sum(args[:-1]))

gamma, k = 10, 2
print(nquad(func, [range_func]*k, args=(gamma,) ))

The limits are defined inside the function range_func above

return (0, gamma-sum(args[:-1]))

How can this support be changed to simply [0,1]^k such that scipy.integrate.nquad still works? That is, each integral sign runs from 0 to 1. Do I just change it to return (0,1)?

(source of code, which is just a toy example of what I plan to do)

来源:https://stackoverflow.com/questions/65689891/how-to-change-support-of-multivariate-integral-to-0-1k-using-scipy-integrate

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!