Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
4.5k views
in Technique[技术] by (71.8m points)

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

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)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
等待大神解答

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...