The R Project SVN R

Rev

Rev 2 | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

<HEAD><TITLE>Spline Interpolation</TITLE>
<A NAME=HEADING1></A>
[ <A HREF="Index.html">top</A> | <A HREF="Index.html"> up</A> ]
<CENTER>
<H2><I>Spline Interpolation</I></H2>
</CENTER>
<H3><I>Syntax</I></H3>
<PRE>spline(x, y, n=3*length(x), xmin=min(x), xmax=max(x),
        method="fmm")
splinefun(x, y, method="fmm")
</PRE>
<H3><I>Arguments</I></H3>
<TABLE>
<TR VALIGN=TOP><TD><code>x,y </code>
<TD>
vectors giving the coordinates of the points to be interpolated.
Alternatively a single plotting structure can be specified.
<TR VALIGN=TOP><TD><code>n </code>
<TD>
interpolation takes place at <code>n</font>
equally spaced points spanning the interval <code>[xmin, xmax]</font>.
<TR VALIGN=TOP><TD><code>xmin </code>
<TD>
left-hand endpoint of the interpolation interval.
<TR VALIGN=TOP><TD><code>xmax </code>
<TD>
right-hand endpoint of the interpolation interval.
<TR VALIGN=TOP><TD><code>method </code>
<TD>
this specifies the type of spline to be used.
Possible values are <code>"fmm"</font>, <code>"natural"</font> and <code>"periodic"</font>.
</TABLE>
<H3><I>Description</I></H3>
<code>spline</font> performs cubic spline interpolation of the given data points.
It returns a list containing components
<code>x</font>, and <code>y</font> which give the ordinates where interpolation took
place and the interpolated values.
<p>
If <code>method="fmm"</font>, 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
<code>method="natural"</font> and periodic splines when 
<code>method="periodic"</font>.
<p>
<code>splinefun</font> returns a function which will perform
cubic spline interpolation of the given data points.
<H3><I>References</I></H3>
Forsythe, G. E., M. A. Malcolm and C. B. Moler (1977).
<I>Computer Methods for Mathematical Computations</I>.
<H3><I>See Also</I></H3>
<code><a href = "approx.html">approx</a></font>.
<H3><I>Examples</I></H3>
<xmp>x <- 1:10
y <- rnorm(10)
plot(x, y)
lines(spline(x, y))

x <- 1:10
y <- rnorm(10)
f <- spline(x, y)
curve(f(x), 1, 10)
</xmp>