Dear Statalisters,
I'm just getting started with Mata, so apologies upfront: I have, I think, a very simple question: I'm calculating eigenvectors and eigenvalues of square matrix Cmat. Here's an example for 3x3 matrix:
The eigenvectors are sorted by their absolute eigenvalues in descending order (the default), but I'd like to have the eigenvectors sorted by their actual eigenvalues, e.g.:
The first column of the eigenvector matrix should therefore represent the eigenvector with the largest value (4.86), the second column the eigenvector with the second largest value (.57) and so on.
Thank you for your help!
Best,
Ali
I'm just getting started with Mata, so apologies upfront: I have, I think, a very simple question: I'm calculating eigenvectors and eigenvalues of square matrix Cmat. Here's an example for 3x3 matrix:
Code:
: Cmat = (2,2,3\1,2,2\1,2,0) : : // Eigenvalues and Eigenvectors : eigenvalues = . : eigenvectors = . : : eigensystem(Cmat, eigenvectors, eigenvalues,) : // Extract real part of eigenvalues and eigenvectors : eigenvectors = Re(eigenvectors) : eigenvalues = Re(eigenvalues') : : : eigenvectors 1 2 3 +----------------------------------------------+ 1 | -.7621332906 -.5136120346 -.8772027338 | 2 | -.5282854667 -.3152370696 .4686056046 | 3 | -.3742556787 .7980152053 .104518664 | +----------------------------------------------+ : eigenvalues 1 +---------------+ 1 | 4.859523389 | 2 | -1.43366463 | 3 | .5741412412 | +---------------+
Code:
: sort(eigenvalues,-1) 1 +---------------+ 1 | 4.859523389 | 2 | .5741412412 | 3 | -1.43366463 | +---------------+
Thank you for your help!
Best,
Ali
Comment