ADMB Documentation  11.5.3197
 All Classes Files Functions Variables Typedefs Friends Defines
vbetai.cpp
Go to the documentation of this file.
00001 
00007 #include <fvar.hpp>
00008 #include <math.h>
00009 
00021 dvariable betai(const dvariable a, const dvariable b, const dvariable x,
00022   int maxit)
00023 {
00024   dvariable bt;
00025 
00026   if (x < 0.0 || x > 1.0) cerr << "Bad x in routine betai" << endl;
00027   if (x == 0.0 || x == 1.0) bt=0.0;
00028   else
00029     bt=exp(gammln(a+b)-gammln(a)-gammln(b)+a*log(x)+b*log(1.0-x));
00030   if (x < (a+1.0)/(a+b+2.0))
00031     return bt*betacf(a,b,x,maxit)/a;
00032   else
00033     return 1.0-bt*betacf(b,a,1.0-x,maxit)/b;
00034 }