Left and right eigenvectors in julia

When working with Julia, it is common to encounter situations where we need to find the left and right eigenvectors of a matrix. The left eigenvectors are the vectors that satisfy the equation A’v = λv, where A’ is the transpose of the matrix A, v is the eigenvector, and λ is the eigenvalue. On the other hand, the right eigenvectors satisfy the equation Av = λv.

Option 1: Using the eigvals function

One way to find the left and right eigenvectors in Julia is by using the eigvals function from the LinearAlgebra package. This function returns the eigenvalues of a matrix. We can then use these eigenvalues to find the corresponding eigenvectors using the eigvecs function.


using LinearAlgebra

A = [1 2; 3 4]  # Example matrix

eigenvalues = eigvals(A)
eigenvectors = eigvecs(A)

left_eigenvectors = eigvecs(A')
right_eigenvectors = eigvecs(A)

In this code, we first define the matrix A. Then, we use the eigvals function to obtain the eigenvalues of A. Next, we use the eigvecs function to find the eigenvectors of A. Finally, we use the eigvecs function again, but this time with the transpose of A, to find the left eigenvectors.

Option 2: Using the eigen function

Another way to find the left and right eigenvectors in Julia is by using the eigen function from the LinearAlgebra package. This function returns both the eigenvalues and eigenvectors of a matrix.


using LinearAlgebra

A = [1 2; 3 4]  # Example matrix

eigenvalues, eigenvectors = eigen(A)

left_eigenvectors = eigenvectors'
right_eigenvectors = eigenvectors

In this code, we again define the matrix A. Then, we use the eigen function to obtain both the eigenvalues and eigenvectors of A. We can then use the transpose of the eigenvectors to find the left eigenvectors.

Option 3: Using the eig function

A third way to find the left and right eigenvectors in Julia is by using the eig function from the LinearAlgebra package. This function returns both the eigenvalues and eigenvectors of a matrix, similar to the eigen function.


using LinearAlgebra

A = [1 2; 3 4]  # Example matrix

eigenvalues, eigenvectors = eig(A)

left_eigenvectors = eigenvectors'
right_eigenvectors = eigenvectors

In this code, we once again define the matrix A. Then, we use the eig function to obtain both the eigenvalues and eigenvectors of A. We can then use the transpose of the eigenvectors to find the left eigenvectors.

Among these three options, the best choice depends on the specific requirements of your problem. If you only need the eigenvalues, Option 1 using the eigvals function is the most efficient. If you need both the eigenvalues and eigenvectors, Options 2 and 3 using the eigen or eig function are equally valid. However, Option 2 using the eigen function may be slightly more efficient as it returns both the eigenvalues and eigenvectors in a single call.

Rate this post

Leave a Reply

Your email address will not be published. Required fields are marked *

Table of Contents