Rev 7002 | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed
\name{curve}\title{Draw Function Plots}\alias{curve}\alias{plot.function}\usage{curve(expr, from, to, n = 101, add = FALSE, type = "l",ylab = NULL, log = NULL, \dots)plot.function(fn, from = 0, to = 1, n = 101, \dots)}\arguments{\item{expr}{an expression written as a function of \code{x}, oralternatively a function which will be plotted.}\item{fn}{a `vectorizing' numeric \R function.}\item{from,to}{the range over which the function will be plotted.}\item{n}{integer; the number of x values at which to evaluate.}\item{add}{logical; if \code{TRUE} add to already existing plot.}\item{\dots}{graphical parameters can also be specified as arguments.\code{plot.function} passes all these to \code{curve}.}}\description{Draws a curve corresponding to the given function or expression (in\code{x}) over the interval \code{[from,to]}.}\details{The evaluation of \code{expr} is at \code{n} points equally spacedover the range \code{[from, to]}. The points determined in this wayare then joined with straight lines. \code{fn(x)} or \code{expr}(with \code{x} inside) must return a numeric of the same length as\code{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.}\value{\code{NULL}. For ``expensive'' \code{expr}essions, you should usesmarter tools.}\seealso{\code{\link{splinefun}} for spline interpolation, \code{\link{lines}}.}\examples{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))}\keyword{hplot}