c
c     Second Edition
c     Numerical Analysis:
c     The Mathematics of Scientific Computing
c     D.R. Kincaid & E.W. Cheney
c     Brooks/Cole Publ., 1996
c     ISBN 0-534-33892-5
c     COPYRIGHT (c) 1996
c
c     Section 4.6
c
c     Example of Jacobi's method
c
c
c     file: jacobi.f
c
      parameter (n=3)
      dimension a(n,n),b(n),u(n),x(n)
      data (a(1,j),j=1,n) /1.0,0.5,0.3333/
      data (a(2,j),j=1,n) /0.3333,1.0,0.5/
      data (a(3,j),j=1,n) /0.5,0.3333,1.0/
      data (b(i),i=1,n) /.6111,.6111,.6111/
      data (x(i),i=1,n) /0.0,0.0,0.0/
c 
      print *
      print *,' Jacobi method example'
      print *,' Section 4.6, Kincaid-Cheney'
      print *
c
      do 7 k=1,100
         do 3 i=1,n
            d = 1.0/a(i,i)
            b(i) = d*b(i)
            do 2 j=1,n
               a(i,j) = d*a(i,j)
 2          continue
 3       continue
         do 5 i=1,n
            sum = 0.0
            do 4 j=1,n      
               if (j .eq. i) goto 4
               sum = sum + a(i,j)*x(j)
 4          continue
            u(i) = b(i) - sum
 5       continue
         do 6 i=1,n
            x(i) = u(i)
 6       continue
         if (0 .eq. mod(k,10)) then
            print *,' At iteration',k
            print 8,x
            print *
         endif
 7    continue
c
 8    format (3x,'x is:',3(e13.6,2x))
      stop
      end
