      program legval
      implicit real*8 (a-h,o-z)
      parameter(n=1024)
      dimension h(n,n),v1(n),v2(n)
      do 20 i=1,n
      do 10 j=1,n
        if(i.eq.j) then
          h(i,j)=i-1.0d0/i
c           h(i,j)=i
        else
           h(i,j)=1.0d0/(i-j)**2
c           h(i,j)=0
        end if
 10   continue
 20   continue
      s=0
      do 30 i=1,n
        t=sqrt(dble(i))
        s=s+t**2
        v1(i)=t
 30   continue
      f=1/sqrt(s)
      do 40 i=1,n
        v1(i)=f*v1(i)
 40   continue
      k=0
      e0=0
 50   s=0
      k=k+1
      do 70 i=1,n
        t=0
        do 60 j=1,n
          t=t+h(j,i)*v1(j)
 60     continue
        v2(i)=t
        s=s+t**2
 70   continue
      e=sqrt(s)
c      write(6,800) k,e
c800  format(' ',i10,f12.6)
      if(abs(e-e0).lt.1.0d-4) go to 90
      e0=e
      f=1/e
      do 80 i=1,n
        v1(i)=f*v2(i)
 80   continue
      go to 50
 90   write(6,900) e,k
 900  format(' Largest eigen value =',f11.5,',  iteration=',i10)
      end
