Singular value decomposition and determinants



next up previous contents
Next: Least squares fitting Up: Some functions returning Previous: Eigenvalues and eigenvectors

Singular value decomposition and determinants

The function svd(M) takes an arbitrary matrix argument, M, and calculates the singular value decomposition of M. This consists of a matrix of orthonormal columns U with the same column space as M, a second matrix of orthonormal columns V whose column space is the row space of M and a diagonal matrix of positive entries D such that M = U %*% D %*% t(V). D is actually returned as a vector of the diagonal elements. The result of svd(M) is actually a list of three components named d, u and v, with evident meanings.

If M is in fact square, then, it is not hard to see that

absdetM <- prod(svd(M)$d)

calculates the absolute value of the determinant of M. If this calculation were needed often with a variety of matrices it could be defined as an S-PLUS function

absdet <- function(M) prod(svd(M)$d)

after which we could use absdet() as just another S-PLUS function. As a further trivial but potentially useful example, you might like to consider writing a function, say tr(), to calculate the trace of a square matrix. [Hint: You will not need to use an explicit loop. Look again at the diag() function.]

Functions will be discussed formally later in these notes.



Erik Moledor
Tue Jan 31 21:02:18 EST 1995