ccccccccccccccccccccccccc     Program 8.1     cccccccccccccccccccccccccc
c
cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc
c                                                                      c
c Please Note:                                                         c
c                                                                      c
c (1) This computer program is part of the book, "An Introduction to   c
c     Computational Physics," written by Tao Pang and published and    c
c     copyrighted by Cambridge University Press in 1997.               c
c                                                                      c
c (2) No warranties, express or implied, are made for this program.    c
c                                                                      c
cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc
c
      PROGRAM GALERKIN
C
C This program solves the one-dimensional Poisson equation
C with the Galerkin method as described in the text.
C
      PARAMETER (N = 99)
      DIMENSION B(N),A(N),Y(N),W(N),U(N)
C
      PI  =  4.0*ATAN(1.0)
      XL  =  1.0
      H   =  XL/(N+1)
      D   =  2.0/H
      E   = -1.0/H
      B0  =  PI/H
      B1  =  1.0/H
C
C Find the elements in L and U
C
      W(1) =  D
      U(1) =  E/D
      DO      100 I = 2, N
        W(I) = D-E*U(I-1)
        U(I) = E/W(I)
  100 CONTINUE
C
C Assign the array B
C
      DO      200 I = 1, N
        XIM  = H*(I-1)
        XI   = H*I
        XIP  = H*(I+1)
        B(I) = B0*COS(PI*XD)*(XIM+XIP-2.0*XI)
     *        +B1*(2.0*SIN(PI*XI)-SIN(PI*XIM)-SIN(PI*XIP))
  200 CONTINUE
C
C Find the solution
C
      Y(1) = B(1)/W(1)
      DO     300 I = 2, N
        Y(I) = (B(I)-E*Y(I-1))/W(I)
  300 CONTINUE
C
      A(N) = Y(N)
      DO     400 I = N-1,1,-1
        A(I) = Y(I)-U(I)*A(I+1)
  400 CONTINUE
C
      WRITE (6, 999) (I*H, A(I), I = 1, N)
      STOP
  999 FORMAT(2F16.8)
      END
