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) {integrate(fx, lower=0, upper=Inf, n=n)$val}
> grad(x=3, func=gf)
[1] 7.536706
>
> grad(x=10, func=gf)
[1] 8534040
>
Best,
Ravi.
----------------------------------------------------------------------------
-------
Ravi Varadhan, Ph.D.
Assistant Professor, The Center on Aging and Health
Division of Geriatric Medicine and Gerontology
Johns Hopkins University
Ph: (410) 502-2619
Fax: (410) 614-9625
Email: [EMAIL PROTECTED]
Webpage: http://www.jhsph.edu/agingandhealth/People/Faculty/Varadhan.html
----------------------------------------------------------------------------
--------
-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On
Behalf Of Max
Sent: Friday, March 07, 2008 1:41 PM
To: [EMAIL PROTECTED]
Subject: [R] Numerical Integration in 1D
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(integrand,lower=0,upper=Inf)
It seems that R doesn't like to integrate for any n, and I was
wondering if anyone knew a way around this?
-Max
______________________________________________
[email protected] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
______________________________________________
[email protected] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.