-1

does anyone of you knows a way to use R so to calculate and display the characteristic polynomial of the eigenvalues of a generic matrix composed by chr elements? say i.e.

m <- matrix(c('a','b','c','d','e','f','g','h','i','l','m','n'),4,4) 

Please consider that I have to apply this method to a very large matrix

Thank you in advance

David Arenburg
  • 91,361
  • 17
  • 137
  • 196
Shatz
  • 11
  • 2
  • It might help to include some details on what exactly is the characteristic polynomial of the eigenvalues of a generic matrix composed by chr elements. Most people here are programmers and not acquainted with esoteric mathematics in character space... – Joris Meys Sep 04 '14 at 12:55
  • 1
    I *think* (??) the OP might be looking for a symbolic calculation (which is not possible in R except by using an interface to an external symbolic calculator such as Yacas) – Ben Bolker Sep 04 '14 at 13:02
  • Thanks for you suggestion, but I think brief definitions might not help who is not acquainted with matrix algebra (or consider general method resolutions as esoteric mathematics in character space...), and of course I cannot give here a class on this topic. Maybe only specialized users may reply. – Shatz Sep 04 '14 at 13:11
  • By the way: Eigenvalue: Let A be a square matrix. A non-zero vector C is called an eigenvector of A if and only if there exists a number (real or complex) b such that A*C=b*C If such a number b exists, it is called an eigenvalue of A and the vector C is called eigenvector associated to the eigenvalue b. Characteristic polynomial of an eigenvalue: it is given by det(A-b*I)=0 where I is an Identity matrix. – Shatz Sep 04 '14 at 13:12
  • Yes @BenBolker this is exactly what I'm looking for. So are you suggesting that no symbolic calculator exists in R-packages and I should switch to another software? Do you suggest Yacas? In your experience do you think also Matlab can be a choice? – Shatz Sep 04 '14 at 13:18
  • We know what an eigenvalue is and most of us are able to calculate eigenvalues "by hand". However, your question doesn't make it obvious that you are looking for symbolic calculation. The only reason I can think of doing something like that is to avoid doing your homework. I advise against that, but if you must you can install yacas and use the [Ryacas](http://cran.r-project.org/web/packages/Ryacas/index.html) package. – Roland Sep 04 '14 at 13:29
  • it's also the case that the characteristic polynomial of a large matrix is going to be really, really ugly, see e.g. http://www.wolframalpha.com/input/?i=characteristic+polynomial+{{a%2Cb%2Cc}%2C{d%2Ce%2Cf}%2C{g%2Ch%2Ci}} – Ben Bolker Sep 04 '14 at 13:41
  • I don't have a lot of experience with MATLAB but I believe it does have a symbolic calculation toolbox ... again, though, I think you may run into a lot of trouble trying to do this for large matrices. – Ben Bolker Sep 04 '14 at 13:43
  • Dear @BenBolker and thank you very much for your sugestions. I will take a look to Yacas. – Shatz Sep 04 '14 at 14:10
  • Dear @Roland thank you for the suggestions and I'm sorry if my question was not clear. Let me add two things: 1) it would be great to be in those years in which I had homework to do, 2) I'm sorry for you if the only reason you can think of doing something like that is to avoid doing your homework, it is very sad. I wish you better and kinder thoughts from now on. – Shatz Sep 04 '14 at 14:24
  • I actually agree with @Roland: there are lots of interesting linear algebra problems to tackle, but it's hard to understand what one is going to gain simply through a brute-force symbolic computation of the characteristic polynomial of an arbitrary, large matrix. It would be interesting if you could edit your question to include more context. – Ben Bolker Sep 04 '14 at 15:00
  • Dear @BenBolker if a matrix represents a network, eigenvalues may be used to compute Nash Equilibria in that network. I am working on this approach in a theoretical paper, and I want to include the characteristic polynomial of the matrix so to have general results. But given that I'm working with matrices very large (i.e. 20x20), computing manually this equation would require too much time. Thus I'm looking for an easier system. – Shatz Sep 04 '14 at 15:49
  • 1
    I just don't see what insight you're going to get out of the full 20-by-20 characteristic equation ... – Ben Bolker Sep 04 '14 at 16:06

1 Answers1

1

You can do this with the Ryacas package, but you'll have to jump through the necessary hoops to install Yacas on your system first.

library("Ryacas")
m <- matrix(letters[1:16],4,byrow=TRUE)
yrow <- function(x) paste0("{",paste(x,collapse=","),"}")
yrow(m[1,]) ##  "{a,b,c,d}"
ymat <- function(x) yrow(apply(x,1,yrow))
cheqstr <-  function(x) {
    paste0("Expand(CharacteristicEquation(",
           ymat(x),",x),x)")
}
yacas(cheqstr(m))
## (a-x)*(f-x)*(k-x)*(p-x)-(a-x)*(f-x)*l*o+(a-x)*h*j*o-d*e*j*o-
## (a-x)*g*j*(p-x)+(a-x)*g*l*n-(a-x)*h*(k-x)*n+d*e*(k-x)*n+c*e*j*(p-x)-
## c*e*l*n+c*h*i*n-d*g*i*n-b*e*(k-x)*(p-x)+b*e*l*o-b*h*i*o+d*(f-x)*i*o+
## b*g*i*(p-x)-b*g*l*m+b*h*(k-x)*m-d*(f-x)*(k-x)*m-c*(f-x)*i*(p-x)+
## c*(f-x)*l*m-c*h*j*m+d*g*j*m;
Ben Bolker
  • 211,554
  • 25
  • 370
  • 453