add numerical recipes library
This commit is contained in:
34
lib/nr/k_and_r/recipes/midexp.c
Normal file
34
lib/nr/k_and_r/recipes/midexp.c
Normal file
@@ -0,0 +1,34 @@
|
||||
|
||||
#include <math.h>
|
||||
#define FUNC(x) ((*funk)(-log(x))/(x))
|
||||
|
||||
float midexp(funk,aa,bb,n)
|
||||
float (*funk)(),aa,bb;
|
||||
int n;
|
||||
{
|
||||
float x,tnm,sum,del,ddel,a,b;
|
||||
static float s;
|
||||
int it,j;
|
||||
|
||||
b=exp(-aa);
|
||||
a=0.0;
|
||||
if (n == 1) {
|
||||
return (s=(b-a)*FUNC(0.5*(a+b)));
|
||||
} else {
|
||||
for(it=1,j=1;j<n-1;j++) it *= 3;
|
||||
tnm=it;
|
||||
del=(b-a)/(3.0*tnm);
|
||||
ddel=del+del;
|
||||
x=a+0.5*del;
|
||||
sum=0.0;
|
||||
for (j=1;j<=it;j++) {
|
||||
sum += FUNC(x);
|
||||
x += ddel;
|
||||
sum += FUNC(x);
|
||||
x += del;
|
||||
}
|
||||
s=(s+(b-a)*sum/tnm)/3.0;
|
||||
return s;
|
||||
}
|
||||
}
|
||||
#undef FUNC
|
||||
Reference in New Issue
Block a user