/* ************************************************************************ * integ.cpp: Integration using trapezoid, Simpson and Gauss rules * * UNIX (DEC OSF, IBM AIX): cc integ.c -lm * * * * comment: The derivation from the theoretical result for each method * * is saved in x y1 y2 y3 format. * * C.A. Bertulani - 03/20/2000 ************************************************************************ */ #include #include #include #include #include typedef double Number; /************************************************************************ /* function "gauss.cpp" /* routine returns Legendre points, weights */ void gauss(int npts, int job, Number a, Number b, Number x[], Number w[]) { /* npts number of points */ /* job = 0 rescaling uniformly between (a,b) */ /* 1 for integral (0,b) with 50% points inside (0, ab/(a+b))*/ /* 2 for integral (a,inf) with 50% inside (a,b+2a) */ /* x, w output grid points and weights. */ int m, i, j; Number t, t1, pp, p1, p2, p3; Number pi = 3.1415926535897932385E0; Number eps = 3.e-10; /* limit for accuracy */ m = (npts+1)/2; for(i=1; i<=m; i++) { t = cos(pi*(i-0.25)/(npts+0.5)); t1 = 1; while((fabs(t-t1))>=eps) { p1 = 1.0; p2 = 0.0; for(j=1; j<=npts; j++) { p3 = p2; p2 = p1; p1 = ((2*j-1)*t*p2-(j-1)*p3)/j; } pp = npts*(t*p1-p2)/(t*t-1); t1 = t; t = t1 - p1/pp; } x[i-1] = -t; x[npts-i] = t; w[i-1] = 2.0/((1-t*t)*pp*pp); w[npts-i] = w[i-1]; } if(job==0) { for(i=0; i