在C++中计算二项式系数的最佳方法是什么?我已经看到了一些代码片段,但在我看来,它总是只在某个特定区域可行.我需要一个非常非常可靠的计算.我尝试使用gamma功能:
unsigned n=N;
unsigned k=2;
number = tgammal(n + 1) / (tgammal(k + 1) * tgammal(n - k + 1));
Run Code Online (Sandbox Code Playgroud)
但它在n = 8时已经不同,k = 2的1(并且n = 30,k = 2它崩溃).我"仅"需要计算大约至少n = 3000,其中k = 2.
我正在尝试计算像这篇文章中定义的上不完全伽马函数。如果我使用
from scipy.special import gamma,gammainc
from numpy import linspace
a = 0
z = (2+3j)*np.linspace(0,10)
gamma(a)*(1-gammainc(a,z))
Run Code Online (Sandbox Code Playgroud)
哪里z是一个复杂的向量我得到一个错误
TypeError: ufunc 'gammainc' not supported for the input types, and the inputs could not be safely coerced to any supported types according to the casting rule ''safe''
Run Code Online (Sandbox Code Playgroud)
是否有替代函数来进行计算?当我尝试使用 WolframAlpha 的Gamma函数执行此操作时,似乎没有问题。
(这是计算椭圆周长的一种方法,a和b是半长轴和半短轴,h定义为:
h = (ab)^2/(a+b)^2)
阶乘函数可以通过 Gamma 函数扩展到负值,该函数是为所有非负整数的实数定义的。
在编码严重时,我尝试了 boost::math::factorial 和 boost::math::tgamma ,它们给出的结果仅低至 -1 (不包括)-1.5 例如给出错误。
#include <iostream>
#include <boost/math/special_functions/factorials.hpp>
int main()
{
double x;
double f;
double tg;
x = -0.5;
f = boost::math::factorial<double>(x);
tg = boost::math::tgamma<double>(x);
cout << "factorial of " << x << " = " << f << endl;
cout << "tgamma of " << x << " = " << tg << endl << endl;
x = -1.5;
f = boost::math::factorial<double>(x);
tg = boost::math::tgamma<double>(x);
cout …Run Code Online (Sandbox Code Playgroud) Weibull 分布的更新函数m(t)如下t = 10所示。
我想找到 的值m(t)。我写了下面的r代码来计算m(t)
last_term = NULL
gamma_k = NULL
n = 50
for(k in 1:n){
gamma_k[k] = gamma(2*k + 1)/factorial(k)
}
for(j in 1: (n-1)){
prev = gamma_k[n-j]
last_term[j] = gamma(2*j + 1)/factorial(j)*prev
}
final_term = NULL
find_value = function(n){
for(i in 2:n){
final_term[i] = gamma_k[i] - sum(last_term[1:(i-1)])
}
return(final_term)
}
all_k = find_value(n)
af_sum = NULL
m_t = function(t){
for(k in 1:n){
af_sum[k] = (-1)^(k-1) * all_k[k] …Run Code Online (Sandbox Code Playgroud) 我的很多编程都涉及到 scipy.stats 中的统计函数。一个新问题需要计算beta-二项式分布的 pmf 。因为它具有解析形式,但没有出现在 scipy.stats 中,所以我需要自己为其 pmf 定义一个函数。我正在使用 scipy 版本 0.12.0 和 numpy 版本 1.7.0。
import numpy
from scipy.special import gammaln, betaln
def beta_binomial_pmf(k, n, K, N):
# compute natural log of pmf
ln_pmf = ( gammaln(n+1) - gammaln(k+1) - gammaln(n-k+1) ) + \
- betaln(K+1,N-K+1) + betaln(K+k+1,N-K+n-k+1)
return numpy.exp(ln_pmf)
Run Code Online (Sandbox Code Playgroud)
在统计问题中,我试图解决 n 和 k 的值通常在 0 到 100 之间的范围内,但 K 和 N 可以大到 1e9。我的问题是这个函数将为不同的输入返回相同的值。
k = 0
n = 5
K = numpy.array([12, 10, 8]) …Run Code Online (Sandbox Code Playgroud) 我想用C#制作科学计算器,但我没有找到伽马函数来计算分形因子.该功能的描述如下:https: //en.wikipedia.org/wiki/Gamma_function
如何在C#中实现gamma功能?
如何用一些简单的分析函数f(s,Г)来近似反不完全伽马函数 Г(s,x)?这意味着写出类似x = f(s,Г)= 12*log(123.45*Г)+Г+ 123.4 ^ s的东西.
(我至少需要想法或参考.)
我是Python的新手,但想在我写的函数中使用Euler的Gamma函数.我不想把它写成一个整体,并想知道是否有我可以导入的东西,很容易定义伽玛函数.
谢谢
R中提供以下功能:
gamma 计算伽马函数digamma 计算log gamma函数的导数pgamma 计算不完整的伽马函数我想知道什么函数可以计算log不完整伽马函数的导数.我注意到gsl包有一个函数gamma_inc但不知道如何计算这个函数的日志的导数.
如果不存在函数,是否有一种简单的方法可以近似这个导数R?
gamma-function ×10
math ×3
python ×3
c++ ×2
factorial ×2
r ×2
scipy ×2
statistics ×2
.net ×1
boost ×1
c# ×1
c++17 ×1
calculator ×1
distribution ×1
javascript ×1
weibull ×1