rpoly: Polynomials with real coefficients

View source: R/rpoly.R

rpolyR Documentation

Polynomials with real coefficients

Description

Compute the coefficients of a polynomial with real coefficients, given its real zeroes (roots) and one representative for each complex pair. If complex numbers are given in polar form, there is an option to specify the complex arguments as multiples of π.

Usage

rpoly(x = numeric(0), arg = numeric(0), real = numeric(0), argpi = FALSE,
      monic = TRUE)

Arguments

x

if complex, the roots (including the real ones), otherwise the moduli of the complex roots of the polynomial. In both cases only one representative for each complex pair should be included.

arg

the complex arguments corresponding to the moduli in x. This argument is not needed when x is complex.

real

the real roots of the polynomial. This argument is not needed when x is complex.

argpi

if TRUE, then arg represents the complex arguments as a multiple of π, see section ‘Details’. The default is FALSE.

monic

if TRUE, the default, the coefficient of the highest term of the polynomialis is set to 1. if FALSE, the constant term is one.

Details

The complex zeroes of polynomials with real coefficients come in complex conjugated pairs. Only one representative from each pair should be supplied to rpoly. The other is added automatically. Of course, all real roots should be supplied, if any.

If x is complex, it should contain all real roots and one representative for each comple pair.

Otherise, if x is not complex, it contains the moduli of the numbers and arg contains the complex arguments. The two should be of equal length.

With the default FALSE for argpi, the k-th root of the polynomial is x[k]*cos(arg[k]) + i*x[k]*sin(arg[k]). If argpi is TRUE it is x[k]*cos(pi*arg[k]) + i*x[k]*sin(pi*arg[k]).

By default, a monic polinomial (the coefficient of the highest order term is 1) is created but if monic is FALSE, the constant term of the polynomial is set to 1 .

The options for argpi = TRUE and/or monic = FALSE are convenient in some applications, e.g., time series analysis and digital signal processing.

Value

a real vector containing the coefficients of the polynomial.

Note

When argpi is TRUE, \cos(π a) is computed using cospi(a). So this may differ slightly from the equivalent result obtained with argpi = FALSE and b = pi*a, which is computed as cos(b) = cos(pi*a), see the example.

Author(s)

Georgi N. Boshnakov

See Also

sim_numbers

Examples

## z-1
rpoly(real = 1)

## roots 1, i, -i;  p3(z) = (z-1)(z-i)(z+i)
p3 <- rpoly(c(1, 1i))
p3
polyroot(p3)

## using polar for the complex roots (i = e^(i pi/2))
p3a <- rpoly(1, pi/2, real = 1)
p3a
## mathematically, p3a is the same as p3
## but the numerical calculation here gives a slight discrepancy
p3a == p3
p3a - p3

## using argpi = TRUE is somewhat more precise:
p3b <- rpoly(1, 1/2, real = 1, argpi = TRUE)
p3b
p3b == p3
p3b - p3
## indeed, in this case the results for p3b and p3 are identical:
identical(p3b, p3)

## two ways to expand (z - 2*exp(i*pi/4))(z - 2*exp(-i*pi/4))
rpoly(2, pi/4)
rpoly(2, 1/4, argpi = TRUE)

## set the constant term to 1; can be used, say, for AR models
rpoly(2, pi/4, monic = FALSE)
rpoly(2, 1/4, argpi = TRUE, monic = FALSE)

gbutils documentation built on May 28, 2022, 1:13 a.m.