      program zero2
c      implicit double precision (a-h,o-z)
      double precision a,b,r,re,re1,rr,func1,func
      real j
      dimension xray(101),yray(101)
      logical flag
      external func1,func,dfunc
      n=101
      x=-1.
      do i=1,n
        xray(i)=x
        yray(i)=func(dble(x))
        x=x+2.e-2
      end do
      CALL metafl('cons') 
      CALL DISINI ()
      CALL graf(-1.0,1.0,-1.0,0.25,-1.0,1.0,-1.0,0.2)
      call color('yellow')
      CALL name('x premenna','X')
      call name('y premenna','Y')
      call HTITLE(10)
      CALL TITLIN('hladanie',1) 
      call color('red')
      call thkcrv(5)
      call curve(xray,yray,n)
      call color('green')
      ixp=nxposn(-1.0)
      ixk=nxposn(1.0)
      iy=nyposn(0.0)
      call line(ixp,iy,ixk,iy)
      call hsymbl(20)
c      call disfin ()
c      open(1,file='c:/modelovanie/Output/zero.out')
      a=-1.0d0
      b=1.0d0
      re=1.d-1
      re1=1.d-5
      j=1.0
      do i=1,1
         call dzero(func,a,b,re,flag,j)
          call newton(func,dfunc,a,re1,flag,j)
         if (flag) then
             rr=func(a)
             ix=nxposn(real(a))
             iy=nyposn(real(rr))
             call symbol(21,ix,iy)
         end if
         a=a+b
      end do
      call disfin ()
c      write(1,*) a,rr,iflag
c      close(1)
      end
c
      function func(x)
      implicit double precision (a-h,o-z)
      func=x*x*x+0.1d0
      return
      end     
      function dfunc(x)
      implicit double precision (a-h,o-z)
      dfunc=3.0d0*x*x
      return
      end
      function func1(x)
      implicit double precision (a-h,o-z)
      func1=dsin(50.d0/(x+2.d0))
      return
      end     
c
      subroutine dzero(func,a,b,eer,lab,j)
      implicit double precision (a-h,o-z)
      real j
      logical lab
      character*1 si
      external func
      call color('blue')
      lab=.false. 
      fa=func(a)
      fb=func(b)
      sab=fa*fb
      if (sab.GT.0.d0) return
10    continue
      diff=dabs(a-b)
      jx=2600
      jy=100+int(j)*100
      call number(j,-1,jx-100,jy)
      call number(real(diff),5,jx,jy)
      if (diff.LT.eer) then
         a=b
         lab=.true.
         call color('green')
         return
      end if
      c=0.5d0*(a+b)
      fc=func(c)
      ic=nxposn(real(c))
      ifc=nyposn(real(fc))
      call symbol(15,ic,ifc)
c      call intcha(i,1,si)
      if (j.LT.5) call number(j,-1,ic,ifc+30)
      j=j+1.0
      sac=fa*fc
      if (sac.GT.0.d0) then
         a=c
      else
         b=c
      end if
      go to 10
      end
c
      subroutine dzero1(func,a,step,eer,lab)
      implicit double precision (a-h,o-z)
      logical lab
      external func
      lab=.false. 
 20   fa=func(a)
      b=a+step
      fb=func(b)
      sab=fa*fb
      if (sab.GT.0.d0) then
         a=b
         go to 20
      else
 10      continue
         dif=dabs(a-b)
         if (dif.LT.eer) then
            a=b
            lab=.true.
            return
         end if
         c=0.5d0*(a+b)
         fc=func(c)
         sac=fa*fc
         if (sac.GT.0.d0) then
             a=c
         else
             b=c
         end if
         go to 10
      end if
      end
c
      subroutine newton(func,dfunc,x,re,flag,j)
      implicit double precision (a-h,o-z)
      external func,dfunc
      real j
      logical flag
      flag=.false.
 10   x1=x-func(x)/dfunc(x)
      diff=dabs(x1-x)
      jx=2600
      jy=100+int(j)*100
      call number(j,-1,jx-100,jy)
      call number(real(diff),5,jx,jy)
      ix=nxposn(real(x1))
      iy=nyposn(real(func(x1)))
      ix0=nxposn(real(x))
      iy0=nyposn(real(func(x)))
      call symbol(15,ix,iy)
      call line(ix,iy,ix0,iy0)
      x=x1
      if (j.LT.5) call number(j,-1,ix,iy+30)
      j=j+1.0
      if (j.GT.20) return
      if (diff.LT.re) then
         flag=.true.
         return
      end if
      go to 10
      return
      end            
