add numerical recipes library
This commit is contained in:
40
lib/nr/k_and_r/recipes/bessi.c
Normal file
40
lib/nr/k_and_r/recipes/bessi.c
Normal file
@@ -0,0 +1,40 @@
|
||||
|
||||
#include <math.h>
|
||||
#define ACC 40.0
|
||||
#define BIGNO 1.0e10
|
||||
#define BIGNI 1.0e-10
|
||||
|
||||
float bessi(n,x)
|
||||
float x;
|
||||
int n;
|
||||
{
|
||||
float bessi0();
|
||||
void nrerror();
|
||||
int j;
|
||||
float bi,bim,bip,tox,ans;
|
||||
|
||||
if (n < 2) nrerror("Index n less than 2 in bessi");
|
||||
if (x == 0.0)
|
||||
return 0.0;
|
||||
else {
|
||||
tox=2.0/fabs(x);
|
||||
bip=ans=0.0;
|
||||
bi=1.0;
|
||||
for (j=2*(n+(int) sqrt(ACC*n));j>0;j--) {
|
||||
bim=bip+j*tox*bi;
|
||||
bip=bi;
|
||||
bi=bim;
|
||||
if (fabs(bi) > BIGNO) {
|
||||
ans *= BIGNI;
|
||||
bi *= BIGNI;
|
||||
bip *= BIGNI;
|
||||
}
|
||||
if (j == n) ans=bip;
|
||||
}
|
||||
ans *= bessi0(x)/bi;
|
||||
return x < 0.0 && (n & 1) ? -ans : ans;
|
||||
}
|
||||
}
|
||||
#undef ACC
|
||||
#undef BIGNO
|
||||
#undef BIGNI
|
||||
Reference in New Issue
Block a user