% FIGURE 5.8.1
%                              BREAK POINTS ARE XPTS(K), K=1,N+1
%                              UNKNOWNS ARE A(I), I=1,M
      global N XPTS M A TKP1 LOCATE OMEGA
      LOCATE = @LOCATE581;
      OMEGA = @OMEGA581;
%                              N = NUMBER OF SUBINTERVALS
      N = 10;
%                              M = NUMBER OF UNKNOWNS
      M = 2*N+1;
%                              NSTEP = NUMBER OF TIME STEPS
      NSTEP = 200;
      for K=1:N+1                                                        
         XPTS(K) = (K-1)/N;
      end
%                              INITIAL VALUES SET        
      for I=1:M                                                       
         [HORS,K] = LOCATE581(I);                                          
         if (HORS == 'H')
            A(I) =  exp(-XPTS(K+1));
         else
            A(I) = -exp(-XPTS(K+1));
         end
      end 
      DT = 1.0/NSTEP;
      for KT=1:NSTEP
         TKP1 = KT*DT;
%                              BACKWARD DIFFERENCE METHOD REQUIRES
%                              SOLUTION OF (BMAT + DT*AMAT)*a(k+1) 
%                              = DT*b + BMAT*a(k) EACH TIME STEP
         L = 3;
         for K=1:M                                                    
            F(K) = DT*GAUSS(@FUNF581,K,0);
            for I=max(K-L,1):min(K+L,M)
               AMATKI = GAUSS(@FUNA581,K,I) + ...
                 exp(0.5*TKP1)*PHI(K,0,1.0)*PHI(I,0,1.0);
               BMATKI = GAUSS(@FUNB581,K,I);
               F(K) = F(K) + BMATKI*A(I);
               AMAT(K,I-K+L+1) = BMATKI + DT*AMATKI;
            end
         end
%                              SOLVE LINEAR SYSTEM USING BAND SOLVER    
         A = LBAND(AMAT,F,M,L);
%                              CALCULATE MAXIMUM ERROR                  
         ERMAX = 0.0;                                                   
         for J=0:100                                                  
            X = J/100.0;
            ERR = abs(USOL(0,X) - exp(TKP1-X));
            ERMAX = max(ERMAX,ERR);                                      
         end
         TKP1
         ERMAX
      end
