Learn R Programming

polyMatrix (version 0.9.16)

matrix.degree: Degree of each item of the matrix

Description

Returns a matrix obtained by applying a function degree() for each element of the matrix.

Usage

matrix.degree(x)

# S4 method for matrix matrix.degree(x)

# S4 method for polynomial matrix.degree(x)

# S4 method for polyMatrix matrix.degree(x)

Arguments

x

an R object

Value

If the argument is a matrix, the result is a matrix of the same size containing the degrees of the matrix items.

For a numerical matrix the value is always a zero matrix of the same size

For a polynomial the value is the degree of the polynomial

Methods (by class)

  • matrix: the degree of a numerical matrix is a zero matrix for compatibility

  • polynomial: the degree of a polynomial

  • polyMatrix: a matrix of degrees for each polynomial item of the source matrix

Details

Degree of each item is calculated using degree() which is defined for polynomials as the highest degree of the terms with non-zero coefficients.

For convenience this function is defined for any object, but returns zero for non polynomial objects.

Examples

Run this code
# NOT RUN {
# numerical matrices
matrix.degree(matrix(1:6, 2, 3))
##      [,1] [,2] [,3]
## [1,]    0    0    0
## [2,]    0    0    0

# polynomials
matrix.degree(parse.polynomial("x + 1")) ## 1
matrix.degree(parse.polynomial("x^3 + 1")) ## 3
matrix.degree(parse.polynomial("1")) ## 0

# polynomial matrices
matrix.degree(parse.polyMatrix(
   "x; x^2 + 1",
   "0; 2x"))
##      [,1] [,2]
## [1,]    1    2
## [2,]    0    1
# }

Run the code above in your browser using DataLab