Description Usage Arguments Details Methods (by class) See Also Examples
Polynomial matrix Diagonals Extract or construct a diagonal polynomial matrix.
1 2 3 4 5 6 7 
x 
a polynomial matrix, or a polynomial, or an R object 
nrow, ncol 
optional dimensions for the result when x is not a matrix 
names 
not used for polynomial matrices 
In case of polynomial objects, diag
has 2 distinct usage:
x
is a polynomial, returns a polynomial matrix the given diagonal
and zero offdiagonal entries.
x
is a polynomial matrix, returns a vector as a polynomial matrix of
diagonal elements
For polynomial, either nrow
or ncol
must be provided.
polynomial
: for a polynomial, returns a polynomial matrix with the given diagonal
polyMatrix
: for a polynomial matrix extracts diagonal
For polynomial matrix, neither nrow
nor ncol
cannot be provided.
Base base::diag()
for numericals and numerical matrices
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24  # numericals and numerical matrices
diag(matrix(1:12, 3, 4)) ## 1 5 8
diag(9, 2, 2)
## [,1] [,2]
## [1,] 9 0
## [2,] 0 9
# polynomial
diag(parse.polynomial("1+x+3x^2"), 2, 3)
## [,1] [,2] [,3]
## [1,] 1 + x + 3x^2 0 0
## [2,] 0 1 + x + 3x^2 0
# polynomial matrix
diag(parse.polyMatrix(
"3 + x^2, 2 + 4 x, x^2",
" 1, 2, 3 + x",
" 2x, 0, 2  3x"
))
## [,1] [,2] [,3]
## [1,] 3 + x^2 2 2  3x

Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.