! From: "COMPUTATIONAL PHYSICS, 2nd Ed" ! by RH Landau, MJ Paez, and CC Bordeianu ! Copyright Wiley - VCH, 2007. ! Electronic Materials copyright: R Landau, Oregon State Univ, 2007; ! MJ Paez, Univ Antioquia, 2007; and CC Bordeianu, Univ Bucharest, 2007. ! Supported by the US National Science Foundation ! ! gauss.f90: Points and weights for Gaussian quadrature ! rescales the gauss - legendre grid points and weights ! ! npts number of points ! job = 0 rescalling 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. subroutine gauss(npts, job, a, b, x, w) Integer :: npts, job, m, i, j Real*8 :: x(npts), w(npts), a, b, xi Real*8 :: t, t1, pp, p1, p2, p3, aj Real*8 :: eps, pi, zero, two, one, half, quarter parameter (pi = 3.14159265358979323846264338328, eps = 3.0E - 14) parameter (zero = 0.d0, one = 1.d0, two = 2.d0) parameter (half = 0.5d0, quarter = 0.25d0) m = (npts + 1)/2 Do i = 1, m t = cos(pi*(i- quarter)/(npts + half)) 10 continue p1 = one p2 = zero aj = zero Do j = 1, npts p3 = p2 p2 = p1 aj = aj + one p1 = ((two*aj - one)*t*p2 - (aj - one)*p3)/aj End Do pp = npts*(t*p1 - p2)/(t*t - one) t1 = t t = t1 - p1/pp If (abs(t - t1) > eps ) goto 10 x(i) = - t x(npts + 1 - i) = t w(i) = two/((one - t*t)*pp*pp) w(npts + 1 - i) = w(i) End Do ! rescale grid points select case(job) ! scale to (a, b) uniformly case (0) Do i = 1, npts x(i) = x(i)*(b - a)/two + (b + a)/two w(i) = w(i)*(b - a)/two End Do ! scale to (0, b) with 50% points inside (0, ab/(a + b)) case(1) Do i = 1, npts xi = x(i) x(i) = a*b*(one + xi)/(b + a - (b - a)*xi) w(i) = w(i)*two*a*b*b/((b + a -(b-a)*xi)*(b + a - (b-a)*xi)) End Do ! scale to (a, inf) with 50% inside (a, b + 2a) case(2) Do i = 1, npts xi = x(i) x(i) = (b*xi + b + a + a)/(one - xi) w(i) = w(i)*two*(a + b)/((one - xi)*(one - xi)) End Do End select Return End