Gavin Simpson
2004-Sep-13 17:47 UTC
[R] generalized eigenvalues - porting code using eig() from Matlab to R
Dear list, I am porting some Matlab routines to R. I am looking for the equivalent function in R for the Matlab function eig(), such that eig(A, B) <quote>produces a diagonal matrix D of generalized eigenvalues and a full matrix V whose columns are the corresponding eigenvectors so that A*V = B*V*D</quote>[1]. More specifically, I want to find the eigenvalues and eigenvectors of eig(ZKZt, diag(K1)) where: ZKZt [,1] [,2] [,3] [,4] [1,] 0.024326360 -0.0087060425 -0.029307513 -0.0131484613 [2,] -0.001316161 0.0028641451 0.003249924 0.0003892546 [3,] -0.016591044 0.0061132182 0.021493284 0.0083083670 [4,] -0.006419155 -0.0002713207 0.004564305 0.0044508397 and diag(K1) [,1] [,2] [,3] [,4] [1,] 0.2307692 0.0000000 0.0000000 0.0000000 [2,] 0.0000000 0.2307692 0.0000000 0.0000000 [3,] 0.0000000 0.0000000 0.3076923 0.0000000 [4,] 0.0000000 0.0000000 0.0000000 0.2307692 How would I go about doing this in R? Thanks in advance, Gavin [1] http://www.mathworks.com/access/helpdesk/help/techdoc/ref/eig.html?cmdname=eig -- %~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~% Gavin Simpson [T] +44 (0)20 7679 5522 ENSIS Research Fellow [F] +44 (0)20 7679 7565 ENSIS Ltd. & ECRC [E] gavin.simpson at ucl.ac.uk UCL Department of Geography [W] http://www.ucl.ac.uk/~ucfagls/cv/ 26 Bedford Way [W] http://www.ucl.ac.uk/~ucfagls/ London. WC1H 0AP. %~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%
Prof Brian Ripley
2004-Sep-13 18:37 UTC
[R] generalized eigenvalues - porting code using eig() from Matlab to R
On Mon, 13 Sep 2004, Gavin Simpson wrote:> I am porting some Matlab routines to R. I am looking for the equivalent > function in R for the Matlab function eig(), such that eig(A, B) > <quote>produces a diagonal matrix D of generalized eigenvalues and a > full matrix V whose columns are the corresponding eigenvectors so that > A*V = B*V*D</quote>[1].So they are eigenvalues/vectors of B^{-1}A provided B is invertible, as in your example.> More specifically, I want to find the eigenvalues and eigenvectors of > eig(ZKZt, diag(K1)) where:... -- 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