1. As Jan pointed out, it looks like you have some typos in your code. It
looks like the lines computing the second row of temp should have temp[2,1]
instead of temp[1,1] and so on.

2. ev[:,1] retrieves the first eigenvector of an upper triangular matrix,
which is always the first canonical basis vector e1 = (1, 0, 0,..., 0). So
as written, the eigenvector computation does nothing.

3. Julia does not guarantee that eigenvalues and eigenvectors are sorted
(since the underlying LAPACK routines do not), so s*ev[:,1] is not always
the principal axis. However you can still determine the principal axis from
the result of the QR factorization because the corresponding eigenvalues
will be the diagonal entries of R, so all you have to do is to find which
diagonal element is the one you want and return its corresponding
eigenvector.

4. Regarding Viral's point about allocating many temporaries, you may be
better off with the in-place variant x = qrfact!(temp) instead of qr(temp).
You can still read off the eigenvalues as the diagonal entries of x.factors
and you can compute the eigenvector you want as x[:Q]*[1.0f0, 0.0f0, 0.0f0]
(for the first column) and similarly for other columns.

Reply via email to