as.body: Create a Function Body From a Polynomial

Description Usage Arguments Details Value Examples

Description

Coerce a polynomial to class "call" such that it can be used in function bodies and for labels in figures.

Usage

1
as.body(x, var = "x", ...)

Arguments

x

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

var

a character string; the name of the variable to use for the polynomial. Optionally a call or expression, see Examples.

...

further arguments passed to reduce.

Details

A zero length polynomial will return one of numeric(length(var)) or complex(length(var)), depending on the mode of the coefficients.

Simplifications are made where possible including not multiplying a variable by 1, not raising a variable to a power of 1, not multiplying by a variable raised to a power of 0, pulling signs from trailing coefficients, and exchanging complex coefficients for real coefficients. These guidelines are not always followed for edge cases, these are for general use.

Value

A class "call" object.

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
## when supplied with exactly one coefficient, most simplifactions are ignored.
as.body(1+0i, strict = FALSE)


## zero valued coefficients are removed by 'reduce', this can be changed.
as.body(0)
as.body(0, zero.rm = FALSE)  # zero valued coefficient is retained.


as.body(Hermite(10), decreasing = TRUE)
as.body(Cyclotomic(105), decreasing = TRUE)


## 'var' can be a call to result in a more interesting result.
## the Chebyshev polynomials of the first kind are based on 'x = cos(theta)'
## and we can use 'var' to simulate this.
as.body(Chebyshev1(5), decreasing = TRUE,
    var = call("cos", as.symbol("theta")))


## we can also specify 'var' as an expresion to get the same thing.
as.body(Chebyshev1(5), decreasing = TRUE,
    var = expression(cos(theta)))


## you can combine this with 'as.function' like this:
as.function(reduce(Chebyshev1(5), decreasing = TRUE),
    xname = "theta", var = expression(cos(theta)))

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