0

I have an M-dimensional integral where the outer limits over x_M are [0, y], the next limits over x_{M-1} are [0, max(x_M, y-x_M)], .... and the inner integral is over x_1 with limits [0, max(x_2, y-x_M-...-x_2)].

The function/integrand is

(K!/(K-M)!)*(1/(x_1+1)^2)*....*(1/(x_{M-1}+1)^2)*(1/(x_M+1)^{K-M+2})

where K and M are integers such that K >= M >= 1, and K!=K*(K-1)*...*2*1 is K factorial.

How can I do this in Python using scipy.integrate.nquad? I had a similar problem here, but don't know how to extend the code there to my case here.

The LaTeX version of the integral: See LaTeX version of the integral

My attempt (but the code isn't working. It doesn't give a result between 0 and 1)

K=4
M=2
du = 0.01
#For m=M
def F(u):
      return 1/(1+u)**(K-M+2)
#For m=1,2,...,M-1
def f(u):
     return 1/((1+u))**2

#Recursive function to evaluate the integral
def G(h, m, prev_lim):
    #print(f'h is {h}, and k is {k}')
    if m == M:
        res = F(h)
    else:
        res =  0
        u = prev_lim
        while u < h:
            res += G(h-u, m+1, u)*f(u)*du
            u += du
    return (math.factorial(K)/math.factorial(K-M))*res

print(G(2, 1, 0))
Nico Schlömer
  • 53,797
  • 27
  • 201
  • 249
BlackMath
  • 932
  • 7
  • 24
  • can you post the latex format of your question? – Onyambu Aug 21 '18 at 23:56
  • @Onyambu How? That would be better for me actually. In other forums I use the symbols $z = y + x$ for inline, and $$ z = y + x $$ for new line equations. But here these symbols don't work. – BlackMath Aug 22 '18 at 00:10
  • it seems so.. I guess you might just upload an image – Onyambu Aug 22 '18 at 00:18
  • @Onyambu OK, I did. That should make things clearer, mathematically speaking. – BlackMath Aug 22 '18 at 00:23
  • Any hint on the problem? – BlackMath Aug 22 '18 at 03:48
  • What is the random variable X(m)? sometimes knowing the distribution of the random variable is important.. if analytical methods cannot be used, then MCMC approximations can be used – Onyambu Aug 22 '18 at 04:09
  • `X(m)` is the mth order statistic. So, I have `K` random variables `X1, X2, ..., XK`, I then order them as `X(1)<=X(2)<=....<=X(K)`. I want to find the CDF of the summation of the `M` smallest random variables. The CDF and PDF of the random variable `Xk` are `1-1/(1+xk)` and `1/(1+xk)^2`, respectively. Analytical solution is not feasible as far as I can tell. What is MCMC? – BlackMath Aug 22 '18 at 04:25
  • Since you know the pdf/cdf of X(m) you can use transformation to find the pmf/cdf of Y.. MCMC is monte carlo markov chains.. which is numeric approximations – Onyambu Aug 22 '18 at 14:01
  • How to use transformation to find the CDF of Y? Can you elaborate more? – BlackMath Aug 22 '18 at 16:44
  • That is a question you should be able to answer. Its the basics of statistics. – Onyambu Aug 22 '18 at 17:17
  • You make it sound clear and simple. But it is not. You cannot separate the PDFs here, because the RVs are dependent. Anyway, if you don't want to help in the code, that is fine. Thanks anyway. – BlackMath Aug 22 '18 at 17:40
  • is there no closed form cdf of Y?? – Onyambu Aug 22 '18 at 17:42
  • No there isn't. I will my attempt in the code, but it is not working. – BlackMath Aug 22 '18 at 17:55

0 Answers0