[R] SVD and spectral decompositions of a hermitian matrix

Ravi Varadhan rvaradha at jhsph.edu
Thu Jul 3 22:54:12 CEST 2003


Many thanks to Prof. Ripley for the help.  The problem was that my 
matrix wasn't Hermitian since I didn't ensure that the diagonals were 
real.

Best,
Ravi.  

----- Original Message -----
From: Prof Brian Ripley <ripley at stats.ox.ac.uk>
Date: Thursday, July 3, 2003 2:21 pm
Subject: Re: [R] SVD and spectral decompositions of a hermitian matrix

> 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
> 
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://www.stat.math.ethz.ch/mailman/listinfo/r-help
>




More information about the R-help mailing list