Dirk Eddelbuettel — written Jan 18, 2013 — updated Nov 23, 2015 — source
Two previous posts showed how to compute eigenvalues
using Armadillo and
using Eigen. As we have also looked at using the
GNU GSL, this post will show how to
conpute eigenvalues using GSL.
As mentioned in the previous GSL post, we
instantiate C language pointers suitable for GSL (here the matrix
M
). Prior to release 0.3.0 of RcppGSL, these had to be freed manually.
However, since release 0.3.0 since is now taken care of via the standard
C++ mechanism of destructors.
We can illustrate this easily via a random sample matrix.
[1] 14.210011 2.409920 1.685588 0.331887
In comparison, R gets the same results (in reverse order) and also returns the eigenvectors.
$values [1] 14.210011 2.409920 1.685588 0.331887 $vectors [,1] [,2] [,3] [,4] [1,] 0.6998802 -0.5579950 0.4458363 -0.00626959 [2,] -0.0683337 -0.0843295 0.0157046 0.99396801 [3,] 0.4409966 -0.1533407 -0.8837594 0.03127147 [4,] 0.5576919 0.8111823 0.1412537 0.10493036Tweet