Polynomials with real coefficients
rpoly.RdCompute 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 \(\pi\).
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 whenxis complex. - real
-
the real roots of the polynomial. This argument is not needed when
xis complex. - argpi
-
if
TRUE, thenargrepresents the complex arguments as a multiple of \(\pi\), see section ‘Details’. The default isFALSE. - monic
-
if
TRUE, the default, the coefficient of the highest term of the polynomialis is set to 1. ifFALSE, 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.
Note
When argpi is TRUE, \(\cos(\pi 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.
Examples
## z-1
rpoly(real = 1)
#> [1] -1 1
## roots 1, i, -i; p3(z) = (z-1)(z-i)(z+i)
p3 <- rpoly(c(1, 1i))
p3
#> [1] -1 1 -1 1
polyroot(p3)
#> [1] 3.845760e-17+1i 5.482132e-17-1i 1.000000e+00+0i
## using polar for the complex roots (i = e^(i pi/2))
p3a <- rpoly(1, pi/2, real = 1)
p3a
#> [1] -1 1 -1 1
## mathematically, p3a is the same as p3
## but the numerical calculation here gives a slight discrepancy
p3a == p3
#> [1] TRUE FALSE FALSE TRUE
p3a - p3
#> [1] 0.000000e+00 2.220446e-16 -2.220446e-16 0.000000e+00
## using argpi = TRUE is somewhat more precise:
p3b <- rpoly(1, 1/2, real = 1, argpi = TRUE)
p3b
#> [1] -1 1 -1 1
p3b == p3
#> [1] TRUE TRUE TRUE TRUE
p3b - p3
#> [1] 0 0 0 0
## indeed, in this case the results for p3b and p3 are identical:
identical(p3b, p3)
#> [1] TRUE
## two ways to expand (z - 2*exp(i*pi/4))(z - 2*exp(-i*pi/4))
rpoly(2, pi/4)
#> [1] 4.000000 -2.828427 1.000000
rpoly(2, 1/4, argpi = TRUE)
#> [1] 4.000000 -2.828427 1.000000
## set the constant term to 1; can be used, say, for AR models
rpoly(2, pi/4, monic = FALSE)
#> [1] 1.0000000 -0.7071068 0.2500000
rpoly(2, 1/4, argpi = TRUE, monic = FALSE)
#> [1] 1.0000000 -0.7071068 0.2500000