9 #define FUNC(x) ((*func)(x)) 11 static double trapzd(
double (*func)(
double),
double a,
double b,
int n)
20 return (s=0.5*(b-a)*(
FUNC(a)+
FUNC(b)));
25 for (sum=0.0,j=1;j<=it;j++,x+=del) sum +=
FUNC(x);
27 s=0.5*(s+(b-a)*sum/tnm);
36 static double qsimp(
double (*func)(
double),
double a,
double b)
42 for (j=1;j<=
JMAX;j++) {
45 if (fabs(s-os) <
EPS*fabs(os))
return s;
49 nrerror(
"Too many steps in routine QSIMP");
61 y=exp(y)/sqrt(2*M_PI);
123 double area(
double leftmargin,
double rightmargin)
131 double coeff, integral;
137 return integral*coeff;
147 #define SHUFFLE_LENGTH 98 163 if((*idum < 0) || (iff==0)) {
165 if((*idum = (
IC-(*idum)) %
IM) < 0)
170 *idum = (
IA*(
unsigned long)(*idum)+
IC) % IM;
171 shuff_tab[j] = (*idum);
173 *idum = (
IA*(
unsigned long)(*idum)+
IC) % IM;
179 nrerror(
"Error in random number generator uniform_deviate.");
183 *idum = (
IA*(
unsigned long)(*idum)+
IC) %
IM;
184 shuff_tab[j] = *idum;
186 return (
double) iy/
IM;
199 double fac, r, v1, v2;
213 fac = sqrt(-2.0*log(r)/r);
231 printf(
"left margin=");
233 printf(
"right margin=");
235 printf(
"... %6.4f %6.4f\n",lm,rm);
236 printf(
"the answer is ... %6.4f\n",
area(lm,rm));
static double multinormal(double x)
static double multicoeff(int n)
void nrerror(char *error_text)
static int factorial(int n)
static int double_factorial(int n)
static double trapzd(double(*func)(double), double a, double b, int n)
int main(int argc, char **argv)
double multiarea(double r, int dim)
static long int power2(int n)
static double qsimp(double(*func)(double), double a, double b)
double area(double leftmargin, double rightmargin)
double uniform_deviate(long *idum)
static double gauss_deviate(long *idum)