Description Usage Arguments Details Value Note Examples
plot.polynomial
, a method for the
plot
generic. It draws a curve
corresponding to a polynomial over the interval [from, to]
.
1 2 3 4 5 6 7 8 9 10 11 12 | ## S3 method for class 'polynomial'
plot(x, y = NULL, to = NULL, from = y, n = 101, add = FALSE,
type = "l", xname = "x", xlab = xname, ylab = NULL,
log = NULL, xlim = NULL, ...)
## S3 method for class 'polynomial'
points(x, y = NULL, to = NULL, from = y, n = 101, add = FALSE,
type = "p", ...)
## S3 method for class 'polynomial'
lines(x, y = NULL, to = NULL, from = y, n = 101, add = FALSE,
type = "l", ...)
|
x |
a polynomial, or an object which can be coerced by |
y |
alias for |
from, to |
the range over which the polynomial will be plotted. |
n |
integer; the number of x values at which to evaluate. |
add |
logical; if |
xlim |
|
type |
plot type: see |
xname |
character string giving the name to be used for the x axis. Optionally a
|
xlab, ylab, log, ... |
labels and |
The polynomial x
is evaluated at n
points equally spaced over the
range [from, to]
. The points determined in this way are then plotted.
If either from
or to
is NULL
, it defaults to the
corresponding element of xlim
if that is not NULL
.
When neither from/to
nor xlim
specifies both x-limits, the
x-limits are inferred from add
. When add = FALSE
the defaults are
(0, 1)
. For add = NA
and add = TRUE
the defaults are taken
from the x-limits used for the previous plot.
The value of log
is used both to specify the plot axes (unless add
= TRUE
) and how ‘equally spaced’ is interpreted: if the x component
indicates log-scaling, the points at which the polynomial is plotted are equally
spaced on the log scale.
The default value of log
is taken from the current plot when add =
TRUE
, whereas if add = NA
the x component is taken from the existing
plot (if any) and the y component defaults to linear. For add = FALSE
the
default is ""
.
A list with components x
and y
of the points that were drawn is
returned invisibly.
For points.polynomial
and lines.polynomial
, add
is ignored
and is taken to be TRUE
. If the ‘active’ device is the "null
device", an error is raised. See dev.cur
.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 | x <- as.polynomial(Hermite(5))
plot(x, -3, 6, ylim = c(-10, 20))
## 'plot.polynomial' can be combined with 'reduce' for a different y label
## use 'add = NA' to use [from, to] from previous plot
plot(reduce(x, decreasing = TRUE), add = NA, ylim = c(-10, 20))
x <- as.polynomial(Chebyshev1(4))
plot(x, -1, 1, ylim = c(-1, 1))
## use 'xname' for a different x label (and polynomial variable)
plot(x, add = NA, ylim = c(-1, 1), xname = expression(cos(theta)))
## plot Chebyshev polynomials for 'n = 0, ..., 4'
plot(
as.polynomial(Chebyshev1(0)),
from = -1, to = 1, ylim = c(-1, 1),
xname = expression(cos(theta)),
ylab = expression(T[n](cos(theta)))
)
lines (as.polynomial(Chebyshev1(1)), col = "red")
lines (as.polynomial(Chebyshev1(2)), col = "green3")
points(as.polynomial(Chebyshev1(3)), col = "blue")
points(as.polynomial(Chebyshev1(4)), col = "deeppink2")
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.