Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Determinant of a complex matrix in R

Is there a way to calculate the determinant of a complex matrix?

F4<-matrix(c(1,1,1,1,1,1i,-1,-1i,1,-1,1,-1,1,-1i,-1,1i),nrow=4)
det(F4)
Error in determinant.matrix(x, logarithm = TRUE, ...) : 
  determinant not currently defined for complex matrices

library(Matrix)
 determinant(Matrix(F4))
Error in Matrix(F4) : 
  complex matrices not yet implemented in Matrix package
Error in determinant(Matrix(F4)) : 
  error in evaluating the argument 'x' in selecting a method for function 'determinant'
like image 804
George Dontas Avatar asked Jul 19 '10 16:07

George Dontas


2 Answers

If you use prod(eigen(F4)$values) I'd recommend prod(eigen(F4, only.values=TRUE)$values)
instead.

Note that the qr() is advocated to use iff you are only interested in the absolute value or rather Mod() :

 prod(abs(Re(diag(qr(x)$qr))))

gives the Mod(determinant(x))
{In X = QR, |det(Q)|=1 and the diagonal of R is real (in R at least).}

BTW: Did you note the caveat

Often, computing the determinant is not what you should be doing to solve a given problem.

on the help(determinant) page ?

like image 170
Martin Mächler Avatar answered Sep 30 '22 16:09

Martin Mächler


If you know that the characteristic polynomial of a matrix A splits into linear factors, then det(A) is the product of the eigenvalues of A, and you can use eigen value functions like this to work around your problem. I suspect you'll still want something better, but this might be a start.

like image 24
Jan Gorzny Avatar answered Sep 30 '22 17:09

Jan Gorzny