

_I_n_t_e_r_p_o_l_a_t_i_n_g _S_p_l_i_n_e_s

     splinefun(x, y, method = "fmm")
     spline(x, y, n = 3*length(x), method = "fmm",
            xmin = min(x), xmax = max(x))

_A_r_g_u_m_e_n_t_s:

     x,y: vectors giving the coordinates of the points to be
          interpolated.  Alternatively a single plotting
          structure can be specified.

  method: specifies the type of spline to be used.  Possible
          values are `"fmm"', `"natural"' and `"periodic"'.

       n: interpolation takes place at `n' equally spaced
          points spanning the interval [`xmin', `xmax'].

    xmin: left-hand endpoint of the interpolation interval.

    xmax: right-hand endpoint of the interpolation interval.

_D_e_s_c_r_i_p_t_i_o_n:

     `spline' performs cubic spline interpolation of the
     given data points.  It returns a list containing com-
     ponents `x' and `y' which give the ordinates where
     interpolation took place and the interpolated values.

     `splinefun' returns a function which will perform cubic
     spline interpolation of the given data points.  This is
     often more useful than `spline'.

     If `method="fmm"', the spline used is that of Forsythe,
     Malcolm and Moler (an exact cubic is fitted through the
     four points at each end of the data, and this is used
     to determine the end conditions).  Natural splines are
     used when `method="natural"', and periodic splines when
     `method="periodic"'.

_R_e_f_e_r_e_n_c_e_s:

     Forsythe, G. E., M. A. Malcolm and C. B. Moler (1977).
     Computer Methods for Mathematical Computations.

_S_e_e _A_l_s_o:

     `approx' and `approxfun' for constant and linear inter-
     polation.

_E_x_a_m_p_l_e_s:

     op <- par(mfrow = c(2,1), mgp = c(2,.8,0), mar = .1+c(3,3,3,1))
     n <- 9
     x <- 1:n
     y <- rnorm(n)
     plot(x, y, main = paste("spline[fun](.) through",n,"points"))
     lines(spline(x, y))
     lines(spline(x, y, n = 201), col = 2)

     y <- (x-6)^2
     plot(x, y, main = "spline(.) -- 3 methods")
     lines(spline(x, y, n = 201), col = 2)
     lines(spline(x, y, n = 201, method = "natural"), col = 3)
     lines(spline(x, y, n = 201, method = "periodic"), col = 4)
     legend(6,25, c("fmm","natural","periodic"), col=2:4, lty=1)

     f <- splinefun(x, y)
     ls(envir = environment(f))
     splinecoef <- eval(expression(z), envir = environment(f))
     curve(f(x), 1, 10, col = "green", lwd = 1.5)
     points(splinecoef, col = "purple", cex = 2)
     par(op)

