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 9.1
c
c     Example of solving a P.D.E using Explicit Method
c
c
c     file: exs91.f
c
      parameter (n=10, np1=11)
      dimension w(0:np1),v(0:np1),error(0:np1) 
      real a,b
      data M,hk/200,0.005125/  
c
      print *
      print *,' Explicit method example'
      print *,' Section 9.1, Kincaid-Cheney'
      print *
      print 7
c
      pi = 4.0*atan(1.0)
      h = 1.0/real(np1)
      s = hk/h**2 
c
      do 2 i=0,np1
         w(i) = sin(pi*real(i)*h) 
 2    continue
c
      t = 0.0
      print 8,0,t,w(0),w(1),w(10),w(11)
      print *
c
      do 6 j=1,M
         v(0) = a(real(j)*hk)
         v(np1) = b(real(j)*hk)
         do 3 i = 1,n
            v(i) = s*w(i-1) + (1.0 - 2.0*s)*w(i) + s*w(i+1) 
 3       continue   
         t = real(j)*hk
         if (0 .eq. mod(j,10)) then 
            print 8,j,t,v(0),v(1),v(10),v(11)
            print *
         endif
c
         do 4 i=1,n
            w(i) = v(i) 
 4       continue
c
         do 5 i=0,np1
            x = real(i)*h
            error(i) = abs(sin(pi*x)/exp(pi*pi*t) - v(i))
 5       continue
c   
         if (0 .eq. mod(j,10)) then
            print *,' norm of error =', vnorm(n,error)
            print *
         endif
 6    continue
c   
 7    format (3x,'j',8x,'t',13x,'v(0)',11x,'v(1)',6x,'.....',
     +        5x,'v(10)',10x,'v(11)')
 8    format (1x,i3,2x,3(e13.6,2x),5x,2(e13.6,2x))
      stop
      end
c
      real function a(t)
      a = 0.0
      return
      end
c
      real function b(t)
      b = 0.0
      return
      end
c
      function vnorm(n,v)
      dimension v(0:n)
c
c     computes infinity norm of n component vector v
c
      real max
c
      temp = 0.0
      do 2 i=0,n
         temp = max(temp,abs(v(i)))
 2    continue
      vnorm = temp
c
      return
      end
