# gamma
Gamma函数
函数库: TyMath
# 语法
gamma(x)
gamma(a,x)
# 说明
gamma(a,x) 可支持任意实数和复数的计算。gamma函数
# 示例
计算gamma函数
使用标量和向量计算 gamma 函数。
计算
using TyMath
gamma(0.5)
ans = 1.772453850905516
计算 gamma 函数在 [-3.5 3.5] 之间的几个值。
x = -3.5:3.5
y = gamma.(x)
y = 8-element Vector{Float64}:
0.2700882058522691
-0.9453087204829418
2.363271801207355
-3.5449077018110318
1.772453850905516
0.886226925452758
1.329340388179137
3.3233509704478426
绘制gamma函数
绘制 gamma 函数及其倒数函数。
gamma 函数对于正参数快速增加,并且在所有负整数参数(以及 0)处具有简单的极点。该函数没有任何零点。相反,gamma 倒数函数在所有负整数参数(以及 0)处的值为零。
using TyMath
using TyPlot
x = Complex.(-5:0.01:5)
y1 = gamma.(x)
y2 = 1 ./ y1
hold("on")
plot(x,y1)
plot(x,y2)
plot([-4,-4],[-10,10],"--",[-3,-3],[-10,10],"--",[-2,-2],[-10,10],"--",[-1,-1],[-10,10],"--",[0,0],[-10,10],"--")
ylim([-10 10])
grid("on")
legend([raw"$\Gamma(x)$",raw"$1/\Gamma(x)$"])
hold("off")
# 输入参数
x-输入数组标量 | 向量 | 矩阵 | 多维数组
输入,指定为标量、向量、矩阵或多维数组
数据类型: Int64 | Int32 | Int16 | Int128 | Float64 | Float32 | Float16 | UInt8 | UInt16 | UInt32 | UInt64 | UInt128 | Complex
# 详细信息
gamma函数
gamma 函数由以下积分为实数 x > 0 定义:
gamma 函数插入 factorial 函数。对于整数 n:
gamma(n+1) = factorial(n) = prod(1:n)
gamma 函数的域通过解析延拓延伸到负实数,在负整数处具有简单的极点。这种扩展源于以下递归关系的重复应用:
对于gamma(a,x),定义如下:
# 算法
gamma 的计算基于参考 1 中介绍的算法。
# 参考
[1] Cody, J., An Overview of Software Development for Special Functions, Lecture Notes in Mathematics, 506, Numerical Analysis Dundee, G. A. Watson (ed.), Springer Verlag, Berlin, 1976.
[2] Abramowitz, M. and I.A. Stegun, Handbook of Mathematical Functions, National Bureau of Standards, Applied Math. Series #55, Dover Publications, 1965, sec. 6.5.