# NOT RUN {
# create a new polynomial matrix by parsing strings
pm <- parse.polyMatrix(
"x; 1 + x^2; 3 x - x^2",
"1; 1 + x^3; - x + x^3"
)
# get coefficient matrix for degree 0
pm[[0]]
## [,1] [,2] [,3]
## [1,] 0 1 0
## [2 ] 1 1 0
# get coefficient matrix for degree 1
pm[[1]]
## [,1] [,2] [,3]
## [1,] 1 0 3
## [2 ] 0 0 -1
# dimensions
nrow(pm) ## 2
ncol(pm) ## 3
dim(pm) ## [1] 2 3
# round
round(parse.polyMatrix(
" 1.0001 - x, 1 - x^2, 1 + 2.0003*x + x^2",
"0.0001 + x - x^2, 1 + x + 0.0001 x^2, 1 - 2*x + x^2"
))
## [,1] [,2] [,3]
## [1,] 1 - x 1 - x^2 1 + 2x + x^2
## [2,] x - x^2 1 + x 1 - 2x + x^2
# print out a polynomial matrix
show(parse.polyMatrix(
" 1.0001 - x, 1 - x^2, 1 + 2.0003*x + x^2",
"0.0001 + x - x^2, 1 + x, 1 - 2*x + x^2",
" 12.3 x^3, 2 + 3.5 x + x^4, -0.7 + 1.6e-3 x^3"
))
## [,1] [,2] [,3]
## [1,] 1.0001 - x 1 - x^2 1 + 2.0003x + x^2
## [2,] 1e-04 + x - x^2 1 + x 1 - 2x + x^2
## [3,] 12.3x^3 2 + 3.5x + x^4 -0.7 + 0.0016x^3
# }
Run the code above in your browser using DataLab