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 3.5
c
c     Example of Bairstow's method
c     applied to a polynomial of degree n
c
c   
c     file: ex7s35.f
c
      parameter (n=4,m=10)
      double precision a(0:n),b(0:n),c(0:n),u,v,xj
      data (a(j),j=0,n)/-2.0,-5.0,7.0,-4.0,1.0/
      data u/3.0/
      data v/-4.0/
c
      print *
      print *,' Bairstow''s Method example'
      print *,' Section 3.5, Kincaid-Cheney'
      print *
      print 10
c
      b(n) = a(n)
      c(n) = 0.0
      c(n-1) = a(n)
c
      do 3 j=1,M
         b(n-1) = a(n-1) + u*b(n) 
c
         do 2 k=n-2,0,-1
            b(k) = a(k) + u*b(k+1) + v*b(k+2)
            c(k) = b(k+1) + u*c(k+1) + v*c(k+2)
 2       continue  
c
         xj = c(0)*c(2) - c(1)**2 
         u = u+(c(1)*b(1) - c(2)*b(0))/xj
         v = v + (c(1)*b(0) - c(0)*b(1))/xj
         print 11,j,u,v,b(0),b(1)
 3    continue
c
 10   format(1x,'n',12x,'u',23x,'v',17x,'b(0)',11x,'b(1)')
 11   format(i2,1x,2(d22.15,2x),2(e13.6,2x))
      stop
      end
