PROGRAM TP2
  IMPLICIT NONE

  REAL, DIMENSION(3,3) :: MatxC, ExpMatxC, MyM
  REAL, DIMENSION(3)   :: VectX0, VectX, VectXF
  REAL :: dt
  INTEGER :: k, Kf, n

  MatxC(1,1:3) = (/ -1.0,  0.0,  1.0 /)
  MatxC(2,1:3) = (/  1.0, -1.0,  0.0 /)
  MatxC(3,1:3) = (/  0.0,  1.0, -1.0 /)

  MyM = MatxC

  WRITE(6, '( 70("-") )' )  
  WRITE(6,*) " Question  1"
  WRITE(6, '( 70("-") )' ) 

  Do k = 1, 3

     MyM   = MATMUL( MatxC, MyM)


     WRITE(6, '( 70("*") )' )  
     WRITE(6,'( A, I1)') " C**", k+1
     WRITE(6, '( 3(E16.3) )' )  MyM(1,1),  MyM(1,2),  MyM(1,3)
     WRITE(6, '( 3(E16.3) )' )  MyM(2,1),  MyM(2,2),  MyM(2,3)
     WRITE(6, '( 3(E16.3) )' )  MyM(3,1),  MyM(3,2),  MyM(3,3)
     WRITE(6, '( 70("*") )' )  


  END Do

  k= 2
  n = 1
  WRITE(6, '( A, I2, I2, A, 3(ES16.3) )' ) "MyM(",k,n,")", &
       &  MyM(1,1),  MyM(1,2),  MyM(1,3)

  WRITE(6, '( 70("-") )' )  
  WRITE(6,*) " Next question "
  WRITE(6, '( 70("-") )' ) 

  VectX0 = (/ 0.0 , 1.0, 0.0 /)

  VectX =  VectX0
  Kf    = 1
  MyM   = MatxC

  Do k = 1, 4

     Kf = Kf*k

     VectX = VectX + (3**k)*MATMUL( MyM, VectX0)/Kf
     MyM   = MATMUL( MatxC, MyM)


     WRITE(6, '( 70("*") )' ) 
     WRITE(6,'( A, I1)') "Approximate  [Exp(3C)]X0  for k=", k
     WRITE(6, '( 3(E16.3) )' )  VectX(1), VectX(2), VectX(3) 
     WRITE(6, '( 70("*") )' )  
  END Do

  WRITE(6, '( 70("-") )' )  
  WRITE(6,*) " Next question "
  WRITE(6, '( 70("-") )' ) 

  VectX0 = (/ 0.0 , 1.0, 0.0 /)

  VectX =  VectX0
  Kf    = 1

  DO k = 1, 10,1
     WRITE(6, '( 70("*") )' ) 
     WRITE(6,'( A, I4)') "Case  k=", k
     Dt = 3.0/k
     VectX =  VectX0
     Do n = 1, k
        VectX = VectX + dt*MATMUL(MatxC,VectX)
        IF( k == 3 .OR. n==k) THEN
           WRITE(6, '( A, 3(E16.3) )' ) " Xk = ", VectX(1), VectX(2), VectX(3) 
        END IF
     END Do
     WRITE(6, '( 70("*") )' ) 
  END DO

  WRITE(6, '( 70("-") )' )  
  WRITE(6,*) " Next question "
  WRITE(6, '( 70("-") )' ) 

  kf = 10
  DO
     kf = kf*2
     k  = 10
     DO
        k = k*2
        IF( k < kf ) CYCLE

        WRITE(6, '( 70("*") )' ) 
        WRITE(6,'( A, I6)') "Case  k=", k
        Dt = REAL(kf)/REAL(k)
        VectX =  VectX0
        Do n = 1, k
           VectX = VectX + dt*MATMUL(MatxC,VectX)
           IF( k == 3 .OR. n==k) THEN
              WRITE(6, '( A, 3(E16.6) )' ) " Xk = ", VectX(1), VectX(2), VectX(3) 
           END IF
        END Do
        WRITE(6, '( 70("*") )' ) 
        IF( k >= 10000 ) EXIT
     END DO
        IF( kf >= 10000 ) EXIT
  END DO

END PROGRAM TP2
