Gnuplot伽玛函数

时间:2018-07-17 08:44:54

标签: python gnuplot

对于G>> 2的k> 2的伽马函数,如何绘制达到1的伽马CDF?当k> = 2时,gamma(k)<1,并且因为igamma(k,x / theta)在[0,1]中(在gnuplot中),因此您的CDF公式限制为gamma(k)。它给了我这样的情节gamma CDF

使用的代码如下:

set grid
set yrange[0:*]

gamma1_pdf(x, k, theta) = (1 / (gamma(k)*theta**k))*x**(k-1)*exp(-(x / theta))
gamma1_cdf(x, k, theta) = (1 / gamma(k))*igamma(k, (x / theta))

set term windows 0
plot gamma1_cdf(x, 1.0, 2.0) lc rgb "red", \
     gamma1_cdf(x, 2.0, 2.0) lc rgb "orange", \
     gamma1_cdf(x, 3.0, 2.0) lc rgb "yellow", \
     gamma1_cdf(x, 7.5, 1.0) lc rgb "black"

set term windows 1
plot gamma1_pdf(x, 1.0, 2.0) lc rgb "red", \
     gamma1_pdf(x, 2.0, 2.0) lc rgb "orange", \
     gamma1_pdf(x, 3.0, 2.0) lc rgb "yellow", \
     gamma1_pdf(x, 7.5, 1.0) lc rgb "black"

1 个答案:

答案 0 :(得分:1)

根据help igamma gnuplot实现了归一化的不完整伽玛函数,对于大x,该函数接近1,而unnormalized版本则在该极限内接近Gamma函数的值。

幸运的是,撤消规范化很容易:

set xrange [0:30]
igamma2(a,x) = igamma(a,x)*gamma(a)    # unnormalized incoplete gamma function
gamma1_cdf(x, k, theta) = (1 / gamma(k))*igamma2(k, (x / theta))

plot gamma1_cdf(x, 1.0, 2.0) lc rgb "red", \
     gamma1_cdf(x, 2.0, 2.0) lc rgb "orange", \
     gamma1_cdf(x, 3.0, 2.0) lc rgb "yellow", \
     gamma1_cdf(x, 7.5, 1.0) lc rgb "black"

enter image description here