Learn R Programming

polyMatrix (version 0.9.16)

degree: Gets the maximum degree of polynomial objects

Description

Returns the maximum degree as an integer number.

Usage

degree(x)

# S4 method for numeric degree(x)

# S4 method for matrix degree(x)

# S4 method for polynomial degree(x)

# S4 method for polyMatrix degree(x)

Arguments

x

an R objects

Value

The value is an integer number which can be different from zero only for polynomial objects.

Methods (by class)

  • numeric: a scalar argument always has zero degree

  • matrix: a numerical matrix always has zero degree

  • polynomial: the degree of a polynomial

  • polyMatrix: the degree of a polynomial matrix is the highest degree of its elements

Details

By default, this function raises error for unknown type of object.

A numerical scalar can be treated as a polynomial with zero degree.

A numerical matrix has zero degree as each of its items has zero degree as well.

For polynomials this function returns the highest degree of its terms with non-zero coefficient.

Examples

Run this code
# NOT RUN {
# numerical
degree(1)  ## 0


# numerical matrix
degree(matrix(1:6, 3, 2)) ## 0


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


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

# }

Run the code above in your browser using DataLab