mirror of
https://bitbucket.org/cosmicvoids/vide_public.git
synced 2025-07-05 07:41:11 +00:00
beginning to fold in HOD code with jeremy tinker's approval
This commit is contained in:
parent
d8108d3a8e
commit
44cd0eb71f
95 changed files with 21950 additions and 0 deletions
89
c_tools/hod/trapzd.c
Normal file
89
c_tools/hod/trapzd.c
Normal file
|
@ -0,0 +1,89 @@
|
|||
#define FUNC(x) ((*func)(x))
|
||||
|
||||
double trapzd(double (*func)(double), double a, double b, int n)
|
||||
{
|
||||
double x,tnm,sum,del;
|
||||
static double s;
|
||||
int it,j;
|
||||
|
||||
if (n == 1) {
|
||||
return (s=0.5*(b-a)*(FUNC(a)+FUNC(b)));
|
||||
} else {
|
||||
for (it=1,j=1;j<n-1;j++) it <<= 1;
|
||||
tnm=it;
|
||||
del=(b-a)/tnm;
|
||||
x=a+0.5*del;
|
||||
for (sum=0.0,j=1;j<=it;j++,x+=del) sum += FUNC(x);
|
||||
s=0.5*(s+(b-a)*sum/tnm);
|
||||
return s;
|
||||
}
|
||||
}
|
||||
#undef FUNC
|
||||
|
||||
|
||||
#define FUNC(x) ((*func)(x))
|
||||
|
||||
double trapzd2(double (*func)(double), double a, double b, int n)
|
||||
{
|
||||
double x,tnm,sum,del;
|
||||
static double s;
|
||||
int it,j;
|
||||
|
||||
if (n == 1) {
|
||||
return (s=0.5*(b-a)*(FUNC(a)+FUNC(b)));
|
||||
} else {
|
||||
for (it=1,j=1;j<n-1;j++) it <<= 1;
|
||||
tnm=it;
|
||||
del=(b-a)/tnm;
|
||||
x=a+0.5*del;
|
||||
for (sum=0.0,j=1;j<=it;j++,x+=del) sum += FUNC(x);
|
||||
s=0.5*(s+(b-a)*sum/tnm);
|
||||
return s;
|
||||
}
|
||||
}
|
||||
#undef FUNC
|
||||
|
||||
#define FUNC(x) ((*func)(x))
|
||||
|
||||
double trapzd3(double (*func)(double), double a, double b, int n)
|
||||
{
|
||||
double x,tnm,sum,del;
|
||||
static double s;
|
||||
int it,j;
|
||||
|
||||
if (n == 1) {
|
||||
return (s=0.5*(b-a)*(FUNC(a)+FUNC(b)));
|
||||
} else {
|
||||
for (it=1,j=1;j<n-1;j++) it <<= 1;
|
||||
tnm=it;
|
||||
del=(b-a)/tnm;
|
||||
x=a+0.5*del;
|
||||
for (sum=0.0,j=1;j<=it;j++,x+=del) sum += FUNC(x);
|
||||
s=0.5*(s+(b-a)*sum/tnm);
|
||||
return s;
|
||||
}
|
||||
}
|
||||
#undef FUNC
|
||||
|
||||
#define FUNC(x) ((*func)(x))
|
||||
|
||||
double trapzd4(double (*func)(double), double a, double b, int n)
|
||||
{
|
||||
double x,tnm,sum,del;
|
||||
static double s;
|
||||
int it,j;
|
||||
|
||||
if (n == 1) {
|
||||
return (s=0.5*(b-a)*(FUNC(a)+FUNC(b)));
|
||||
} else {
|
||||
for (it=1,j=1;j<n-1;j++) it <<= 1;
|
||||
tnm=it;
|
||||
del=(b-a)/tnm;
|
||||
x=a+0.5*del;
|
||||
for (sum=0.0,j=1;j<=it;j++,x+=del) sum += FUNC(x);
|
||||
s=0.5*(s+(b-a)*sum/tnm);
|
||||
return s;
|
||||
}
|
||||
}
|
||||
#undef FUNC
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue