add numerical recipes library
This commit is contained in:
17
lib/nr/cpp/recipes/betai.cpp
Normal file
17
lib/nr/cpp/recipes/betai.cpp
Normal file
@@ -0,0 +1,17 @@
|
||||
#include <cmath>
|
||||
#include "nr.h"
|
||||
using namespace std;
|
||||
|
||||
DP NR::betai(const DP a, const DP b, const DP x)
|
||||
{
|
||||
DP bt;
|
||||
|
||||
if (x < 0.0 || x > 1.0) nrerror("Bad x in routine betai");
|
||||
if (x == 0.0 || x == 1.0) bt=0.0;
|
||||
else
|
||||
bt=exp(gammln(a+b)-gammln(a)-gammln(b)+a*log(x)+b*log(1.0-x));
|
||||
if (x < (a+1.0)/(a+b+2.0))
|
||||
return bt*betacf(a,b,x)/a;
|
||||
else
|
||||
return 1.0-bt*betacf(b,a,1.0-x)/b;
|
||||
}
|
||||
Reference in New Issue
Block a user