R语言 计算gamma函数对数值的二阶导数 – trigamma()函数
R语言中的 trigamma() 函数用于计算用gamma函数计算的gamma值的自然对数的二阶导数。
trigamma函数基本上。
trigamma(x) = d2(ln(factorial(n-1)))/dx2
语法: trigamma(x)
参数:
x: 数字向量
例1 :
# R program to find second derivative
# of the lgamma value
# Calling the trigamma() Function
trigamma(2)
trigamma(4)
trigamma(5.2)
输出
[1] 0.6449341
[1] 0.283823
[1] 0.2119756
例2 :
# R program to find second derivative
# of the lgamma value
# Creating a vector
x <- c(2.3, 3, 1.2)
# Calling the trigamma() Function
trigamma(x)
# Calling trigamma() function
# on negative values
trigamma(-2.3)
trigamma(-2)
输出
[1] 0.5425375 0.3949341 1.2673772
[1] 14.72591
[1] Inf