Advertisement
Guest User

Untitled

a guest
Apr 1st, 2015
247
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. !
  2. !         this routine is a supplement to the journal article,
  3. !      Algorithm 726: ORTHPOL - A Package of Routines for Generating
  4. !        Orthogonal Polynomials and Gauss-Type Quadrature Rules.
  5. !                         Walter Gautschi,
  6. !      ACM Transactions on Mathematical Software, 20, 21-62(1994)
  7. !
  8. !            A footnote in Gautschi's article reveals that
  9. !            this particular routine came from Gene Golub.
  10. !
  11. ! Given  n  and a measure  dlambda, this routine generates the n-point
  12. ! Gaussian quadrature formula
  13. !
  14. !     integral over supp(dlambda) of f(x)dlambda(x)
  15. !
  16. !        = sum from k=1 to k=n of w(k)f(x(k)) + R(n;f).
  17. !
  18. ! The nodes are returned as  zero(k)=x(k) and the weights as
  19. ! weight(k)=w(k), k=1,2,...,n. The user has to supply the recursion
  20. ! coefficients  alpha(k), beta(k), k=0,1,2,...,n-1, for the measure
  21. ! dlambda. The routine computes the nodes as eigenvalues, and the
  22. ! weights in term of the first component of the respective normalized
  23. ! eigenvectors of the n-th order Jacobi matrix associated with  dlambda.
  24. ! It uses a translation and adaptation of the algol procedure  imtql2,
  25. ! Numer. Math. 12, 1968, 377-383, by Martin and Wilkinson, as modified
  26. ! by Dubrulle, Numer. Math. 15, 1970, 450. See also Handbook for
  27. ! Autom. Comput., vol. 2 - Linear Algebra, pp.241-248, and the eispack
  28. ! routine  imtql2.
  29. !
  30. !        Input:  n - - the number of points in the Gaussian quadrature
  31. !                      formula; type integer
  32. !                alpha,beta - - arrays of dimension  n  to be filled
  33. !                      with the values of  alpha(k-1), beta(k-1), k=1,2,
  34. !                      ...,n
  35. !                eps - the relative accuracy desired in the nodes
  36. !                      and weights
  37. !
  38. !        Output: zero- array of dimension  n  containing the Gaussian
  39. !                      nodes (in increasing order)  zero(k)=x(k), k=1,2,
  40. !                      ...,n
  41. !                weight - array of dimension  n  containing the
  42. !                      Gaussian weights  weight(k)=w(k), k=1,2,...,n
  43. !                ierr- an error flag equal to  0  on normal return,
  44. !                      equal to  i  if the QR algorithm does not
  45. !                      converge within 30 iterations on evaluating the
  46. !                      i-th eigenvalue, equal to  -1  if  n  is not in
  47. !                      range, and equal to  -2  if one of the beta's is
  48. !                      negative.
  49. !
  50. ! The array  wrk  is needed for working space.
  51. !
  52.       subroutine gauss(n,alpha,beta,eps,zero,weight,ierr,wrk)
  53.       implicit none
  54.       real*8 alpha(n),beta(n),zero(n),weight(n),wrk(n)
  55.       real*8 dg, dr, dp, ds, dc, db, df
  56.       integer*8 ierr, i, ii, j, k, l, m, mml, n
  57.       if(n.lt.1) then
  58.         ierr=-1
  59.         return
  60.       end if
  61. !    
  62.       ierr=0
  63.       zero(1)=alpha(1)
  64.       if(beta(1).lt.0.0D+00) then
  65.         ierr=-2
  66.         return
  67.       end if
  68.       weight(1)=beta(1)
  69.       if (n.eq.1) return
  70. !    
  71.       weight(1)=1.0D+00
  72.       wrk(n)=0.0D+00
  73.       do 100 k=2,n
  74.         zero(k)=alpha(k)
  75.         if(beta(k).lt.0.0D+00) then
  76.           ierr=-2
  77.           return
  78.         end if
  79.         wrk(k-1)=sqrt(beta(k))
  80.         weight(k)=0.0D+00
  81.   100 continue
  82. !    
  83.       do 240 l=1,n
  84.         j=0
  85. !
  86. ! Look for a small subdiagonal element.
  87. !
  88.   105   do 110 m=l,n
  89.           if(m.eq.n) go to 120
  90.           if(abs(wrk(m)).le.eps*(abs(zero(m))+abs(zero(m+1)))) go to 120
  91.   110   continue
  92.   120   dp=zero(l)
  93.         if(m.eq.l) go to 240
  94.         if(j.eq.30) go to 400
  95.         j=j+1
  96. !
  97. ! Form shift.
  98. !      
  99.         dg=(zero(l+1)-dp)/(2.0D+00*wrk(l))
  100.         dr=sqrt(dg*dg+1.0D+00)
  101.         dg=zero(m)-dp+wrk(l)/(dg+sign(dr,dg))
  102.         ds=1.0D+00
  103.         dc=1.0D+00
  104.         dp=0.0D+00
  105.         mml=m-l
  106.  
  107. !
  108. ! For i=m-1 step -1 until l do ...
  109. !      
  110.         do 200 ii=1,mml
  111.           i=m-ii
  112.           df=ds*wrk(i)
  113.           db=dc*wrk(i)
  114.           if(abs(df).lt.abs(dg)) go to 150
  115.           dc=dg/df
  116.           dr=sqrt(dc*dc+1.0D+00)
  117.           wrk(i+1)=df*dr
  118.           ds=1.0D+00/dr
  119.           dc=dc*ds
  120.           go to 160
  121.   150     ds=df/dg
  122.           dr=sqrt(ds*ds+1.0D+00)
  123.           wrk(i+1)=dg*dr
  124.           dc=1.0D+00/dr
  125.           ds=ds*dc
  126.   160     dg=zero(i+1)-dp
  127.           dr=(zero(i)-dg)*ds+2.0D+00*dc*db
  128.           dp=ds*dr
  129.           zero(i+1)=dg+dp
  130.           dg=dc*dr-db
  131. !
  132. ! Form first component of vector.
  133. !        
  134.           df=weight(i+1)
  135.           weight(i+1)=ds*weight(i)+dc*df
  136.           weight(i)=dc*weight(i)-ds*df
  137.   200   continue
  138.         zero(l)=zero(l)-dp
  139.         wrk(l)=dg
  140.         wrk(m)=0.0D+00
  141.         go to 105
  142.   240 continue
  143. !
  144. ! Order eigenvalues and eigenvectors.
  145. !    
  146.       do 300 ii=2,n
  147.         i=ii-1
  148.         k=i
  149.         dp=zero(i)
  150.         do 260 j=ii,n
  151.           if(zero(j).ge.dp) go to 260
  152.           k=j
  153.           dp=zero(j)
  154.   260   continue
  155.         if(k.eq.i) go to 300
  156.         zero(k)=zero(i)
  157.         zero(i)=dp
  158.         dp=weight(i)
  159.         weight(i)=weight(k)
  160.         weight(k)=dp
  161.  
  162.   300 continue
  163.       do 310 k=1,n
  164.         weight(k)=beta(1)*weight(k)*weight(k)
  165.   310 continue
  166.       return
  167. !
  168. ! Set error - no convergence to an eigenvalue after 30 iterations.
  169. !
  170.   400 ierr=l
  171.       return
  172.       end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement