      program integ
c derivovanie pomocou chebyshev aproximacie
      dimension xray(101),yray(101),yray1(101),yray2(101)
      dimension c(40),cder(40)
      external funct
      x=-5.0
      a=-5.0
      write(*,*) 'zadaj hornu hranicu integrovania'
      read(*,*) b
      if ((b.LE.a).OR.(b.GE.5.0)) b=5.0
      write(*,*) 'zadaj pocet intervalov'
      read(*,*) m
      do i=1,101
         xray(i)=x
         yray(i)=funct(x)
         x=x+0.1
      end do
c
      call metafl('cons')
      CALL SETPAG('DA4L')
      CALL DISINI
      CALL TITLIN(CTIT,1)
      CALL AXSLEN(2500,700)
      CALL AXSPOS(200,800)
      CALL GRAF(-5.,5.,-5.,2.,0.0,1.2,0.0,2.e-1)
           NX=NXPOSN(-3.)
           NY=NYPOSN(1.3)
      CALL MESSAG('Obdlznik',NX,NY)      
      CALL COLOR('yellow')
      CALL curve(xray,yray,101)
      call color('red')
      step=(b-a)/(real(m)-0.0)
      xpos=a
      ain=0.0
      do i=1,m
         x1=xpos
         y1=0.0
         x2=xpos
         y2=funct(xpos)
         ain=ain+y2
         call rline(x1,y1,x2,y2)
         y1=funct(xpos)
         x2=xpos+step
         call rline(x1,y1,x2,y2)
         x1=x2
         y2=0.0
         call rline(x1,y1,x2,y2)
         xpos=xpos+step
      end do
      ain=step*ain
       NX=NXPOSN(-1.)
       call number(ain,3,nx,ny)
c      CALL COLOR('yellow')
c      CALL curve(xray,yray,101)
      CALL COLOR('white')
      CALL ENDGRF
      CALL AXSLEN(2500,700)
      CALL AXSPOS(200,1800)
      CALL GRAF(-5.,5.,-5.,2.,0.,1.2,0.,0.2)
           NX=NXPOSN(-3.)
           NY=NYPOSN(1.3)
      CALL MESSAG('Lichobeznik',NX,NY)
      CALL COLOR('yellow')
      CALL curve(xray,yray,101)
      call color('red')
      step=(b-a)/(real(m)-0.0)
      xpos=a
      ain=0.0
      do i=1,m
         x1=xpos
         y1=0.0
         x2=xpos
         y2=funct(xpos)
         ain=ain+y2
         call rline(x1,y1,x2,y2)
         x1=x2
         y1=y2
         x2=x2+step
         y2=funct(x2)
         ain=ain+y2
         call rline(x1,y1,x2,y2)
         x1=x2
         y1=y2
         y2=0.0
         call rline(x1,y1,x2,y2)
         xpos=xpos+step
      end do
      ain=0.5*step*ain
       NX=NXPOSN(-1.)
       call number(ain,3,nx,ny)
      call color('white')
      NX=NXPOSN(-3.)
      NY=NYPOSN(-0.2)
      CALL MESSAG('presne',NX,NY)
      ain=(1.0/0.25)*(cos(0.25*b+5.0)-cos(0.25*a+5.0))
      call color('red')
      NX=NXPOSN(-1.)
       call number(ain,3,nx,ny) 
      CALL DISFIN
      END 
c
      function funct(x)
c        a=0.1*(2.*rand()+1.)
        funct=-1.0*sin(0.25*x+5.0)
c        funct=0.01*x*x*x+a
      return
      end 
         
      