Title: | Exact Matrix Algebra for Rational Matrices |
---|---|
Description: | Provides functions to deal with matrix algebra for matrices with rational entries: determinant, rank, image and kernel, inverse, Cholesky decomposition. All computations are exact. |
Authors: | Stéphane Laurent [aut, cre] |
Maintainer: | Stéphane Laurent <[email protected]> |
License: | GPL-3 |
Version: | 1.0.0 |
Built: | 2024-10-26 04:25:28 UTC |
Source: | https://github.com/stla/rationalmatrix |
Cholesky-'UtDU' decomposition of a symmetric rational matrix.
QcholUtDU(M)
QcholUtDU(M)
M |
a square matrix such that |
The Cholesky-'UtDU' decomposition of M
in a list
(see example).
Symmetry is not checked! Only the lower triangular part of
M
is used.
library(RationalMatrix) x <- matrix(c(1:5, (1:5)^2), 5, 2) x <- cbind(x, x[, 1L] + 3L*x[, 2L]) M <- crossprod(x) UtDU <- QcholUtDU(M) library(gmp) U <- as.bigq(UtDU$U) D <- matrix("0", 3L, 3L) diag(D) <- UtDU$D D <- as.bigq(D) perm <- UtDU$perm UP <- U[, perm] t(UP) %*% D %*% UP # this is `M`
library(RationalMatrix) x <- matrix(c(1:5, (1:5)^2), 5, 2) x <- cbind(x, x[, 1L] + 3L*x[, 2L]) M <- crossprod(x) UtDU <- QcholUtDU(M) library(gmp) U <- as.bigq(UtDU$U) D <- matrix("0", 3L, 3L) diag(D) <- UtDU$D D <- as.bigq(D) perm <- UtDU$perm UP <- U[, perm] t(UP) %*% D %*% UP # this is `M`
Determinant of a square matrix with rational entries.
Qdet(M)
Qdet(M)
M |
a square matrix such that |
A string: quoted rational number representing the determinant.
library(RationalMatrix) M <- cbind(c("1/2", "3"), c("5/3", "-2/7")) Qdet(M)
library(RationalMatrix) M <- cbind(c("1/2", "3"), c("5/3", "-2/7")) Qdet(M)
Inverse matrix of a square rational matrix.
Qinverse(M)
Qinverse(M)
M |
a square matrix such that |
A character matrix representing the inverse of M
.
library(RationalMatrix) M <- cbind(c("1/2", "3", "1"), c("5/3", "-2/7", "10/3"), c("0", "1", "2")) Qinverse(M)
library(RationalMatrix) M <- cbind(c("1/2", "3", "1"), c("5/3", "-2/7", "10/3"), c("0", "1", "2")) Qinverse(M)
Checks whether a rational matrix represents an injective linear map (i.e. has trivial kernel).
QisInjective(M)
QisInjective(M)
M |
a matrix such that |
A Boolean value indicating whether the linear map corresponding to
M
is injective.
library(RationalMatrix) set.seed(666L) M <- matrix(rpois(35L, 1), 5L, 7L) QisInjective(M)
library(RationalMatrix) set.seed(666L) M <- matrix(rpois(35L, 1), 5L, 7L) QisInjective(M)
Checks whether a square rational matrix is invertible.
QisInvertible(M)
QisInvertible(M)
M |
a square matrix such that |
A Boolean value indicating whether M
is invertible.
library(RationalMatrix) set.seed(666L) M <- matrix(rpois(25L, 1), 5L, 5L) QisInvertible(M)
library(RationalMatrix) set.seed(666L) M <- matrix(rpois(25L, 1), 5L, 5L) QisInvertible(M)
Checks whether a rational matrix represents a surjective linear map.
QisSurjective(M)
QisSurjective(M)
M |
a matrix such that |
A Boolean value indicating whether the linear map corresponding to
M
is surjective.
library(RationalMatrix) set.seed(666L) M <- matrix(rpois(35L, 1), 7L, 5L) QisSurjective(M)
library(RationalMatrix) set.seed(666L) M <- matrix(rpois(35L, 1), 7L, 5L) QisSurjective(M)
Kernel (null-space) of a rational matrix.
Qkernel(M)
Qkernel(M)
M |
a matrix such that |
A character matrix representing a basis of the kernel of M
.
Note that this basis is not orthogonal.
library(RationalMatrix) set.seed(666L) M <- matrix(rpois(30L, 6), 10L, 3L) M <- cbind(M, M[,1] + M[,2], M[,2] + 2L*M[,3]) Qkernel(M)
library(RationalMatrix) set.seed(666L) M <- matrix(rpois(30L, 6), 10L, 3L) M <- cbind(M, M[,1] + M[,2], M[,2] + 2L*M[,3]) Qkernel(M)
Range (column-space, image, span) of a rational matrix.
Qrange(M)
Qrange(M)
M |
a matrix such that |
A character matrix representing a basis of the range of M
.
Note that this basis is not orthogonal.
library(RationalMatrix) set.seed(666L) M <- matrix(rpois(15L, 6), 3L, 5L) Qrange(M)
library(RationalMatrix) set.seed(666L) M <- matrix(rpois(15L, 6), 3L, 5L) Qrange(M)
Returns the rank of a rational matrix.
Qrank(M)
Qrank(M)
M |
a matrix such that |
An integer, the rank of M
.
library(RationalMatrix) M <- cbind(c("1/2", "3", "1"), c("5/3", "-2/7", "10/3"), c("1", "1", "2")) Qrank(M)
library(RationalMatrix) M <- cbind(c("1/2", "3", "1"), c("5/3", "-2/7", "10/3"), c("1", "1", "2")) Qrank(M)