问题
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