f1<-function(t)
{
sqrt((t^2)+1)
}
curve(f1,from=0,to = 5,n=10)
plot(f1,from=0,to = 5,n=10)
gives the same output. Then, what is the difference between curve and plot function?
Not a lot for functions. plot
eventually calls curve
.
plot
is a generic function, meaning that it has multiple methods depending on the class of object passed to it (in this case, a function). To find out the code behind a particular method, you can type graphcs:::plot.<method>
.
In this case, you can see that plot
when applied to a function first checks and tweaks its arguments before eventually just calling curve
.
> graphics:::plot.function
function (x, y = 0, to = 1, from = y, xlim = NULL, ylab = NULL,
...)
{
if (!missing(y) && missing(from))
from <- y
if (is.null(xlim)) {
if (is.null(from))
from <- 0
}
else {
if (missing(from))
from <- xlim[1L]
if (missing(to))
to <- xlim[2L]
}
if (is.null(ylab)) {
sx <- substitute(x)
ylab <- if (mode(x) != "name")
deparse(sx)[1L]
else {
xname <- list(...)[["xname"]]
if (is.null(xname))
xname <- "x"
paste0(sx, "(", xname, ")")
}
}
curve(expr = x, from = from, to = to, xlim = xlim, ylab = ylab,
...)
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With