0

if I have a matrix that is including variables as entries, how can I obtain the determinant? It does not seem like R can handle non-numeric entries in matrices in calculations.

for ex.

    z <- matrix(c(1,1,1,"d"),nrow = 2)

then I would want the answer to be like det(z)=d-1 i.e in as a polynomial including the variable d. is this possible with the "det" function in r?

Yung Gud
  • 67
  • 6
  • 1
    Check out https://stackoverflow.com/questions/39820161/handling-symbolic-matrices-in-r-as-in-matlab for handling symbolic matrices in R – bala83 Mar 24 '18 at 15:30

1 Answers1

0

This works:

> library(Ryacas)
> yacas("M := {{1, 1}, {1, d}}")
expression(list(list(1, 1), list(1, d)))
> yacas("Determinant(M)")
expression(d - 1)

However I don't know whether there's a convenient way to defined the matrix M directly from its value in R. Perhaps it's possible; there are some docs to check...


EDIT 2020-02

With the new Ryacas package:

M <- matrix(c("1", "1", "1", "d"), nrow = 2)
yac_assign(ysym(M), "M")
yac_str("Determinant(M)")
# [1] "d-1"
Stéphane Laurent
  • 75,186
  • 15
  • 119
  • 225