plot.polynomial: Plot Method for Polynomials

Description Usage Arguments Details Value Note Examples

Description

plot.polynomial, a method for the plot generic. It draws a curve corresponding to a polynomial over the interval [from, to].

Usage

 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", ...)

Arguments

x

a polynomial, or an object which can be coerced by as.polynomial to a polynomial.

y

alias for from for compatibility with plot.

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 TRUE add to an already existing plot; if NA start a new plot taking the defaults for the limits and log-scaling of the x-axis from the previous plot. Taken as FALSE (with a warning if a different value is supplied) if no graphics device is open.

xlim

NULL or a numeric vector of length 2; if non-NULL it provides the defaults for c(from, to) and, unless add = TRUE, selects the x-limits of the plot.

type

plot type: see plot.default.

xname

character string giving the name to be used for the x axis. Optionally a call or expression, see as.body.

xlab, ylab, log, ...

labels and graphical parameters can also be specified as arguments. See Details for the interpretation of the default for log.

Details

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 "".

Value

A list with components x and y of the points that were drawn is returned invisibly.

Note

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.

Examples

 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")

polynomial documentation built on Feb. 22, 2021, 5:08 p.m.