Package 'RationalMatrix'

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

Help Index


'UtDU' decomposition of a rational matrix

Description

Cholesky-'UtDU' decomposition of a symmetric rational matrix.

Usage

QcholUtDU(M)

Arguments

M

a square matrix such that as.character(Mij) is a quoted integer or a quoted fraction for each entry Mij

Value

The Cholesky-'UtDU' decomposition of M in a list (see example).

Note

Symmetry is not checked! Only the lower triangular part of M is used.

Examples

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 rational matrix

Description

Determinant of a square matrix with rational entries.

Usage

Qdet(M)

Arguments

M

a square matrix such that as.character(Mij) is a quoted integer or a quoted fraction for each entry Mij

Value

A string: quoted rational number representing the determinant.

Examples

library(RationalMatrix)
M <- cbind(c("1/2", "3"), c("5/3", "-2/7"))
Qdet(M)

Inverse of a rational matrix

Description

Inverse matrix of a square rational matrix.

Usage

Qinverse(M)

Arguments

M

a square matrix such that as.character(Mij) is a quoted integer or a quoted fraction for each entry Mij

Value

A character matrix representing the inverse of M.

Examples

library(RationalMatrix)
M <- cbind(c("1/2", "3", "1"), c("5/3", "-2/7", "10/3"), c("0", "1", "2"))
Qinverse(M)

Check injectivity

Description

Checks whether a rational matrix represents an injective linear map (i.e. has trivial kernel).

Usage

QisInjective(M)

Arguments

M

a matrix such that as.character(Mij) is a quoted integer or a quoted fraction for each entry Mij

Value

A Boolean value indicating whether the linear map corresponding to M is injective.

Examples

library(RationalMatrix)
set.seed(666L)
M <- matrix(rpois(35L, 1), 5L, 7L)
QisInjective(M)

Check invertibility

Description

Checks whether a square rational matrix is invertible.

Usage

QisInvertible(M)

Arguments

M

a square matrix such that as.character(Mij) is a quoted integer or a quoted fraction for each entry Mij

Value

A Boolean value indicating whether M is invertible.

Examples

library(RationalMatrix)
set.seed(666L)
M <- matrix(rpois(25L, 1), 5L, 5L)
QisInvertible(M)

Check surjectivity

Description

Checks whether a rational matrix represents a surjective linear map.

Usage

QisSurjective(M)

Arguments

M

a matrix such that as.character(Mij) is a quoted integer or a quoted fraction for each entry Mij

Value

A Boolean value indicating whether the linear map corresponding to M is surjective.

Examples

library(RationalMatrix)
set.seed(666L)
M <- matrix(rpois(35L, 1), 7L, 5L)
QisSurjective(M)

Kernel of a rational matrix

Description

Kernel (null-space) of a rational matrix.

Usage

Qkernel(M)

Arguments

M

a matrix such that as.character(Mij) is a quoted integer or a quoted fraction for each entry Mij

Value

A character matrix representing a basis of the kernel of M. Note that this basis is not orthogonal.

Examples

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 of a rational matrix

Description

Range (column-space, image, span) of a rational matrix.

Usage

Qrange(M)

Arguments

M

a matrix such that as.character(Mij) is a quoted integer or a quoted fraction for each entry Mij

Value

A character matrix representing a basis of the range of M. Note that this basis is not orthogonal.

Examples

library(RationalMatrix)
set.seed(666L)
M <- matrix(rpois(15L, 6), 3L, 5L)
Qrange(M)

Rank of a rational matrix

Description

Returns the rank of a rational matrix.

Usage

Qrank(M)

Arguments

M

a matrix such that as.character(Mij) is a quoted integer or a quoted fraction for each entry Mij

Value

An integer, the rank of M.

Examples

library(RationalMatrix)
M <- cbind(c("1/2", "3", "1"), c("5/3", "-2/7", "10/3"), c("1", "1", "2"))
Qrank(M)