Create Test Polynomial Matrix
test_polm.Rd
This simple tool creates (random) polynomial matrices for testing purposes.
Usage
test_polm(
dim = c(1, 1),
degree = 0,
random = FALSE,
digits = NULL,
col_end_matrix = NULL,
value_at_0 = NULL,
bzeroes = NULL,
n.trials = 100
)
Arguments
- dim
two dimensional vector of non negative integers, determines the dimension of the polynomial matrix to be created. If the prescribed number of rows or number of columns is zero then an "empty" polynomial matrix is generated. In this case all parameters below are ignored.
- degree
desired degree(s), either a scalar, a vector or a matrix. In the matrix case
degree
prescribes the degrees of the entries of the polynomial matrix. A vectordegree
defines the column degrees of the matrix, i.e. the respective maximal degrees within the columns, and a scalardegree
determines the maximum degree of all entries of the matrix. Of coursedegree
has to be compatible with the parameterdim
. If the desired degree is \(-1\) then a zero polynomial is generated and the parameters below are ignored.- random
If TRUE the coefficents are generated by drawing from a normal distribution. If FALSE then the coefficient of the \(k\)-th power \(z^k\) of the (i,j)-th entry is set equal to "\(ijk\)". In this case the parameters below are ignored!
- digits
integer, if non NULL then the randomly generated numbers are rounded to "digits" number of decimal places.
- col_end_matrix
desired column end matrix (or
NULL
).- value_at_0
desired value of the polynomial at \(z=0\) (or
NULL
).- bzeroes
lower bound for the moduli of the zeroes of the rational matrix (or NULL). This parameter is ignored for non-square matrices (m != n).
- n.trials
maximum number of trials.
Value
polm
object, which represents the generated polynomial matrix.
Details
Note that the desired parameters value_at_0
and column_end_matrix
may be in conflict to the desired degree(s). See the examples below.
The matrices column_end_matrix
and value_at_0
may contain NA
's.
These entries are replaced by randomly generated numbers.
The user may prescribe lower bounds for the moduli of the zeroes
of the polynomial. In this case the procedure simply generates (up to n.trials
)
random matrices until a matrix is found which satisfies the constraint. The standard deviation
of the normal distribution, which is used to generate the random entries, is decreased in each step.
Of course this is a very crude method and it may fail or need a very large number of randomly
generated matrices.
Examples
### "empty" polynomials, number of rows or number of columns is zero.
test_polm(dim = c(0,0))
#> ( 0 x 0 ) matrix polynomial with degree <= -1
test_polm(dim = c(0,2))
#> ( 0 x 2 ) matrix polynomial with degree <= -1
test_polm(dim = c(3,0))
#> ( 3 x 0 ) matrix polynomial with degree <= -1
### (3,3) polynomial of degree -1 (i.e. a(z)=0)
test_polm(dim = c(3,3), degree = -1)
#> ( 3 x 3 ) matrix polynomial with degree <= -1
### (3,3) polynomial with degree 1
test_polm(dim = c(3,3), degree = 1) %>% print(format = 'c')
#> ( 3 x 3 ) matrix polynomial with degree <= 1
#> [,1] [,2] [,3]
#> [1,] 110 + 111z 120 + 121z 130 + 131z
#> [2,] 210 + 211z 220 + 221z 230 + 231z
#> [3,] 310 + 311z 320 + 321z 330 + 331z
### (3,3) polynomial with column degrees -1, 0 and 1
test_polm(dim = c(3,3), degree = c(-1,0,1)) %>% print(format = 'c')
#> ( 3 x 3 ) matrix polynomial with degree <= 1
#> [,1] [,2] [,3]
#> [1,] 0 120 130 + 131z
#> [2,] 0 220 230 + 231z
#> [3,] 0 320 330 + 331z
### random, (3,3) polynomial with prescribed degrees for each element
deg = matrix(c(0, 1, 2,
1,-1,-1,
1, 1, 1), nrow = 3, ncol = 3, byrow = TRUE)
print(deg)
#> [,1] [,2] [,3]
#> [1,] 0 1 2
#> [2,] 1 -1 -1
#> [3,] 1 1 1
a = test_polm(dim = c(3,3), degree = deg, random = TRUE)
print(a, digits = 2, format = 'c')
#> ( 3 x 3 ) matrix polynomial with degree <= 2
#> [,1] [,2] [,3]
#> [1,] 0.05 -1.09 + 0.43z 1.2 + 0.67z + 0.38z^2
#> [2,] 2.83 + 1.54z 0 0
#> [3,] -1.1 + 0.26z -0.64 - 0.2z -0.49 + 0.55z
### random, (3,3) polynomial with prescribed column degree and column end matrix
cm = matrix(NA_real_, nrow = 3, ncol = 3)
cm[lower.tri(cm, diag = FALSE)] = 0
a = test_polm(dim = c(3,3), degree = c(0,1,2), random = TRUE,
digits = 2, col_end_matrix = cm)
print(a, digits = 2, format = 'c')
#> ( 3 x 3 ) matrix polynomial with degree <= 2
#> [,1] [,2] [,3]
#> [1,] 0.74 2.06 - 0.76z 0.51 - 1.16z + 0.89z^2
#> [2,] 0 -0.13 + 1.08z 1.07 - 0.72z - 1.66z^2
#> [3,] 0 1.65 -0.03 + 0.18z + 0.8z^2
print(degree(a, which = 'column'))
#> [1] 0 1 2
print(col_end_matrix(a))
#> [,1] [,2] [,3]
#> [1,] 0.74 -0.76 0.89
#> [2,] 0.00 1.08 -1.66
#> [3,] 0.00 0.00 0.80
### the parameters column_end_matrix and value_at_zero
### may be in conflict with the prescribed degree(s).
# E.g. if we set the second column of "cm" equal to zero
cm[, 2] = 0
a = test_polm(dim = c(3,3), degree = c(0,1,2), random = TRUE,
digits = 2, col_end_matrix = cm)
print(a, digits = 2, format = 'c')
#> ( 3 x 3 ) matrix polynomial with degree <= 2
#> [,1] [,2] [,3]
#> [1,] -0.4 1.9 0.43 - 1.42z + 0.86z^2
#> [2,] 0 -0.48 -1.19 - 0.34z + 0.03z^2
#> [3,] 0 -0.09 -0.81 + 1.75z + 2.98z^2
# then the generated polynomial has column degrees 0,0,2
# and the column end matrix is not upper triangular!
print(degree(a, which = 'column'))
#> [1] 0 0 2
print(col_end_matrix(a))
#> [,1] [,2] [,3]
#> [1,] -0.4 1.90 0.86
#> [2,] 0.0 -0.48 0.03
#> [3,] 0.0 -0.09 2.98
### here we set a(0) equal to the identity matrix and
### require that a(z) has no zeroes within the unit circle
a = try(test_polm(dim = c(3,3), degree = 2, random = TRUE,
digits = 2, value_at_0 = diag(3), bzeroes = 1))
if (!inherits(a, 'try-error')) {
print(a, digits = 2, format = 'c')
print(abs(zeroes(a)))
}
#> ( 3 x 3 ) matrix polynomial with degree <= 2
#> [,1] [,2] [,3]
#> [1,] 1 - 0.04z + 0.39z^2 -0.4z - 0.05z^2 -0.08z + 0.11z^2
#> [2,] 0.04z - 0.3z^2 1 - 0.6z + 0.15z^2 -0.2z - 0.15z^2
#> [3,] -0.05z + 0.34z^2 -0.34z + 0.25z^2 1 - 0.48z + 0.82z^2
#> [1] 1.222945 1.222945 1.426166 1.426166 2.903849 2.903849