Re: [R] Numerical Integration in 1D

2008-03-07 Thread Prof Brian Ripley
On Fri, 7 Mar 2008, Max wrote: > Prof Brian Ripley formulated on Friday : >> On Fri, 7 Mar 2008, Max wrote: >> >>> Dear UseRs, >>> >>> I'm curious about the derivative of n!. >>> >>> We know that Gamma(n+1)=n! So when on takes the derivative of >>> Gamma(n+1) we get Int(ln(x)*exp(-x)*x^n,x=0..Inf)

Re: [R] Numerical Integration in 1D

2008-03-07 Thread Ravi Varadhan
Hi max, Prof. Ripley is right. Your problem is that you missed a (-) sign in the exponential. Here is a demonstration showing the agreement between numerical and analytical results: gx <- function(x, n) exp(-x) * x^n * log(x) df <- function(n) {integrate(gx, lower=0, upper=Inf, n=n)$val} lib

Re: [R] Numerical Integration in 1D

2008-03-07 Thread Max
Prof Brian Ripley formulated on Friday : > On Fri, 7 Mar 2008, Max wrote: > >> Dear UseRs, >> >> I'm curious about the derivative of n!. >> >> We know that Gamma(n+1)=n! So when on takes the derivative of >> Gamma(n+1) we get Int(ln(x)*exp(-x)*x^n,x=0..Inf). >> >> I've tried code like >> >>> in

Re: [R] Numerical Integration in 1D

2008-03-07 Thread Ravi Varadhan
Hi Max, The analytic integral \int _0 ^\Inf exp(-t) t^n log(t) might not converge because the integrand tends to -Inf as t -> 0. So, here is a numerical approach to estimating the derivative of the gamma function: library(numDeriv) fx <- function(x, n) exp(-x) * x^n gf <- function(n) {integrat

Re: [R] Numerical Integration in 1D

2008-03-07 Thread Prof Brian Ripley
On Fri, 7 Mar 2008, Max wrote: > Dear UseRs, > > I'm curious about the derivative of n!. > > We know that Gamma(n+1)=n! So when on takes the derivative of > Gamma(n+1) we get Int(ln(x)*exp(-x)*x^n,x=0..Inf). > > I've tried code like > >> integrand<-function(x) {log(x)*exp(x)*x^n} >> integrate(inte