My goal is to find solution to the following integration in R.
I have tried the following code, but it does not work.
my_func <- function(x){
n=45
alpha_const=1
beta_const=1
term_11 <- c()
for (i in 0:n) {
term_11[i+1] <- (n-i) / (x+n-i)
}
return( (x^(alpha_const-1)) * (exp(-beta_const*x)) * prod(term_11) )
}
integrate(my_func,0,Inf)
The solution I get is
0 with absolute error < 0
There were 46 warnings (use warnings() to see them)
When I looked in to the warnings,
Warning messages:
1: In term_11[i + 1] <- (n - i)/(x + n - i) :
number of items to replace is not a multiple of replacement length
2: In term_11[i + 1] <- (n - i)/(x + n - i) :
number of items to replace is not a multiple of replacement length
3: In term_11[i + 1] <- (n - i)/(x + n - i) :
number of items to replace is not a multiple of replacement length
4: In term_11[i + 1] <- (n - i)/(x + n - i) :
number of items to replace is not a multiple of replacement length
5: In term_11[i + 1] <- (n - i)/(x + n - i) :
number of items to replace is not a multiple of replacement length
6: In term_11[i + 1] <- (n - i)/(x + n - i) :
which went on till "46: In term...".
I think I am not handling the product term in the integrand properly. Is it possible to solve this integral numerically? How do I work with the product term here?