caracasThis vignette is based on caracas version
r packageVersion("caracas"). caracas is
avavailable on CRAN at [https://cran.r-project.org/package=caracas] and on
github at [https://github.com/r-cas/caracas].
We now show different ways to create a symbolic matrix:
A <- matrix(c("a", "b", "0", "1"), 2, 2) |> as_sym()
A
A <- matrix_(c("a", "b", "0", "1"), 2, 2) # note the '_' postfix
A
A <- as_sym("[[a, 0], [b, 1]]")
A
A2 <- matrix_(c("a", "b", "c", "1"), 2, 2)
A2
B <- matrix_(c("a", "b", "0",
"c", "c", "a"), 2, 3)
B
b <- matrix_(c("b1", "b2"), nrow = 2)
D <- diag_(c("a", "b")) # note the '_' postfix
DNote that a vector is a matrix in which one of the dimensions is one.
Solve \(Ax=b\) for \(x\):
Below we present convenient functions for performing linear algebra
operations. If you need a function in SymPy for which we have not
supplied a convinience function (see https://docs.sympy.org/latest/modules/matrices/matrices.html),
you can still call it with the do_la() (short for “do
linear algebra”) function presented at the end of this section.
do_la short for “do linear algebra”
The above functions can be called:
do_la(A, "QRdecomposition") # == QRdecomposition(A)
do_la(A, "inv") # == inv(A)
do_la(A, "eigenvec") # == eigenvec(A)
do_la(A, "eigenvals") # == eigenval(A)