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'
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 ?
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With