swh:1:snp:dcccee4ba1e6e7fdbe7bdf90401f2f9499bd525b
Tip revision: 392ae21a013fb3f518e8f9eb8efb458a55a2eca2 authored by HwB on 09 April 2011, 00:00:00 UTC
version 0.3-0
version 0.3-0
Tip revision: 392ae21
polyfit.Rd
\name{polyfit}
\alias{polyfit}
\title{Fitting by Polynomial}
\description{
Polynomial curve fitting
}
\usage{
polyfit(x, y, n)
}
\arguments{
\item{x}{x-coordinates of points}
\item{y}{y-coordinates of points}
\item{n}{degree of the fitting polynomial}
}
\details{
Calculates the coefficients of a polynomial of degree \code{n}
fitting the points given by their \code{x}, \code{y} coordinates
in a least-squares sense.
if \code{x}, \code{y} are matrices of the same size, the coordinates
are taken elementwise. Complex values are not allowed.
}
\value{
vector representing a polynomial
}
\seealso{
\code{\link{polydef}}, \code{\link{polyval}}
}
\examples{
# Fitting the sine function by a polynomial
x <- seq(0, pi, length.out=25)
y <- sin(x)
p <- polyfit(x, y, 6)
\dontrun{
# Plot sin and fitted polynomial
plot(x, y, type="b")
yf <- polyval(p, x)
lines(x, yf, col="red")
grid()
}
}
\keyword{ math }