diff --git a/DESCRIPTION b/DESCRIPTION index a175207..b1bdd37 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,5 +1,5 @@ Package: polyMatrix -Version: 0.9.11 +Version: 0.9.16 Title: Infrastructure for Manipulation Polynomial Matrices Description: Implementation of class "polyMatrix" for storing a matrix of polynomials and implements @@ -20,7 +20,7 @@ Type: Package Authors@R: c( person("Tamas", "Prohle", email="prohlet@ludens.elte.hu", role="aut"), person("Peter", "Prohle", email="prohlep@math.elte.hu", role="aut"), - person("Nikolai", "Ryzhkov", email="namezys@gmail.com", role=c("aut", "cre")), + person("Nikolai", "Ryzhkov", email="namezys@gmail.com", role=c("aut", "cre"), comment = c(ORCID = "0000-0003-4896-280X")), person("Ildiko", "Laszlo", role="aut", comment = c(ORCID = "0000-0003-2324-8183")), person("Ulas Onat", "Alakent", role="ctb") ) diff --git a/R/class_polyMatrix.R b/R/class_polyMatrix.R index 63fad26..62e7282 100644 --- a/R/class_polyMatrix.R +++ b/R/class_polyMatrix.R @@ -1,5 +1,5 @@ # Title : Main class of polymatrix -# Objective : Definition of class +# Objective : The definition of the class # Created by: namezys # Created on: 2020. 10. 16. @@ -15,15 +15,15 @@ setOldClass(P) return("Negative number of columns") } if(ncol(object@coef) %% object@ncol != 0) { - return("Invalid coefficient matrix size") + return("Invalid matrix size and size of coef") } return(TRUE) } -#' A class to represent matrix of polinomials +#' A class to represent a matrix of polynomials #' #' @slot coef A matrix of coefficients which are joined into one matrix from lower degree to higher -#' @slot ncol Actual number of columns in the polynomial matrix +#' @slot ncol The actual number of columns in the polynomial matrix #' #' @examples #' @@ -41,7 +41,7 @@ polyMatrixClass <- setClass( ) .clean.coef <- function(coef, ncol) { - # clean up coef matrix by removing zero tails + # cleans up coef matrix by removing zero tails stopifnot(ncol(coef) %% ncol == 0) nr <- nrow(coef) d <- ncol(coef) / ncol - 1 @@ -73,23 +73,25 @@ polyMatrixClass <- setClass( #' Create polyMatrix object #' -#' This function will create polynomial object fromm +#' This function will create a polynomial object from #' coefficient matrix or signle value #' #' A coefficient matrix is a matrix which contains -#' matrices of coefficients from lower degree to higher +#' matrices of coefficients starting from lower degree to higher ones, #' side-by-side #' -#' @param data an matrix in case of creation from coefficient matrices or an numer/polynomial -#' @param nrow A numer of rows of matrix. -#' If data is a matrix, default value is the number of rows of data matrix. -#' In other case, it's a required parameter -#' @param ncol Must be positibe. -#' If data is a matrix, default value is the number of columns of data matrix. -#' In other ccase, it's a required parameter. -#' @param degree Degree of polynomials in coefficient matrix. Can't be negative. -#' If data is polynomail, degree can be evaluated automatcal. -#' In other case, default value is 0. +#' @param data A matrix containing matrices of coefficients +#' or a number or a polynomial +#' @param nrow The numer of rows of a polynomial matrix. Must be postive. +#' If data is a matrix, the default value is the number of rows of matrix `data`. +#' In other cases it is a required parameter. +#' @param ncol A number of columns of a polynomial matrix. Must be positive. +#' If data is a matrix, the default value is the number of columns of matrix `data`. +#' In other cases it is a required parameter. +#' @param degree Degree of polynomials in the coefficient matrix. Must be zero or positive. +#' If data is polynomial, degree can be evaluated automatcal. +#' In other case, default value is 0. +#' #' @return new polynomial matrix of polyMatrix class #' @export polyMatrix <- function(data, nrow, ncol, degree) { @@ -104,7 +106,7 @@ polyMatrix <- function(data, nrow, ncol, degree) { ncol <- 1 } if(!missing(degree) && degree < length(data) - 1) { - stop("Polynomail has higher degree than requested") + stop("Polynomial has higher degree than requested") } degree <- length(data) - 1 nrow <- as.integer(nrow) @@ -158,7 +160,7 @@ polyMatrix <- function(data, nrow, ncol, degree) { #' Check if object is polyMatrix #' #' @param x an \R object -#' @return TRUE if object is a polonial matrix +#' @return TRUE if object is a polynomial matrix #' @examples #' is.polyMatrix(c(1, 2, 3)) #' is.polyMatrix(polyMatrix(0, 2, 2)) @@ -176,4 +178,4 @@ is.polyMatrix <- function(x) { } } return(polynom::as.polylist(result)) -} \ No newline at end of file +} diff --git a/R/class_polyMatrixCharPolynomial.R b/R/class_polyMatrixCharPolynomial.R index 70e4d33..cae8ca1 100644 --- a/R/class_polyMatrixCharPolynomial.R +++ b/R/class_polyMatrixCharPolynomial.R @@ -1,4 +1,4 @@ -# Title : Class of characteristic polinomail of polynomail matrix +# Title : Class of characteristic polynomial of a polynomial matrix # Objective : We use polyMatrix to store polynomial coefficients # Created by: namezys # Created on: 2021. 05. 05. @@ -8,14 +8,14 @@ PMCP <- "polyMatrixCharPolynomial" .check.polyMatrixCharClass <- function (object) { if (nrow(object@coef) != 1) { - return("Char polynomial matrix should contrains only one row") + return("Char polynomial matrix should contain only one row") } return(TRUE) } -#' A class to repesent characteristic polynomial of polynomial matrix +#' A class to repesent characteristic polynomial of a polynomial matrix #' -#' Characteristic polynomial of polynomial matrix is polynomial with polynomial coefficients +#' Characteristic polynomial of a polynomial matrix is a polynomial with polynomial coefficients #' @export polyMatrixCharClass <- setClass( PMCP, diff --git a/R/method_adjoint.R b/R/method_adjoint.R index 846d619..37dd768 100644 --- a/R/method_adjoint.R +++ b/R/method_adjoint.R @@ -1,12 +1,12 @@ -# Title : cofactor and adjoint matrix +# Title : cofactor and the adjoint matrix # Created by: namezys # Created on: 2021. 04. 29. -#' Cofactor of matrix +#' Cofactor of a matrix #' -#' @param x an matrix -#' @param r,c the row and column -#' @return cofactor which is number or polynomial +#' @param x a matrix +#' @param r,c the rows and columns +#' @return cofactor which is a number or a polynomial #' #' @seealso [adjoint()] #' @@ -39,15 +39,15 @@ cofactor <- function(x, r, c) { return(result) } -#' Adjugate or classical adjoint of a square matrix +#' Adjungate or classical adjoint of a square matrix #' -#' The adjugate or classical adjoint of a square matrix is the transpose of its cofactor matrix. -#' It is also occasionally known as adjunct matrix,[ though this nomenclature appears to have decreased in usage. +#' The adjungate or classical adjoint of a square matrix is the transpose of its cofactor matrix. +#' It is also occasionally known as adjunct matrix, though this nomenclature appears to have been decreased in usage. #' -#' @param x an matrix +#' @param x a matrix #' #' @export setGeneric("adjoint", .adjoint.generic) -#' @describeIn adjoint adjugate of polynomial matrix +#' @describeIn adjoint adjungate of polynomial matrix DON'T UNDERSTAND!!! #' @export setMethod("adjoint", signature(x = PM), .adjoint.polyMatrix) diff --git a/R/method_bind.R b/R/method_bind.R index 1ca07cd..0ab4b6d 100644 --- a/R/method_bind.R +++ b/R/method_bind.R @@ -1,18 +1,18 @@ -# Title : row and column bind -# Objective : because core function use only "..." we have to redefine method to allow to use with polyMatrix in any -# poisition +# Title : row and column binding +# Objective : because core functions use only "..." we have to redefine the method +# in order to allow us to use with polyMatrix in any poisition of argument liist # Created by: namezys # Created on: 2020. 10. 23. -#' Combine polynial matrices by rows or coluns +#' Combine polynomial matrices by rows or columns #' -#' @param ... (generalzed) vectors or mmatrices. -#' If any of objects are polynomail matrix -#' @param deparse.level details in base function, polynomial matrices doesn't use it +#' @param ... (generalized) vectors or matrices. +#' If any of the objects is a polynomail matrix +#' @param deparse.level details in the base function, polynomial matrices doesn't use this argument #' -#' @return if at least one argument is a polynomail matrix, -#' the result will be combined polynomial matrix. -#' Overwise, base package implementatioon [base::cbind()] or [base::rbind()] +#' @return if at least one argument is a polynomial matrix, +#' the result will be a combined polynomial matrix. +#' Otherwise, the base package implementation [base::cbind()] or [base::rbind()] #' will be called. #' #' @seealso [base::cbind()] @@ -42,7 +42,7 @@ cbind <- function(..., deparse.level = 1) { if(is.null(nr)) { nr <- vnr } else if(!is.null(vnr) && nr != vnr) { - stop("number of rows of matrices must match") + stop("the number of rows of the matrices must match") } vnc <- ncol(i) if(is.null(vnc)) { @@ -69,7 +69,7 @@ cbind <- function(..., deparse.level = 1) { return(res) } -#' @describeIn cbind row based bind +#' @describeIn cbind row based bind DON'T UNDERSTAND.. !!! #' #' @export rbind <- function(..., deparse.level = 1) { @@ -97,7 +97,7 @@ rbind <- function(..., deparse.level = 1) { if(is.null(nc)) { nc <- vnc } else if(!is.null(vnc) && nc != vnc) { - stop("number of columns of matrices must match") + stop("the number of columns of the matrices must match") } vnr <- nrow(i) if(is.null(vnr)) { @@ -122,4 +122,4 @@ rbind <- function(..., deparse.level = 1) { r <- r + vnr } return(res) -} \ No newline at end of file +} diff --git a/R/method_charpolynom.R b/R/method_charpolynom.R index 8d92bf9..3e346aa 100644 --- a/R/method_charpolynom.R +++ b/R/method_charpolynom.R @@ -65,18 +65,18 @@ return(polyMatrixCharClass(coef=.char.step(x, diag(1, nrow(x), ncol(x))))) } -#' Characteristic polynomial of matrix +#' Characteristic polynomial of a matrix #' #' @param x an matrix #' #' @export setGeneric("charpolynom", function(x) { - stop("Matrix object is exppected") + stop("Matrix object is expected") }) #' @describeIn charpolynom for numerical matrix it is a polynomial with numerical coefficients #' #' @return When the input is a numerical matrix of `matrix` class -#' then the value is a `polynomial` object. +#' the value is a `polynomial` object. #' #' @examples #' @@ -92,13 +92,13 @@ setMethod("charpolynom", signature(x="matrix"), .charpolynom.matrix) setMethod("charpolynom", signature(x=P), function (x) { return(charpolynom(polyMatrix(x))) }) -#' @describeIn charpolynom for polynomial matrix it has polynomial coefficients +#' @describeIn charpolynom for polynomial matrix has polynomial coefficients #' #' @details #' The characteristic polynom of a polynomial matrix is a polynom with polynomial coefficients. #' #' @return When the input is a `polyMatrix` object -#' then a value is `polyMatrixCharClass` class object, +#' then the value is `polyMatrixCharClass` class object, #' #' @seealso [polyMatrixCharClass] #' @export diff --git a/R/method_coef.R b/R/method_coef.R index fc96a82..f652a76 100644 --- a/R/method_coef.R +++ b/R/method_coef.R @@ -1,10 +1,10 @@ -# Title : Get coeffisient matrix by using "[[" operator +# Title : Gets coefficient matrix by using "[[" operator # Created by: namezys # Created on: 2020. 10. 16. #' @describeIn polyMatrix get coefficient matrix by degree #' -#' @param i the degree to extract matrix of coefficient +#' @param i the degree of the matrix of coefficient to be extracted #' @examples #' #' # get coefficient matrix for degree 0 @@ -21,23 +21,23 @@ #' @export setMethod("[[", signature(x = PM, i = "numeric"), function(x, i) { if(length(i) != 1) { - stop("Only one coefficient matrix can be gotten") + stop("Only one coefficient matrix can be gotten at once") } if(i > degree(x) || i < 0) { stop("degree out of bounds") } return(x@coef[, seq_len(ncol(x)) + ncol(x) * i]) }) -#' @describeIn charpolynom get polynomial coefficient of characteristic +#' @describeIn charpolynom get polynomial coefficient of characteristic polynomial #' -#' @param i the degree to extract polinomial coefficient +#' @param i the degree of the polynomial coefficient to be extract #' @export setMethod("[[", signature(x = PMCP), function(x, i) { if(length(i) != 1) { - stop("Only one coefficient matrix can be gotten") + stop("Only one coefficient matrix can be gotten at once") } if(i + 1 > ncol(x@coef) || i < 0) { stop("degree out of bounds") } return(x@coef[1, i + 1]) -}) \ No newline at end of file +}) diff --git a/R/method_degree.R b/R/method_degree.R index 1bd8e48..3f55c14 100644 --- a/R/method_degree.R +++ b/R/method_degree.R @@ -2,7 +2,7 @@ # Created by: namezys # Created on: 2020. 10. 17. -#' Gets maximum degree of polynomial objects +#' Gets the maximum degree of polynomial objects #' #' Returns the maximum degree as an integer number. #' @@ -11,8 +11,7 @@ #' for polynomial objects. #' #' @details -#' By default, this function raises -#' error for unknown type of object. +#' By default, this function raises error for unknown type of object. #' #' @export setGeneric("degree", function(x) { @@ -22,7 +21,7 @@ setGeneric("degree", function(x) { #' @describeIn degree a scalar argument always has zero degree #' #' @details -#' A numerical scalar has zero degree. +#' A numerical scalar can be treated as a polynomial with zero degree. #' #' @examples #' @@ -32,7 +31,7 @@ setGeneric("degree", function(x) { #' @export setMethod("degree", signature(x = NUM), function(x) { if(length(x) != 1) { - stop("Numeric suquence is unsupported") + stop("Numeric sequence is unsupported") } return(0) }) @@ -77,12 +76,12 @@ setMethod("degree", signature(x = P), function(x) { length(x) - 1 }) #' #' @export setMethod("degree", signature(x = PM), function(x) { as.integer(ncol(x@coef) / x@ncol - 1) }) -#' @describeIn charpolynom the degree of char polynomail of polynomial matrix +#' @describeIn charpolynom the degree of char polynomial of polynomial matrix #' #' @export setMethod("degree", signature(x = PMCP), function(x) { as.integer(ncol(x@coef) - 1) }) -#' Degree of each item of matrix +#' Degree of each item of the matrix #' #' Returns a matrix obtained by applying a function [degree()] #' for each element of the matrix. @@ -94,7 +93,7 @@ setMethod("degree", signature(x = PMCP), function(x) { as.integer(ncol(x@coef) - #' #' @details #' Degree of each item is calculated using [degree()] which is defined for polynomials -#' as the highest degree of the terms with non-zero coefficient. +#' 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. diff --git a/R/method_det.R b/R/method_det.R index dbe231c..774e5d6 100644 --- a/R/method_det.R +++ b/R/method_det.R @@ -1,10 +1,10 @@ -# Title : deteminant of polyMatrix +# Title : determinant of polyMatrix # Created by: namezys # Created on: 2021. 04. 02. .number.nonzero.item.in.row <- function(pm, r) { - # We should it very fast, use coef matrix directly + # We should do it very fast, use coef matrix directly positions <- ncol(pm) * 0:degree(pm) result <- 0 for(i in seq_len(ncol(pm))) { diff --git a/R/method_diag.R b/R/method_diag.R index f3807cb..178ff0d 100644 --- a/R/method_diag.R +++ b/R/method_diag.R @@ -1,4 +1,4 @@ -# Title : get diagnola matrix from polynomail +# Title : get diagnoal matrix from polynomial # Created by: namezys # Created on: 2021. 04. 02. @@ -37,22 +37,22 @@ #' Extract or construct a diagonal polynomial matrix. #' #' @param x a polynomial matrix, or a polynomial, or an \R object -#' @param nrow,ncol optional dimensions for the result when x is not a matrix. -#' @param names not usedd +#' @param nrow,ncol optional dimensions for the result when x is not a matrix +#' @param names not used for polynomial matrices #' @details #' -#' In case of polynomail objets, `diag` has 2 distinct usage: +#' In case of polynomial objects, `diag` has 2 distinct usage: #' -#' * \code{x} is a polynomial, it returns a polynomial matrix the given diagonal +#' * `x` is a polynomial, returns a polynomial matrix the given diagonal #' and zero off-diagonal entries. -#' * \code{x} is a polynomial matrix, it returns a vector as a polynomial matrix of -#' diagonal elements +#' * `x` is a polynomial matrix, returns a vector as a polynomial matrix of +#' diagonal elements #' #' @seealso Base [base::diag()] for numericals and numerical matrices #' #' @examples #' -#' # numericals and numerical matrix +#' # numericals and numerical matrices #' diag(matrix(1:12, 3, 4)) ## 1 5 8 #' diag(9, 2, 2) #' ## [,1] [,2] @@ -62,11 +62,11 @@ #' #' @export setGeneric("diag", diag) -#' @describeIn diag for a polynomial, returns polynomial matrix with given diagonal +#' @describeIn diag for a polynomial, returns a polynomial matrix with the given diagonal #' #' @details #' -#' For polynomial, either \code{nrow} or \code{ncol} must be provided. +#' For polynomial, either `nrow` or `ncol` must be provided. #' #' @examples #' @@ -78,9 +78,9 @@ setGeneric("diag", diag) #' #' @export setMethod("diag", signature(x=P), .diag.polynomail) -#' @describeIn diag for a polynomial matrix extract diagonal +#' @describeIn diag for a polynomial matrix extracts diagonal #' -#' For polynomial matrix, neither \code{nrow} and \code{ncol} can't be provided. +#' For polynomial matrix, neither `nrow` nor `ncol` cannot be provided. #' #' @examples #' diff --git a/R/method_dim.R b/R/method_dim.R index 96aedb5..1f47aec 100644 --- a/R/method_dim.R +++ b/R/method_dim.R @@ -4,11 +4,11 @@ #' @export setGeneric("nrow", nrow) -#' @describeIn polyMatrix number of rows of a polynomial matrix +#' @describeIn polyMatrix the number of rows of a polynomial matrix #' #' @export setMethod("nrow", signature(x = PM), function(x) { return(nrow(x@coef)) }) -#' @describeIn polyMatrix an polynomial has only one row +#' @describeIn polyMatrix a polynomial has only one row #' #' @examples #' @@ -20,11 +20,11 @@ setMethod("nrow", signature(x = P), function(x) { 1 }) #' @export setGeneric("ncol", ncol) -#' @describeIn polyMatrix number of column of a polynomial matrix +#' @describeIn polyMatrix the number of columns of a polynomial matrix #' #' @export setMethod("ncol", signature(x = PM), function(x) { return(x@ncol) }) -#' @describeIn polyMatrix an polynomial has only one column +#' @describeIn polyMatrix a polynomial has only one column #' #' @examples #' @@ -34,7 +34,7 @@ setMethod("ncol", signature(x = PM), function(x) { return(x@ncol) }) setMethod("ncol", signature(x = P), function(x) { 1 }) setGeneric("dim") -#' @describeIn polyMatrix dimension of a polynomial matrix +#' @describeIn polyMatrix the dimension of a polynomial matrix #' #' @examples #' diff --git a/R/method_gcd.R b/R/method_gcd.R index 3b38ae0..f688ca6 100644 --- a/R/method_gcd.R +++ b/R/method_gcd.R @@ -1,4 +1,4 @@ -# Title : Greater commmon divisor of matrix +# Title : Greater common divisor of a matrix # Created by: namezys # Created on: 2021. 05. 09. @@ -6,12 +6,12 @@ #' #' The greatest common divisor of polynomials or polynomial matrices. #' -#' @param ... an list of polynomial objects +#' @param ... a list of polynomial objects #' @seealso polynomial implementation [polynom::GCD()] and [LCM()] #' #' @export setGeneric("GCD", polynom::GCD) -#' @describeIn GCD the greatest common divisor of all elements of the polynomial matrice +#' @describeIn GCD the greatest common divisor of all elements of the polynomial matrix #' #' @examples #' diff --git a/R/method_inv.R b/R/method_inv.R index 6e57773..207e431 100644 --- a/R/method_inv.R +++ b/R/method_inv.R @@ -4,18 +4,18 @@ #' Inverse polynomial matrix #' -#' During inversion we will try to round to zero +#' During inversion we will try to round elememnts to zero. #' -#' @param x an polynomial matrix +#' @param x a polynomial matrix #' @param eps zero threshold #' @details -#' Right now only matrices with numerical determinant is supported +#' Right now only matrices with numerical determinant are supported. #' #' @export inv <- function (x, eps=ZERO_EPS) { dd <- zero.round(det(x), eps=eps) if (degree(dd) != 0) { - stop("Only matrices with numerical determinant is supported") + stop("Only matrices with numerical determinant are supported") } return((1/dd[1]) * adjoint(x)) -} \ No newline at end of file +} diff --git a/R/method_is_zero.R b/R/method_is_zero.R index adb1572..65668ca 100644 --- a/R/method_is_zero.R +++ b/R/method_is_zero.R @@ -1,54 +1,52 @@ -ZERO_EPS <- 1e-5 - -#' Test if something is zero -#' -#' Generic function to check if we can treat on object as being zero. -#' For matrices the result is a matrix of the same size. -#' -#' @param x The checked object -#' @param eps Minimal numerical value which will not treat as zero -#' @return TRUE if the object can be treat as zero -#' -#' @details -#' Different type of objects can be treated as a zero in different ways: -#' * Numerical types can be compare by absolute value with \code{eps}. -#' * Customer types should define an an customer method. -#' -#' By befault eps: -#' ```{r} -#' ZERO_EPS -#' ``` -#' -#' @seealso [zero.round()] -#' -#' @examples -#' -#' # numericals and matrices -#' is.zero(0) ## TRUE -#' is.zero(0.0001, eps=0.01) ## TRUE -#' is.zero(c(0, 1, 0)) ## TRUE, FALSE, TRUE -#' is.zero(matrix(c(1, 9, 0, 0), 2, 2)) -#' # FALSE TRUE -#' # FALSE TRUE -#' -#' @export -setGeneric("is.zero", function (x, eps=ZERO_EPS) {abs(x) < eps}) - -#' @describeIn is.zero a polynomail can be treated as zero -#' if all its coefficients can be treated as zero -#' -#' @examples -#' -#' # polynomials -#' is.zero(parse.polynomial("0.1 - 0.5 x")) ## FALSE -#' is.zero(parse.polynomial("0.0001 - 0.0005 x + 0.00002 x^2"), eps=0.01) ## TRUE -#' -#' @export -setMethod("is.zero", signature(x=P), function (x, eps=ZERO_EPS) {all(abs(as.numeric(x)) < eps)}) - -#' @describeIn is.zero for a polunomial matrix every item is checked as polynomial -#' -#' @export -setMethod("is.zero", signature(x=PM), function (x, eps=ZERO_EPS) { - return(polyMatrix.apply(x, function(x) {is.zero(x, eps=eps)})) -}) \ No newline at end of file +#' Tests if something is zero or not +#' +#' Generic function to check if we can treat on object as being zero. +#' For matrices the result is a matrix of the same size. +#' +#' @param x An \R object +#' @param eps The minimal numerical value which will not be treated as zero +#' @return TRUE if the object can be treat as zero +#' +#' @details +#' Different type of objects can be treated as zero in different ways: +#' * Numerical types can be compared by absolute value with `eps`. +#' * Other types should define its own method. +#' +#' By befault `eps` = `{r} ZERO_EPS` +#' +#' @seealso [zero.round()] +#' +#' @examples +#' +#' # numericals and matrices +#' is.zero(0) ## TRUE +#' +#' is.zero(0.0001, eps=0.01) ## TRUE +#' +#' is.zero(c(0, 1, 0)) ## TRUE, FALSE, TRUE +#' +#' is.zero(matrix(c(1, 9, 0, 0), 2, 2)) +#' ## FALSE TRUE +#' ## FALSE TRUE +#' +#' @export +setGeneric("is.zero", function (x, eps=ZERO_EPS) {abs(x) < eps}) + +#' @describeIn is.zero a polynomial can be treated as zero +#' if all its coefficients can be treated as zero +#' +#' @examples +#' +#' # polynomials +#' is.zero(parse.polynomial("0.1 - 0.5 x")) ## FALSE +#' is.zero(parse.polynomial("0.0001 - 0.0005 x + 0.00002 x^2"), eps=0.01) ## TRUE +#' +#' @export +setMethod("is.zero", signature(x=P), function (x, eps=ZERO_EPS) {all(abs(as.numeric(x)) < eps)}) + +#' @describeIn is.zero for a polynomial matrix every item is checked if it is zero polynomial +#' +#' @export +setMethod("is.zero", signature(x=PM), function (x, eps=ZERO_EPS) { + return(polyMatrix.apply(x, function(x) {is.zero(x, eps=eps)})) +}) diff --git a/R/method_lcm.R b/R/method_lcm.R index 402ecdb..59865c4 100644 --- a/R/method_lcm.R +++ b/R/method_lcm.R @@ -1,4 +1,4 @@ -# Title : Lagest common multiplier of matrix +# Title : Largest common multiplier of a matrix # Created by: namezys # Created on: 2021. 05. 09. @@ -6,7 +6,7 @@ #' #' The least common multiple of polynomials or polynomial matrices. #' -#' @param ... an list of polynomial objects +#' @param ... a list of polynomial objects #' @seealso polynomial implementation [polynom::GCD()] and [GCD()] #' #' @export diff --git a/R/method_predict.R b/R/method_predict.R index 640479e..6c60fa8 100644 --- a/R/method_predict.R +++ b/R/method_predict.R @@ -4,7 +4,7 @@ .predict.polyMatrix <- function(object, newdata) { if (!polynom::is.polynomial(newdata) && !is.numeric(newdata)) { - stop("Only polynomail or numerical argument is supported") + stop("Only polynomial or numerical argument is supported") } d <- degree(object) if (newdata == 0) { @@ -25,7 +25,7 @@ .predict.polyMatrix.charPoly <- function(object, newdata) { if (!polynom::is.polynomial(newdata) && !is.numeric(newdata)) { - stop("Only polynomail or numerical argument is supported") + stop("Only polynomial or numerical argument is supported") } d <- degree(object) if (newdata == 0) { @@ -43,13 +43,13 @@ #' @export setGeneric("predict", predict) -#' @describeIn polyMatrix value of polynomial matrix in point +#' @describeIn polyMatrix the value of a polynomial matrix in a point #' -#' @param newdata the value to evaluate +#' @param newdata the value to be evaluated #' @export setMethod("predict", signature(object = PM), .predict.polyMatrix) -#' @describeIn charpolynom value of char polynomail in polynomial point +#' @describeIn charpolynom the value of char polynomial in a polynomial point #' -#' @param newdata the value to evaluate +#' @param newdata the value to be evaluated #' @export setMethod("predict", signature(object = PMCP), .predict.polyMatrix.charPoly) diff --git a/R/method_proper.R b/R/method_proper.R index f97f258..eff17c1 100644 --- a/R/method_proper.R +++ b/R/method_proper.R @@ -1,25 +1,26 @@ -# Title : Row and column proper prooperty of polyMatrix +# Title : Row and column proper property of polyMatrix # Created by: namezys #' Proper polynomial matrices #' -#' Polynomial matrix is column (row, full) proper (or reduced) if associated matrix has same rank -#' as the number of column (row) +#' A polynomial matrix is column (row, full) proper (or reduced) +#' if the associated matrix has the same rank +#' as the number of columns (rows) #' -#' @param pm a polyMatrix objects -#' @return True if object \code{pm} is a (row-/column-) proper matrix +#' @param pm a polyMatrix object +#' @return True if object `pm` is a (row-/column-) proper matrix #' -#' @description Tests the proper property of polynomial matrix. +#' @description Tests the proper property of a polynomial matrix. #' A polynomial matrix is proper if the associeted matrix has a full rank. #' #' @examples -#' pm <- parse.polyMatrix( -#' "-1 + 7x , x", -#' " 3 - x + x^2, -1 + x^2 - 3 x^3" -#' ) -#' is.column.proper(pm) -#' is.row.proper(pm) -#' is.proper(pm) +#' pm <- parse.polyMatrix( +#' "-1 + 7x , x", +#' " 3 - x + x^2, -1 + x^2 - 3 x^3" +#' ) +#' is.column.proper(pm) +#' is.row.proper(pm) +#' is.proper(pm) #' #' @export is.proper <- function (pm) { diff --git a/R/method_round.R b/R/method_round.R index acb0e52..ae5e289 100644 --- a/R/method_round.R +++ b/R/method_round.R @@ -1,23 +1,25 @@ -# Title : Roung of polynomial matrix -# Created by: namezys -# Created on: 2020. 10. 16. - -#' @describeIn polyMatrix round of polynomial matrix is rounding of polynomial coefficients -#' -#' @param x an matrix object -#' @param digits integer indicating the number of decimal places (round) or significant digits (signif) to be used -#' @examples -#' -#' # 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 -#' -#' @export -setMethod("round", signature(x = PM), function(x, digits = 0) { - return(polyMatrix(round(x@coef, digits = digits), nrow(x), ncol(x), degree(x))) -}) \ No newline at end of file +# Title : Rounding of a polynomial matrix +# Created by: namezys +# Created on: 2020. 10. 16. + +#' @describeIn polyMatrix rounding of a polynomial matrix is rounding of polynomial coefficients +#' +#' @param x a matrix object +#' @param digits an integer indicating the number of decimal places (round) +#' or significant digits (signif) to be used +#' +#' @examples +#' +#' # 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 +#' +#' @export +setMethod("round", signature(x = PM), function(x, digits = 0) { + return(polyMatrix(round(x@coef, digits = digits), nrow(x), ncol(x), degree(x))) +}) diff --git a/R/method_show.R b/R/method_show.R index 9c8a573..80e2ba7 100644 --- a/R/method_show.R +++ b/R/method_show.R @@ -124,8 +124,8 @@ #' @export #' @importFrom methods show setMethod("show", signature(object = PM), .show.polyMarix) -#' @describeIn charpolynom prints out a text representation of a characteristic polinomial of -#' polinomial matrix +#' @describeIn charpolynom prints out a text representation of a characteristic polynomial of +#' a polynomial matrix #' #' @param object an \R object #' diff --git a/R/method_subscript.R b/R/method_subscript.R index b5a498d..f346df9 100644 --- a/R/method_subscript.R +++ b/R/method_subscript.R @@ -1,4 +1,4 @@ -# Title : Suscribe to get element of matrix as polynoam or numeric +# Title : Subscribe to get element or part of matrix as polynom or numeric # Created by: namezys # Created on: 2020. 10. 17. @@ -25,40 +25,43 @@ return(if(length(p) == 1) p[1] else p) } -#' @describeIn polyMatrix get matrix content +#' Extract or Replace Parts of a polynomial matrix #' +#' @param x a polynomial matrix +#' @param i row indeces #' @param j column indeces #' @param ... unused #' @param drop unused #' +#' @rdname polyMatrix-subscript #' @export setMethod("[", signature(x = PM, i = "missing", j = "missing", drop="missing"), function(x, ...) { x }) -#' @describeIn polyMatrix get columns +#' @describeIn polyMatrix-subscript get columns #' #' @export setMethod("[", signature(x = PM, i = "missing", j = "ANY", drop="missing"), function(x, i, j) { x[seq_len(nrow(x)), j] }) -#' @describeIn polyMatrix get rows +#' @describeIn polyMatrix-subscript gets rows #' #' @export setMethod("[", signature(x = PM, i = "ANY", j = "missing", drop="missing"), function(x, i, j) { x[i, seq_len(ncol(x))] }) -#' @describeIn polyMatrix get by logical index +#' @describeIn polyMatrix-subscript gets by logical index #' #' @export setMethod("[", signature(x = PM, i = "logical", j = "logical", drop="missing"), function(x, i, j) { return(x[.logic.index.to.integer.index(i, nrow(x)), .logic.index.to.integer.index(j, ncol(x))]) }) -#' @describeIn polyMatrix get by logical index and numerical indeces +#' @describeIn polyMatrix-subscript gets by logical index and numerical indices #' #' @export setMethod("[", signature(x = PM, i = "logical", j = "numeric", drop="missing"), function(x, i, j) { return(x[.logic.index.to.integer.index(i, nrow(x)), j]) }) -#' @describeIn polyMatrix get by logical index and numerical indeces +#' @describeIn polyMatrix-subscript gets by logical index and numerical indices #' #' @export setMethod("[", signature(x = PM, i = "numeric", j = "logical", drop="missing"), function(x, i, j) { @@ -69,20 +72,20 @@ setMethod("[", signature(x = PM, i = "numeric", j = "logical", drop="missing"), nr <- nrow(x) nc <- ncol(x) if(max(i) > nr || max(j) > nc) { - stop("subscript out of bounds") + stop("subscript out of bounds OR RANGE...") } i <- i[i != 0] j <- j[j != 0] if(any(i < 0) || any(j < 0)) { if(any(i < 0)) { if(any(i > 0)) { - stop("only 0's may be mixed with negative subscripts") + stop("only 0's may be mixed with negative subscripts I DON'T UNDERSTAND") } i <- !(seq_len(nr) %in% -i) } if(any(j < 0)) { if(any(j > 0)) { - stop("only 0's may be mixed with negative subscripts") + stop("only 0's may be mixed with negative subscripts SAME..") } j <- !(seq_len(nc) %in% -j) } @@ -97,7 +100,7 @@ setMethod("[", signature(x = PM, i = "numeric", j = "logical", drop="missing"), c_idx <- .rep.seq(j, nc, degree(x)) return(polyMatrix(x@coef[i, c_idx], length(i), length(j), degree(x))) } -#' @describeIn polyMatrix get by row and column indeces +#' @describeIn polyMatrix-subscript gets by row and column indices #' #' @export setMethod("[", signature(x = PM, i = "numeric", j = "numeric", drop="missing"), @@ -108,7 +111,7 @@ setMethod("[", signature(x = PM, i = "numeric", j = "numeric", drop="missing"), stop("subscript out of bounds") } if(any(j < 1) | any(ncol(x) < j)) { - stop("subscript out of bounds") + stop("subscript out of bounds RANGE ... ") } if(degree(x) > 0) { x@coef[i, .rep.seq(j, ncol(x), up_to = degree(x), from = 1)] <- 0 @@ -124,7 +127,7 @@ setMethod("[", signature(x = PM, i = "numeric", j = "numeric", drop="missing"), return(x) } if(length(i) != nrow(value) || length(j) != ncol(value)) { - stop("number of items to replace is not compatable with the replacement") + stop("number of items to be replaced is not compatible with the replacement") } d <- degree(x) value_d <- degree(value) @@ -159,7 +162,7 @@ setMethod("[", signature(x = PM, i = "numeric", j = "numeric", drop="missing"), return(x) } -#' @describeIn polyMatrix replace matrix content +#' @describeIn polyMatrix-subscript replace o matrix by a new one #' #' @param value new value #' @@ -168,14 +171,14 @@ setMethod("[<-", signature(x = PM, i = "missing", j = "missing"), function(x, i, x[seq_len(nrow(x)), seq_len(ncol(x))] <- value return(x) }) -#' @describeIn polyMatrix assign rows +#' @describeIn polyMatrix-subscript assigns rows #' #' @export setMethod("[<-", signature(x = PM, i = "missing"), function(x, i, j, value) { x[seq_len(nrow(x)), j] <- value return(x) }) -#' @describeIn polyMatrix assign columns +#' @describeIn polyMatrix-subscript assigns columns #' #' @export setMethod("[<-", signature(x = PM, j = "missing"), function(x, i, j, value) { @@ -183,19 +186,21 @@ setMethod("[<-", signature(x = PM, j = "missing"), function(x, i, j, value) { return(x) }) -#' @describeIn polyMatrix assign part of matrix with number +#' @describeIn polyMatrix-subscript replace part of matrix by one number #' #' @export setMethod("[<-", signature(x = PM, i = "numeric", j = "numeric", value = "numeric"), .set.numerical.or.matrix) -#' @describeIn polyMatrix assign part of matrix with another matrix +#' @describeIn polyMatrix-subscript replace part of matrix by another numerical matrix. +#' Size of the new matrix should be same as replaced part #' #' @export setMethod("[<-", signature(x = PM, i = "numeric", j = "numeric", value = "matrix"), .set.numerical.or.matrix) -#' @describeIn polyMatrix assign part of matrix with polynomial +#' @describeIn polyMatrix-subscript replace part of matrix by one polynomail #' #' @export setMethod("[<-", signature(x = PM, i = "numeric", j = "numeric", value = P), .set.polynomial) -#' @describeIn polyMatrix assign part of matrix with another polynomial matrix +#' @describeIn polyMatrix-subscript replace part of matrix by another polunomial matrix. +#' Size of the new matrix should be same as replaced part #' #' @export setMethod("[<-", signature(x = PM, i = "numeric", j = "numeric", value = PM), .set.polyMatrix) diff --git a/R/method_trace.R b/R/method_trace.R index a3e73cf..2911639 100644 --- a/R/method_trace.R +++ b/R/method_trace.R @@ -6,7 +6,7 @@ #' #' Trace of a matrix is the sum of the diagonal elements of the given matrix. #' -#' @param x an matrix or a polynomial matrix +#' @param x a matrix or a polynomial matrix #' @return Returns the trace of the given matrix as a number or a polynomial. #' #' @details diff --git a/R/method_zero_round.R b/R/method_zero_round.R index 0af8d3a..84127e8 100644 --- a/R/method_zero_round.R +++ b/R/method_zero_round.R @@ -1,68 +1,65 @@ -#' Rounds object to zero if it's too small -#' -#' @param x an \R object -#' @param eps Minimal numerical value which will not treat as zero -#' -#' @details -#' -#' By befault eps: -#' ```{r} -#' ZERO_EPS -#' ``` -#' -#' @examples -#' -#' # numerical -#' zero.round(1) ## 1 -#' zero.round(0) ## 0 -#' zero.round(0.1, eps=0.5) ## 0 -#' zero.round(c(1, 0, .01, 1e-10)) ## 1.00 0.00 0.01 0.00 -#' -#' @seealso [is.zero()] -#' -#' @export -setGeneric("zero.round", function(x, eps = ZERO_EPS) { - if (eps <= 0) { - stop("'eps' must be greater than zero") - } - x[abs(x) < eps] <- 0 - return(x) -}) - -#' @describeIn zero.round rounding of a polynomial means rounding of each coefficient -#' -#' @examples -#' -#' # polynomials -#' zero.round(parse.polynomial("0.1 + x + 1e-7 x^2")) ## 0.1 + x -#' zero.round(parse.polynomial("0.1 + x + 1e-7 x^2"), eps=0.5) ## x -#' -#' @export -setMethod("zero.round", signature(x = P), function(x, eps = ZERO_EPS) { - return(polynom::polynomial(zero.round(as.numeric(x), eps = eps))) -}) -#' @describeIn zero.round rounding of a polynomial matrix -#' -#' @examples -#' -#' # polynomial matrix -#' zero.round(parse.polyMatrix( -#' "1 + 0.1 x, 10 + x + 3e-8 x^2, 1e-8", -#' "0.1 + x^2, .1 + 1e-8 x^4, 1e-8 x^5" -#' )) -#' ## [,1] [,2] [,3] -#' ## [1,] 1 + 0.1x 10 + x 0 -#' ## [2,] 0.1 + x^2 0.1 0 -#' -#' zero.round(parse.polyMatrix( -#' "1 + 0.1 x, 10 + x + 3e-8 x^2, 1e-8", -#' "0.1 + x^2, .1 + 1e-8 x^4, 1e-8 x^5" -#' ), eps=0.5) -#' ## [,1] [,2] [,3] -#' ## [1,] 1 10 + x 0 -#' ## [2,] x^2 0 0 -#' -#' @export -setMethod("zero.round", signature(x = PM), function(x, eps = ZERO_EPS) { - return(polyMatrix(zero.round(x@coef, eps = eps), nrow(x), ncol(x), degree(x))) -}) \ No newline at end of file +#' Rounds objects to zero if there is too small +#' +#' @param x an \R object +#' @param eps Minimal numerical value which will not be treated as zero +#' +#' @details +#' +#' By befault `eps` = `{r} ZERO_EPS` +#' +#' @examples +#' +#' # numerical +#' zero.round(1) ## 1 +#' zero.round(0) ## 0 +#' zero.round(0.1, eps=0.5) ## 0 +#' zero.round(c(1, 0, .01, 1e-10)) ## 1.00 0.00 0.01 0.00 +#' +#' @seealso [is.zero()] +#' +#' @export +setGeneric("zero.round", function(x, eps = ZERO_EPS) { + if (eps <= 0) { + stop("'eps' must be greater than zero") + } + x[abs(x) < eps] <- 0 + return(x) +}) + +#' @describeIn zero.round rounding of a polynomial means rounding of each coefficient +#' +#' @examples +#' +#' # polynomials +#' zero.round(parse.polynomial("0.1 + x + 1e-7 x^2")) ## 0.1 + x +#' zero.round(parse.polynomial("0.1 + x + 1e-7 x^2"), eps=0.5) ## x +#' +#' @export +setMethod("zero.round", signature(x = P), function(x, eps = ZERO_EPS) { + return(polynom::polynomial(zero.round(as.numeric(x), eps = eps))) +}) +#' @describeIn zero.round rounding of a polynomial matrix +#' +#' @examples +#' +#' # polynomial matrix +#' zero.round(parse.polyMatrix( +#' "1 + 0.1 x, 10 + x + 3e-8 x^2, 1e-8", +#' "0.1 + x^2, .1 + 1e-8 x^4, 1e-8 x^5" +#' )) +#' ## [,1] [,2] [,3] +#' ## [1,] 1 + 0.1x 10 + x 0 +#' ## [2,] 0.1 + x^2 0.1 0 +#' +#' zero.round(parse.polyMatrix( +#' "1 + 0.1 x, 10 + x + 3e-8 x^2, 1e-8", +#' "0.1 + x^2, .1 + 1e-8 x^4, 1e-8 x^5" +#' ), eps=0.5) +#' ## [,1] [,2] [,3] +#' ## [1,] 1 10 + x 0 +#' ## [2,] x^2 0 0 +#' +#' @export +setMethod("zero.round", signature(x = PM), function(x, eps = ZERO_EPS) { + return(polyMatrix(zero.round(x@coef, eps = eps), nrow(x), ncol(x), degree(x))) +}) diff --git a/R/ops.R b/R/ops.R new file mode 100644 index 0000000..b174758 --- /dev/null +++ b/R/ops.R @@ -0,0 +1,15 @@ +#' Arithmetic Operators +#' +#' These unary and binary operators perform arithmetical operations on polynomial or numerical marices. +#' +#' @param e1,e2 first and second operands +#' +#' @details +#' Both operands can be: +#' * numerical scalar +#' * polynomial scalar +#' * numerical matrix +#' * polynomial matrix +#' +#' @name polyMatrix-Arith +NULL diff --git a/R/ops_addition.R b/R/ops_addition.R index a5005d0..cf7a920 100644 --- a/R/ops_addition.R +++ b/R/ops_addition.R @@ -1,13 +1,15 @@ -# Title : adidiotnal +# Title : addition # Created by: namezys # Created on: 2020. 10. 25. -#' @describeIn polyMatrix summation with polynomial matrix +#' @describeIn polyMatrix-Arith unary `+` +#' @return Unary `+` return same object. #' #' @export setMethod("+", signature(e1 = PM, e2 = "missing"), function(e1, e2) { e1 }) -#' @describeIn polyMatrix summation of polynomial matrices +#' @rdname polyMatrix-Arith +#' @return Binary `+` with two matrix operands returns elementwise summation. #' #' @export setMethod("+", signature(e1 = PM, e2 = PM), function(e1, e2) { @@ -27,7 +29,8 @@ setMethod("+", signature(e1 = PM, e2 = PM), function(e1, e2) { return(polyMatrix(bc, nrow(e1), ncol(e1), d)) }) -#' @describeIn polyMatrix summation of polynomial matrix and scalar polynomial +#' @rdname polyMatrix-Arith +#' @return Binary `+` with matrix and scalar operands returns elementwise summation with scalar. #' #' @export setMethod("+", signature(e1 = PM, e2 = P), function(e1, e2) { @@ -43,17 +46,19 @@ setMethod("+", signature(e1 = PM, e2 = P), function(e1, e2) { return(polyMatrix(coef, nrow(e1), nc, res_d)) }) -#' @describeIn polyMatrix summation of polynomial matrix and scalar nummber +#' @rdname polyMatrix-Arith #' #' @export setMethod("+", signature(e1 = PM, e2 = "numeric"), function(e1, e2) { e1 + polynom::polynomial(e2) }) -#' @describeIn polyMatrix summation of polynomial matrix and numerical matrix + +#' @rdname polyMatrix-Arith #' #' @export setMethod("+", signature(e1 = PM, e2 = "matrix"), function(e1, e2) { e1 + polyMatrix(e2, nrow(e2), ncol(e2)) }) -#' @describeIn polyMatrix summation of polynomial matrix + +#' @rdname polyMatrix-Arith #' #' @export setMethod("+", signature(e1 = "ANY", e2 = PM), function(e1, e2) { e2 + e1 }) diff --git a/R/ops_matrix_mult.R b/R/ops_matrix_mult.R index b32426e..7de4407 100644 --- a/R/ops_matrix_mult.R +++ b/R/ops_matrix_mult.R @@ -2,10 +2,13 @@ # Created by: namezys # Created on: 2020. 10. 25. -#' @describeIn polyMatrix matrix multiplicatoin of polynomial matrices +#' Matrix multiplication #' -#' @param y second argument +#' Matrix multiplication accepts both polynomial and numerical matrices. #' +#' @param x,y first and second operands +#' +#' @rdname polyMatrix-mmult #' @export setMethod("%*%", signature(x = PM, y = PM), function(x, y) { if(ncol(x) != nrow(y)) { @@ -27,11 +30,11 @@ setMethod("%*%", signature(x = PM, y = PM), function(x, y) { } return(polyMatrix(coef, nrow(x), ncol(y), degree(x) + degree(y))) }) -#' @describeIn polyMatrix matrix multiplicatoin of polynomial and numerical matrices +#' @rdname polyMatrix-mmult #' #' @export setMethod("%*%", signature(x = PM, y = "matrix"), function(x, y) { x %*% polyMatrix(y, nrow(y), ncol(y)) }) -#' @describeIn polyMatrix matrix multiplicatoin of numerical and polynomial matrices +#' @rdname polyMatrix-mmult #' #' @export setMethod("%*%", signature(x = "matrix", y = PM), function(x, y) { polyMatrix(x, nrow(x), ncol(x)) %*% y }) diff --git a/R/ops_multiplication.R b/R/ops_multiplication.R index 7595d41..5f0c545 100644 --- a/R/ops_multiplication.R +++ b/R/ops_multiplication.R @@ -6,7 +6,7 @@ return(polyMatrix(e1@coef * e2, nrow(e1), ncol(e1), degree(e1))) } -.mult.polyMatrix.polinomial <- function(e1, e2) { +.mult.polyMatrix.polynomial <- function(e1, e2) { res_d <- degree(e1) + degree(e2) src_c_idx <- seq_len(ncol(e1@coef)) nc <- ncol(e1) @@ -18,25 +18,27 @@ return(polyMatrix(coef, nrow(e1), nc, res_d)) } -.mult.matrix.polinomial <- function (e1, e2) { - return(.mult.polyMatrix.polinomial(polyMatrix(e1, nrow(e1), ncol(e1), 0), e2)) +.mult.matrix.polynomial <- function (e1, e2) { + return(.mult.polyMatrix.polynomial(polyMatrix(e1, nrow(e1), ncol(e1), 0), e2)) } -#' @describeIn polyMatrix scalar multiplication with number +#' @rdname polyMatrix-Arith +#' +#' @return Binary `*` is elementwise multiplication with matrix or scalar operands. #' #' @export setMethod("*", signature(e1 = PM, e2 = "numeric"), .mult.polyMatrix.numeric) -#' @describeIn polyMatrix scalar multiplication with polynomial +#' @rdname polyMatrix-Arith #' #' @export -setMethod("*", signature(e1 = PM, e2 = P), .mult.polyMatrix.polinomial) -#' @describeIn polyMatrix scalar multiplication of polynomial mattrices elementwise +setMethod("*", signature(e1 = PM, e2 = P), .mult.polyMatrix.polynomial) +#' @rdname polyMatrix-Arith #' #' @export setMethod("*", signature(e1 = PM, e2 = PM), function(e1, e2) { stop("Per element multiplication for polyMatrix isn't supported") }) -#' @describeIn polyMatrix scalar multiplication +#' @rdname polyMatrix-Arith #' #' @export setMethod("*", signature(e1 = "ANY", e2 = PM), function(e1, e2) { e2 * e1 }) diff --git a/R/ops_substraction.R b/R/ops_subtraction.R similarity index 66% rename from R/ops_substraction.R rename to R/ops_subtraction.R index 92c98d4..fb6bb5b 100644 --- a/R/ops_substraction.R +++ b/R/ops_subtraction.R @@ -4,11 +4,14 @@ # Created on: 2020. 10. 25. -#' @describeIn polyMatrix substractioin +#' @describeIn polyMatrix-Arith unary `-` +#' @return Unary `-` return a matrix with changed sign. #' #' @export setMethod("-", signature(e1 = PM, e2 = PM), function(e1, e2) { e1 + (-e2) }) -#' @describeIn polyMatrix substractioin + +#' @rdname polyMatrix-Arith +#' @return Binary '-' of matrices or scalar operands returns matrix subtraction. #' #' @export setMethod("-", signature(e1 = PM, e2 = "ANY"), function(e1, e2) { @@ -17,7 +20,7 @@ setMethod("-", signature(e1 = PM, e2 = "ANY"), function(e1, e2) { } return(e1 + -e2) }) -#' @describeIn polyMatrix substractioin +#' @rdname polyMatrix-Arith #' #' @export setMethod("-", signature(e1 = "ANY", e2 = PM), function(e1, e2) { e1 + -e2 }) diff --git a/R/parser.R b/R/parser.R index 2ad3d70..50f9077 100644 --- a/R/parser.R +++ b/R/parser.R @@ -107,6 +107,7 @@ #' #' @return new polynomial as `polynom::polynomial` object #' +#' @seealso [parse.polyMatrix()] #' @export parse.polynomial <- function(s, var = "x") { if(!grepl("^[a-z]$", var) || var == "e") { @@ -165,6 +166,7 @@ parse.polyMatrix.prepare <- function(...) { #' ## Fail to parse polyMatrix: invalid term at position 2 in item [1, 1] #' } #' +#' @seealso [parse.polynomial()] #' @export parse.polyMatrix <- function(..., var = "x") { # use "..." to suppress name hints in PyCharm diff --git a/R/polyMatrix-package.R b/R/polyMatrix-package.R new file mode 100644 index 0000000..960c426 --- /dev/null +++ b/R/polyMatrix-package.R @@ -0,0 +1,29 @@ +#' Implementation of matrices of polynomials +#' +#' @details +#' +#' This package add transperent support of matrices of polynomials to \R language. +#' +#' @section Input: +#' +#' * low level input of matrix: [polyMatrix::polyMatrix()] +#' * string ibpuy of polynomial: [polyMatrix::parse.polynomial()] +#' * string input of matrix: [polyMatrix::parse.polyMatrix()] +#' +#' +#' @section Output: +#' +#' Matrices of polynomials uses same format as numerical matrices +#' +#' @section Operators: +#' +#' Basic arithmetic operations were implemented. +#' +#' @section Functions: +#' +#' The most important matrix functions are implemented: +#' * the determinant [polyMatrix::det()] +#' +#' @aliases polyMatrix-package +#' @keywords internal +"_PACKAGE" \ No newline at end of file diff --git a/man/GCD.Rd b/man/GCD.Rd index 211303e..98fbd2a 100644 --- a/man/GCD.Rd +++ b/man/GCD.Rd @@ -10,14 +10,14 @@ GCD(...) \S4method{GCD}{polyMatrix}(...) } \arguments{ -\item{...}{an list of polynomial objects} +\item{...}{a list of polynomial objects} } \description{ The greatest common divisor of polynomials or polynomial matrices. } \section{Methods (by class)}{ \itemize{ -\item \code{polyMatrix}: the greatest common divisor of all elements of the polynomial matrice +\item \code{polyMatrix}: the greatest common divisor of all elements of the polynomial matrix }} \examples{ diff --git a/man/LCM.Rd b/man/LCM.Rd index 0fc7687..ffc4b08 100644 --- a/man/LCM.Rd +++ b/man/LCM.Rd @@ -10,7 +10,7 @@ LCM(...) \S4method{LCM}{polyMatrix}(...) } \arguments{ -\item{...}{an list of polynomial objects} +\item{...}{a list of polynomial objects} } \description{ The least common multiple of polynomials or polynomial matrices. diff --git a/man/adjoint.Rd b/man/adjoint.Rd index 6746aa4..833c218 100644 --- a/man/adjoint.Rd +++ b/man/adjoint.Rd @@ -3,21 +3,21 @@ \name{adjoint} \alias{adjoint} \alias{adjoint,polyMatrix-method} -\title{Adjugate or classical adjoint of a square matrix} +\title{Adjungate or classical adjoint of a square matrix} \usage{ adjoint(x) \S4method{adjoint}{polyMatrix}(x) } \arguments{ -\item{x}{an matrix} +\item{x}{a matrix} } \description{ -The adjugate or classical adjoint of a square matrix is the transpose of its cofactor matrix. -It is also occasionally known as adjunct matrix,[ though this nomenclature appears to have decreased in usage. +The adjungate or classical adjoint of a square matrix is the transpose of its cofactor matrix. +It is also occasionally known as adjunct matrix, though this nomenclature appears to have been decreased in usage. } \section{Methods (by class)}{ \itemize{ -\item \code{polyMatrix}: adjugate of polynomial matrix +\item \code{polyMatrix}: adjungate of polynomial matrix DON'T UNDERSTAND!!! }} diff --git a/man/cbind.Rd b/man/cbind.Rd index e7e9330..c2ef0ff 100644 --- a/man/cbind.Rd +++ b/man/cbind.Rd @@ -3,30 +3,30 @@ \name{cbind} \alias{cbind} \alias{rbind} -\title{Combine polynial matrices by rows or coluns} +\title{Combine polynomial matrices by rows or columns} \usage{ cbind(..., deparse.level = 1) rbind(..., deparse.level = 1) } \arguments{ -\item{...}{(generalzed) vectors or mmatrices. -If any of objects are polynomail matrix} +\item{...}{(generalized) vectors or matrices. +If any of the objects is a polynomail matrix} -\item{deparse.level}{details in base function, polynomial matrices doesn't use it} +\item{deparse.level}{details in the base function, polynomial matrices doesn't use this argument} } \value{ -if at least one argument is a polynomail matrix, -the result will be combined polynomial matrix. -Overwise, base package implementatioon \code{\link[base:cbind]{base::cbind()}} or \code{\link[base:cbind]{base::rbind()}} +if at least one argument is a polynomial matrix, +the result will be a combined polynomial matrix. +Otherwise, the base package implementation \code{\link[base:cbind]{base::cbind()}} or \code{\link[base:cbind]{base::rbind()}} will be called. } \description{ -Combine polynial matrices by rows or coluns +Combine polynomial matrices by rows or columns } \section{Functions}{ \itemize{ -\item \code{rbind}: row based bind +\item \code{rbind}: row based bind DON'T UNDERSTAND.. !!! }} \seealso{ diff --git a/man/charpolynom.Rd b/man/charpolynom.Rd index 281c7f1..5a622b5 100644 --- a/man/charpolynom.Rd +++ b/man/charpolynom.Rd @@ -10,7 +10,7 @@ \alias{degree,polyMatrixCharPolynomial-method} \alias{predict,polyMatrixCharPolynomial-method} \alias{show,polyMatrixCharPolynomial-method} -\title{Characteristic polynomial of matrix} +\title{Characteristic polynomial of a matrix} \usage{ charpolynom(x) @@ -31,21 +31,21 @@ charpolynom(x) \arguments{ \item{x}{an matrix} -\item{i}{the degree to extract polinomial coefficient} +\item{i}{the degree of the polynomial coefficient to be extract} \item{object}{an \R object} -\item{newdata}{the value to evaluate} +\item{newdata}{the value to be evaluated} } \value{ When the input is a numerical matrix of \code{matrix} class -then the value is a \code{polynomial} object. +the value is a \code{polynomial} object. When the input is a \code{polyMatrix} object -then a value is \code{polyMatrixCharClass} class object, +then the value is \code{polyMatrixCharClass} class object, } \description{ -Characteristic polynomial of matrix +Characteristic polynomial of a matrix } \details{ The characteristic polynom of a polynomial matrix is a polynom with polynomial coefficients. @@ -56,16 +56,16 @@ The characteristic polynom of a polynomial matrix is a polynom with polynomial c \item \code{polynomial}: for polynomial it treats as a matrix 1x1 -\item \code{polyMatrix}: for polynomial matrix it has polynomial coefficients +\item \code{polyMatrix}: for polynomial matrix has polynomial coefficients -\item \code{x = polyMatrixCharPolynomial,i = ANY}: get polynomial coefficient of characteristic +\item \code{x = polyMatrixCharPolynomial,i = ANY}: get polynomial coefficient of characteristic polynomial -\item \code{polyMatrixCharPolynomial}: the degree of char polynomail of polynomial matrix +\item \code{polyMatrixCharPolynomial}: the degree of char polynomial of polynomial matrix -\item \code{polyMatrixCharPolynomial}: value of char polynomail in polynomial point +\item \code{polyMatrixCharPolynomial}: the value of char polynomial in a polynomial point -\item \code{polyMatrixCharPolynomial}: prints out a text representation of a characteristic polinomial of -polinomial matrix +\item \code{polyMatrixCharPolynomial}: prints out a text representation of a characteristic polynomial of +a polynomial matrix }} \examples{ diff --git a/man/cofactor.Rd b/man/cofactor.Rd index d1ee8e7..086cc7a 100644 --- a/man/cofactor.Rd +++ b/man/cofactor.Rd @@ -2,20 +2,20 @@ % Please edit documentation in R/method_adjoint.R \name{cofactor} \alias{cofactor} -\title{Cofactor of matrix} +\title{Cofactor of a matrix} \usage{ cofactor(x, r, c) } \arguments{ -\item{x}{an matrix} +\item{x}{a matrix} -\item{r, c}{the row and column} +\item{r, c}{the rows and columns} } \value{ -cofactor which is number or polynomial +cofactor which is a number or a polynomial } \description{ -Cofactor of matrix +Cofactor of a matrix } \seealso{ \code{\link[=adjoint]{adjoint()}} diff --git a/man/degree.Rd b/man/degree.Rd index 0b2fde3..e2054b3 100644 --- a/man/degree.Rd +++ b/man/degree.Rd @@ -6,7 +6,7 @@ \alias{degree,matrix-method} \alias{degree,polynomial-method} \alias{degree,polyMatrix-method} -\title{Gets maximum degree of polynomial objects} +\title{Gets the maximum degree of polynomial objects} \usage{ degree(x) @@ -29,10 +29,9 @@ for polynomial objects. Returns the maximum degree as an integer number. } \details{ -By default, this function raises -error for unknown type of object. +By default, this function raises error for unknown type of object. -A numerical scalar has zero degree. +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. diff --git a/man/diag.Rd b/man/diag.Rd index 12581aa..d6a3134 100644 --- a/man/diag.Rd +++ b/man/diag.Rd @@ -16,20 +16,20 @@ diag(x = 1, nrow, ncol, names = TRUE) \arguments{ \item{x}{a polynomial matrix, or a polynomial, or an \R object} -\item{nrow, ncol}{optional dimensions for the result when x is not a matrix.} +\item{nrow, ncol}{optional dimensions for the result when x is not a matrix} -\item{names}{not usedd} +\item{names}{not used for polynomial matrices} } \description{ Polynomial matrix Diagonals Extract or construct a diagonal polynomial matrix. } \details{ -In case of polynomail objets, \code{diag} has 2 distinct usage: +In case of polynomial objects, \code{diag} has 2 distinct usage: \itemize{ -\item \code{x} is a polynomial, it returns a polynomial matrix the given diagonal +\item \code{x} is a polynomial, returns a polynomial matrix the given diagonal and zero off-diagonal entries. -\item \code{x} is a polynomial matrix, it returns a vector as a polynomial matrix of +\item \code{x} is a polynomial matrix, returns a vector as a polynomial matrix of diagonal elements } @@ -37,16 +37,16 @@ For polynomial, either \code{nrow} or \code{ncol} must be provided. } \section{Methods (by class)}{ \itemize{ -\item \code{polynomial}: for a polynomial, returns polynomial matrix with given diagonal +\item \code{polynomial}: for a polynomial, returns a polynomial matrix with the given diagonal -\item \code{polyMatrix}: for a polynomial matrix extract diagonal +\item \code{polyMatrix}: for a polynomial matrix extracts diagonal -For polynomial matrix, neither \code{nrow} and \code{ncol} can't be provided. +For polynomial matrix, neither \code{nrow} nor \code{ncol} cannot be provided. }} \examples{ -# numericals and numerical matrix +# numericals and numerical matrices diag(matrix(1:12, 3, 4)) ## 1 5 8 diag(9, 2, 2) ## [,1] [,2] diff --git a/man/inv.Rd b/man/inv.Rd index e366514..fa26ce4 100644 --- a/man/inv.Rd +++ b/man/inv.Rd @@ -7,13 +7,13 @@ inv(x, eps = ZERO_EPS) } \arguments{ -\item{x}{an polynomial matrix} +\item{x}{a polynomial matrix} \item{eps}{zero threshold} } \description{ -During inversion we will try to round to zero +During inversion we will try to round elememnts to zero. } \details{ -Right now only matrices with numerical determinant is supported +Right now only matrices with numerical determinant are supported. } diff --git a/man/is.polyMatrix.Rd b/man/is.polyMatrix.Rd index bca8339..a641e2d 100644 --- a/man/is.polyMatrix.Rd +++ b/man/is.polyMatrix.Rd @@ -10,7 +10,7 @@ is.polyMatrix(x) \item{x}{an \R object} } \value{ -TRUE if object is a polonial matrix +TRUE if object is a polynomial matrix } \description{ Check if object is polyMatrix diff --git a/man/is.proper.Rd b/man/is.proper.Rd index b7bf333..08cd800 100644 --- a/man/is.proper.Rd +++ b/man/is.proper.Rd @@ -13,18 +13,19 @@ is.column.proper(pm) is.row.proper(pm) } \arguments{ -\item{pm}{a polyMatrix objects} +\item{pm}{a polyMatrix object} } \value{ True if object \code{pm} is a (row-/column-) proper matrix } \description{ -Tests the proper property of polynomial matrix. +Tests the proper property of a polynomial matrix. A polynomial matrix is proper if the associeted matrix has a full rank. } \details{ -Polynomial matrix is column (row, full) proper (or reduced) if associated matrix has same rank -as the number of column (row) +A polynomial matrix is column (row, full) proper (or reduced) +if the associated matrix has the same rank +as the number of columns (rows) } \section{Functions}{ \itemize{ @@ -34,12 +35,12 @@ as the number of column (row) }} \examples{ - pm <- parse.polyMatrix( - "-1 + 7x , x", - " 3 - x + x^2, -1 + x^2 - 3 x^3" - ) - is.column.proper(pm) - is.row.proper(pm) - is.proper(pm) +pm <- parse.polyMatrix( + "-1 + 7x , x", + " 3 - x + x^2, -1 + x^2 - 3 x^3" +) +is.column.proper(pm) +is.row.proper(pm) +is.proper(pm) } diff --git a/man/is.zero.Rd b/man/is.zero.Rd index a1ff0ed..d4bcb80 100644 --- a/man/is.zero.Rd +++ b/man/is.zero.Rd @@ -4,7 +4,7 @@ \alias{is.zero} \alias{is.zero,polynomial-method} \alias{is.zero,polyMatrix-method} -\title{Test if something is zero} +\title{Tests if something is zero or not} \usage{ is.zero(x, eps = ZERO_EPS) @@ -13,9 +13,9 @@ is.zero(x, eps = ZERO_EPS) \S4method{is.zero}{polyMatrix}(x, eps = ZERO_EPS) } \arguments{ -\item{x}{The checked object} +\item{x}{An \R object} -\item{eps}{Minimal numerical value which will not treat as zero} +\item{eps}{The minimal numerical value which will not be treated as zero} } \value{ TRUE if the object can be treat as zero @@ -25,33 +25,34 @@ Generic function to check if we can treat on object as being zero. For matrices the result is a matrix of the same size. } \details{ -Different type of objects can be treated as a zero in different ways: +Different type of objects can be treated as zero in different ways: \itemize{ -\item Numerical types can be compare by absolute value with \code{eps}. -\item Customer types should define an an customer method. +\item Numerical types can be compared by absolute value with \code{eps}. +\item Other types should define its own method. } -By befault eps:\if{html}{\out{