\Header{curve}{Draw Function Plots}
\alias{plot.function}{curve}
\keyword{hplot}{curve}
\begin{Usage}
\begin{verbatim}
curve(expr, from, to, n=101, add=FALSE, type="l", ylab = NULL, log=NULL, ...)
plot.function(fn, from=0, to=1, n=101, ...)
\end{verbatim}
\end{Usage}
\begin{Arguments}
\begin{ldescription}
\item[\texttt{expr}] an expression written as a function of \texttt{x}, or
alternatively a function which will be plotted.
\item[\texttt{fn}] a `vectorizing' numeric \R\ function.
\item[\texttt{from,to}] the range over which the function will be plotted.
\item[\texttt{n}] integer; the number of x values at which to evaluate.
\item[\texttt{add}] logical; if \texttt{TRUE} add to already existing plot.
\item[\texttt{...}] graphical parameters can also be specified as arguments.
\texttt{plot.function} passes all these to \texttt{curve}.
\end{ldescription}
\end{Arguments}
\begin{Description}
Draws a curve corresponding to the given function or expression 
(in \texttt{x}) over the interval \texttt{[from,to]}.\end{Description}
\begin{Details}
The evaluation of \texttt{expr} is at \texttt{n} points equally spaced
over the range \texttt{[from, to]}. 
The points determined in this way are then joined with
straight lines.
\texttt{fn(x)} or \texttt{expr} (with \texttt{x} inside) must return a
numeric of the same length as \texttt{x}.

This used to be a quick hack which seems to serve a useful purpose,
but can give bad results for functions which are not smooth.\end{Details}
\begin{Value}
\texttt{NULL}. For ``expensive'' \texttt{expr}essions, you should use smarter tools.\end{Value}
\begin{SeeAlso}
\texttt{\Link{splinefun}} for spline interpolation, \texttt{\Link{lines}}.\end{SeeAlso}
\begin{Examples}
\begin{ExampleCode}
par(mfrow=c(2,2))
curve(x^3-3*x, -2, 2)
curve(x^2-2, add = TRUE, col = "violet")

curve(sin, -pi, 3*pi)
plot(cos)
chippy <- function(x) sin(cos(x)*exp(-x/2))
curve(chippy, -8, 7, n=2001)

for(ll in c("","x","y","xy"))
   curve(log(1+x), 1,100, log=ll, sub=paste("log=",ll))
\end{ExampleCode}
\end{Examples}

