inst/doc/a05-extend-caracas.R

## ---- include = FALSE---------------------------------------------------------
knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>"
)

## ---- message=FALSE-----------------------------------------------------------
library(caracas)

## ---- include = FALSE---------------------------------------------------------
inline_code <- function(x) {
  x
}

if (!has_sympy()) {
  # SymPy not available, so the chunks shall not be evaluated
  knitr::opts_chunk$set(eval = FALSE)
  
  inline_code <- function(x) {
    deparse(substitute(x))
  }
}

## -----------------------------------------------------------------------------
cofactor_matrix <- function(x) {
  sympy_func(x, "cofactor_matrix")
}

cofactor <- function(x, i, j) {
  # Python indexing starts at 0 - thus subtract 1 to convert from R indexing
  # to Python indexing
  sympy_func(x, "cofactor", i - 1, j - 1)
}

## -----------------------------------------------------------------------------
A <- matrix_sym(3, 3, "a")

## -----------------------------------------------------------------------------
CC <- cofactor_matrix(A)
CC
cc <- cofactor(A, 1, 1)
cc

## -----------------------------------------------------------------------------
B <- t(CC) / det(A)
P <- A %*% B
P %>% simplify()

Try the caracas package in your browser

Any scripts or data that you put into this service are public.

caracas documentation built on June 22, 2024, 10:59 a.m.