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 5.2
c
c     Example of Schur factorization 
c
c
c     file: ex1s52.f
c
      parameter (n=3)
      dimension a(n,n),u(n,n),t(n,n),v(n,n)
      data (a(1,j),j=1,n) /361.,123.,-180./
      data (a(2,j),j=1,n) /148.,414.,-240./
      data (a(3,j),j=1,n) /-92.,169.,65./
      data (u(1,j),j=1,n) /0.36,0.48,0.80/
      data (u(2,j),j=1,n) /0.48,0.64,-0.60/
      data (u(3,j),j=1,n) /0.80,-0.60,0.0/
c 
      print *
      print *,' Schur factorization example'
      print *,' Section 5.2, Kincaid-Cheney'
      print *
c
      print *,' Matrix A'
      call prtmtx(n,a)
c
      print *,' Matrix U'
      call prtmtx(n,u)
c
      call mult(n,u,u,v)
      print *,' Matrix (U*)U'
      call prtmtx(n,v)
c
      call mult(n,u,a,t)
      print *,' Matrix UA'
      call prtmtx(n,t)
c 
      call mult(n,t,u,v)
      print *,' Matrix UA(U*)'
      call prtmtx(n,v)
c
      stop
      end 
c
      subroutine prtmtx(n,a)
c          
c     print the matrix
c
      dimension a(n,n)
c
      do 2 i=1,n
         print 3,(a(i,j),j=1,n)
 2    continue
      print *
c
      return
 3    format (2x,3(e13.6,2x))
      end
c
      subroutine mult(n,a,b,c)
c
c     compute matrix product c=ab
c
      dimension a(n,n),b(n,n),c(n,n)
c
      do 3 i=1,n
         do 3 j=1,n
            x = 0.0
            do 2 k=1,n
               x = x + a(i,k)*b(k,j) 
 2          continue
            c(i,j)=x
 3    continue
c
      return
      end 
