      subroutine trh(n,a,w,alpha)
c     transformacja Householdera: Ha=alpha*e1
c     DANE: n-wymiar, a-wektor
c     WYNIKI: w -wektor, alpha 
c     H=I-ww^T

      implicit none
      real*8 a,w,alpha,lambda,nor,nor2,O,E
      integer n,k
      dimension a(n),w(n)

      O=real(0)
      E=real(1)
      nor2=O
      do 1,k=1,n,1
      nor2=nor2+a(k)*a(k)
    1 continue
      nor=sqrt(nor2)
      if(a(1).lt.O)then
      alpha=nor
      else
      alpha=-nor
      endif
      lambda=sqrt(nor2-alpha*a(1))
      w(1)=(a(1)-alpha)/lambda
      do 3,k=2,n,1
      w(k)=a(k)/lambda
    3 continue
      return
      end

