Skip to content

MATLAB - Eigenvalues and Eigenvectors

MATLAB - A Modern Guide to Eigenvalues and Eigenvectors

Section titled “MATLAB - A Modern Guide to Eigenvalues and Eigenvectors”

Eigenvalues and eigenvectors are core concepts in linear algebra with profound applications across science and engineering. They reveal the fundamental properties of linear transformations. MATLAB provides powerful, numerically stable functions to compute them.

Imagine a matrix A as a linear transformation that stretches, shrinks, or rotates vectors in space. An eigenvector of this transformation is a special non-zero vector v whose direction does not change when the transformation A is applied to it. It only gets scaled (stretched or shrunk).

The corresponding eigenvalue, λ (lambda), is the scalar factor by which the eigenvector is scaled. This relationship is captured by the fundamental equation:

A * v = λ * v

Where A is a square matrix, v is the eigenvector, and λ is the eigenvalue.

Computing Eigenvalues and Eigenvectors with eig

Section titled “Computing Eigenvalues and Eigenvectors with eig”

The primary function in MATLAB for this task is eig. Let’s explore its most common uses.

e = eig(A)

This returns a column vector e containing the eigenvalues of the square matrix A.

Syntax 2: Getting Eigenvalues and Eigenvectors

Section titled “Syntax 2: Getting Eigenvalues and Eigenvectors”
[V, D] = eig(A)
  • D is a diagonal matrix where the diagonal elements D(i,i) are the eigenvalues.
  • V is a matrix whose columns V(:,i) are the corresponding right eigenvectors.
  • This output satisfies the matrix equation A*V = V*D.

Example 1: A Simple Geometric Transformation

Section titled “Example 1: A Simple Geometric Transformation”

Let’s use a matrix that represents a stretch along the x-axis and a shrink along the y-axis. The eigenvectors and eigenvalues should be intuitive.

% Transformation: stretches x-axis by 3, shrinks y-axis by 0.5
A = [3 0;
0 0.5];
% Compute eigenvalues and eigenvectors
[V, D] = eig(A);
% Display the results in a clear format
lambda1 = D(1,1);
v1 = V(:,1);
lambda2 = D(2,2);
v2 = V(:,2);
fprintf('Eigenvalue 1: %.2f\n', lambda1);
disp('Corresponding Eigenvector 1:');
disp(v1);
fprintf('\nEigenvalue 2: %.2f\n', lambda2);
disp('Corresponding Eigenvector 2:');
disp(v2);

The output will show eigenvalues of 0.5 and 3.0, with eigenvectors along the y-axis [0; 1] and x-axis [1; 0] respectively. This confirms our intuition: vectors on these axes are only scaled by the transformation.

For most matrices, the eigenvectors are not aligned with the axes.

% Define the matrix
A = [1 -1; 2 4];
% Compute eigenvalues and eigenvectors
[V, D] = eig(A);
% Display results
eigenvalues = diag(D);
disp('Eigenvalues:');
disp(eigenvalues);
disp('Eigenvectors (columns of V):');
disp(V);

You can verify the correctness of the results by checking if A*V is close to V*D. Due to floating-point arithmetic, they might not be exactly equal, so we check if the difference is very small.

% Using A, V, and D from the previous example
% Calculate the difference
residual = A*V - V*D;
% Calculate the maximum absolute error
max_error = max(abs(residual), [], 'all');
fprintf('\nVerification: Maximum error in A*V - V*D is %e\n', max_error);
% This value should be very close to zero, like 1e-15.

Why Are Eigenvalues and Eigenvectors Important? (Practical Applications)

Section titled “Why Are Eigenvalues and Eigenvectors Important? (Practical Applications)”
  • Principal Component Analysis (PCA): In data science and machine learning, eigenvectors of the covariance matrix are the principal components, used for dimensionality reduction.
  • Structural Engineering: They are used to find the natural frequencies and modes of vibration of a structure, helping to prevent resonance.
  • Quantum Mechanics: In quantum mechanics, physical quantities are represented by operators (matrices), and their eigenvalues are the possible measurable values.
  • Graph Theory: The eigenvector corresponding to the largest eigenvalue of a graph’s adjacency matrix is used in algorithms like Google’s PageRank to determine the importance of nodes in a network.
  • Stability Analysis: In control systems, the eigenvalues of the system matrix determine its stability. If all eigenvalues have negative real parts, the system is stable.

The eig function has more capabilities for advanced numerical linear algebra:

  • Generalized Eigenvalue Problem: [V,D] = eig(A,B) solves the problem A*V = B*V*D. This is common in fields like finite element analysis.
  • Numerical Stability: The optional argument 'nobalance' can be used, but the default 'balance' option permutes and scales the matrix A before computation to improve numerical accuracy. It is recommended to stick with the default unless you are an expert.