c  21. $BM[2rK!$G5a$a$kG.EAF3J}Dx<0$N(B3$B<!85%0%i%U(B
c     $B?9@n(B $BLwBg(B , 22980138
c
      program ex21
c
      implicit none
      integer :: tp,tp1,tp2,xp,k1,k2
      real :: r1,r2
c
      r1 =0.25
      r2 =0.5
      k1 =16
      k2 =8
      tp =51
      tp1=(tp-1)*k1+1
      tp2=(tp-1)*k2+1
      xp =21

      call youkaihou21(r1,k1,tp1,xp,10)

      call youkaihou21(r2,k2,tp2,xp,11)

      stop 
      end
c
c-----$BM[2rK!$N%5%V%k!<%A%s(B
      subroutine youkaihou21(r,k,tp,xp,shutsuryoku)
      implicit none
      integer :: i,j,shutsuryoku,tp,xp,k
      real :: r,u(xp,tp),x,t      

      do i=1,xp
         x=0.05*float(i-1)
         if (i <= 11) then
           u(i,1)=2.0*x
         else
           u(i,1)=2.0*(1.0-x)
         endif
      enddo
      do j=1,tp
         u( 1,j)=0.0
         u(21,j)=0.0
      enddo
      
      do j=1,tp-1     
         do i=2,xp-1     
            u(i,j+1)=r*(u(i+1,j)+u(i-1,j))+(1.0-2.0*r)*u(i,j)
         enddo
      enddo
      do j=1,tp,k
         do i=1,xp
            t=(0.01/float(k))*float(j-1)
            x=0.05*float(i-1)
            write(shutsuryoku,*) t,x,u(i,j)
         enddo
         write(shutsuryoku,*) ''
      enddo
                  
      return
      end      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
