How can I efficiently compute the determinant of a square diagonal matrix? In this case, the determinant is simply the product of each element in the diagonal. I can think of a couple options that might work:
- I could store the diagonal of the matrix as a vector and apply a
reduce
operation to it (would I have to write my ownreduce
?). I think that one could implement a “poor man’s reduce” usingmap
. - I could implement my own class,
DiagonalMatrix
, and add adeterminant
function to it.