开发者

Determinant of a complex matrix in R

开发者 https://www.devze.com 2023-01-08 10:52 出处:网络
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)

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 i开发者_如何学Pythonn 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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号