linalg: Do linear algebra operation

linalgR Documentation

Do linear algebra operation

Description

Performs various linear algebra operations like finding the inverse, the QR decomposition, the eigenvectors and the eigenvalues.

Usage

columnspace(x, matrix = TRUE)

nullspace(x, matrix = TRUE)

rowspace(x, matrix = TRUE)

orthcompspace(x, x2 = NULL)

intersectionspace(x, x2)

leftnullspace(x)

singular_values(x)

inv(x, method = c("ge", "gauss", "lu", "cf", "yac"))

eigenval(x)

eigenvec(x)

eigen_(x)

GramSchmidt(x)

pinv(x)

QRdecomposition(x)

## S4 method for signature 'caracas_symbol'
qr(x)

## S4 method for signature 'caracas_symbol'
chol(x, ...)

## S4 method for signature 'QRdecomposition'
qr.Q(qr)

## S4 method for signature 'QRdecomposition'
qr.R(qr)

## S4 method for signature 'caracas_symbol,ANY'
determinant(x, logarithm = TRUE, ...)

LUdecomposition(x)

svd_(x, ...)

det(x, ...)

trace_(x)

Arguments

x, x2

A matrix for which a property is requested.

matrix

When relevant should a matrix be returned.

method

The default works by Gaussian elimination. The alternatives are $LU$ decomposition (lu), the cofactor method (cf), and Ryacas (yac).

...

Auxillary arguments.

qr

A QRdecomposition object.

logarithm

logical.

Value

Returns the requested property of a matrix.

See Also

do_la()

Examples

if (has_sympy()) {
  A <- matrix(c("a", "0", "0", "1"), 2, 2) |> as_sym()
  
  QRdecomposition(A)
  LUdecomposition(A)
  #chol(A) # error
  chol(A, hermitian = FALSE)
  eigenval(A)
  eigenvec(A)
  inv(A)
  det(A)
  rowspace(A)
  columnspace(A)
  nullspace(A)
  
  ## Matrix inversion:
  d <- 3
  m <- matrix_sym(d, d)
  print(system.time(inv(m)))                  ## Gauss elimination
  print(system.time(inv(m, method="cf")))     ## Cofactor 
  print(system.time(inv(m, method="lu")))     ## LU decomposition
  if (requireNamespace("Ryacas")){
    print(system.time(inv(m, method="yac")))  ## Use Ryacas
  }

  A <- matrix(c("a", "b", "c", "d"), 2, 2) |> as_sym()
  evec <- eigenvec(A)
  evec
  evec1 <- evec[[1]]$eigvec
  evec1
  simplify(evec1)
  
  lapply(evec, function(l) simplify(l$eigvec))

  A <- as_sym("[[1, 2, 3], [4, 5, 6]]")
  pinv(A)
}


r-cas/caracas documentation built on Feb. 28, 2025, 3:39 p.m.