[R] SVD and spectral decompositions of a hermitian matrix

Prof Brian Ripley ripley at stats.ox.ac.uk
Thu Jul 3 20:21:27 CEST 2003


On Thu, 3 Jul 2003, Ravi Varadhan wrote:

> I create a hermitian matrix 

You didn't succeed, if you meant Hermitian.

> and then perform its singular value 
> decomposition. But when I put it back, I don't get the original 
> hermitian matrix.  I am having the same problem with spectral value 
> decomposition as well.
> 
> I am using R 1.7.0 on Windows.  Here is my code:
> 
> X <- matrix(rnorm(16)+1i*rnorm(16),4)
> X <- X + t(X)
> X[upper.tri(X)] <- Conj(X[upper.tri(X)])

and I get 

> X - Conj(t(X))
            [,1]        [,2]        [,3]        [,4]
[1,] 0-7.044789i 0+0.000000i 0+0.000000i 0+0.000000i
[2,] 0+0.000000i 0+4.255175i 0+0.000000i 0+0.000000i
[3,] 0+0.000000i 0+0.000000i 0+6.163605i 0+0.000000i
[4,] 0+0.000000i 0+0.000000i 0+0.000000i 0+3.021553i

so X is not Hermitian.

> Y <- La.svd(X)
> Y$u %*% diag(Y$d) %*% t(Y$v)   # this doesn't give back X

The result has component vt, not v: you can't read the help page!

> Y$u %*% diag(Y$d) %*% Y$v      # this works fine.
but is really matching Y$u %*% diag(Y$d) %*% Y$vt

> Z <- La.eigen(X)   # the eigen values should be real, but are not.

The matrix is not Hermitian.

> Z$vec %*% diag(Z$val) %*% t(Z$vec)   # this doesn't give back X

Nor should it: for a Hermitian matrix try

Z$vec %*% diag(Z$val) %*% Conj(t(Z$vec))

> The help for "La.svd" says that the function return U, D, and V such 
> that X = U D V' 

It doesn't: please work on improving your reading skills.

> Furthermore, the help for "La.eigen" says that if the 
> argument "symmetric" is not specified, the matrix is inspected for 
> symmetry, so I expect that I should get real eigen values to a 
> hermitian matrix. 

Yes, so check your matrix!

> Are there any problems with these 2 functions, or 
> what is it that I am not understanding? 

There is now no real point in using La.svd() and La.eigen() rather than 
svd() and eigen().


-- 
Brian D. Ripley,                  ripley at stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595




More information about the R-help mailing list