如果我在 gamma(z)=y 中知道 y,R 中是否有一个函数可以找到 z
Is there a function in R which finds z if I know y in gamma(z)=y
我想知道 R 中是否有任何函数可以在我知道 y 和
的情况下找到 z
伽玛(z)=y
Uniroot 可能会有用,但不确定如何使用它。
谢谢
Let k denote the positive zero of the digamma function, approximately
1.461632 ...
c = Sqrt(2*pi)/e - Gamma(k) ...
... Leting L(x) = ln((x+c)/Sqrt(2*pi)), the inverse of my gamma
approximation is
ApproxInvGamma or AIG(x) = L(x) / W(L(x) / e) + 1/2.
k <- 1.461632
cc <- sqrt(2*pi)/exp(1)-gamma(k)
L <- function(x) {
log((x+cc)/sqrt(2*pi))
}
AIG <- function(x) {
Lx <- L(x)
Lx/(emdbook::lambertW(Lx*exp(-1))) + 1/2
}
par(las=1,bty="l")
curve(1-AIG(gamma(x))/x,from=2,to=20,
ylab="relative error of approximation")
或者您可以使用 uniroot()
:
AIG(5)
ufun <- function(x=5) {
uniroot(function(z) gamma(z)-x,c(1.00001,10))$root
}
ufun(5) ## 3.852341
AIG(5) ## 3.848149
我想知道 R 中是否有任何函数可以在我知道 y 和
的情况下找到 z伽玛(z)=y
Uniroot 可能会有用,但不确定如何使用它。
谢谢
Let k denote the positive zero of the digamma function, approximately 1.461632 ...
c = Sqrt(2*pi)/e - Gamma(k) ...
... Leting L(x) = ln((x+c)/Sqrt(2*pi)), the inverse of my gamma approximation is
ApproxInvGamma or AIG(x) = L(x) / W(L(x) / e) + 1/2.
k <- 1.461632
cc <- sqrt(2*pi)/exp(1)-gamma(k)
L <- function(x) {
log((x+cc)/sqrt(2*pi))
}
AIG <- function(x) {
Lx <- L(x)
Lx/(emdbook::lambertW(Lx*exp(-1))) + 1/2
}
par(las=1,bty="l")
curve(1-AIG(gamma(x))/x,from=2,to=20,
ylab="relative error of approximation")
或者您可以使用 uniroot()
:
AIG(5)
ufun <- function(x=5) {
uniroot(function(z) gamma(z)-x,c(1.00001,10))$root
}
ufun(5) ## 3.852341
AIG(5) ## 3.848149