Program 0 : defvec, d1, dn, spd

      program prog0 
      implicit none

      real cubic,slope,rms,d1,dn
      external cubic,slope,rms  
      real f(10),x(10),h(10),fslp(10),sslp(10),sslp1,sslpn
      real a(10),c(10),d(10)
      integer i

# define vector of regularly spaced coordinates, x,
# compute values of f and slope of f at these coordinates
# compute spacing of coordinates
      print *,'The cubic f=x**3+15.0*x**2+60.0*x+6.0:'
      call defvec(x,10,2.0,3.0)
      do i=1,10
         f(i)=cubic(x(i))
         fslp(i)=slope(x(i))
         print *,'f(x(',i,' ))=',f(i),'   x(',i,' )=',x(i)
         if (i.ne.1) h(i-1)=x(i)-x(i-1)
      enddo

# compute the slope at the first point
      sslp1=d1(f,2.0,10)
      print *,''
      print *,'The slope at the first point'
      print *,'  computed by d1:',sslp1
      print *,'  computed analytically:',fslp(1)
      print *,''

# compute the slope at the last point
      sslpn=dn(f,2.0,10)
      print *,'The slope at the last point'
      print *,'  computed by dn:',sslpn
      print *,'  computed analytically:',fslp(10)
      print *,''

# compute the slope of the spline passing through the points of f(10)
# with spd and its rms error compared to the real slope of f
      call spd(sslp,f,10,h,0,sslp1,0,sslpn,a,c,d)
      print *,'For the ten slopes calculated,'
      print *,'spd has an rms error of:',rms(sslp,fslp,10)
      
      stop
      end
   
      real function cubic(x)
      real x
      cubic=x**3+15.0*x**2+60.0*x+6.0
      return
      end
         
      real function slope(x)
      real x
      slope=3*x**2+30*x+60
      return
      end

      real function rms(a,b,n)
      real a(n),b(n),sum
      integer i,n
      sum=0
      do i=1,n
         sum=sum+(a(i)-b(i))**2
      enddo
      rms=sqrt(sum/n)
      return
      end