program polynom_Newton_Horner
implicit none

!=========================================================================
! Nullstellennaeherung mit Newtonverfahren
integer :: i,n
real, dimension(:), allocatable :: a
real :: x0,x1,p,q

open(100, "w08_1.dat")
read(100,*) n

allocate(a(0:n))
write(*,*) n,a
do i=0,n
   read(100,*) a(i)
   end do
close(100)
write(*,*) n,a
write(*,"(A10)",advance="no") "x0="
read(*,*) x0

do 
   p=a(n)
   q=a(n)
   do i=n-1,1,-1
      p=p*x0+a(i)
      q=q*x0+ p 
      end do
   p=p*x0+a(0)
   x1=x0-p/q
   write(*,*) x0,p,q,x1
   if (abs(x0-x1)<1e-8) exit
   x0=x1
   end do

endprogram polynom_Newton_Horner
