ANALYSIS TOOL BOX

Linear Algebra

CalculateEigenvalues

Calculate and visualize the eigenvalues and eigenvectors of a 2x2 matrix.

linear-algebramatricesvectorsdecomposition

Introduction

When a matrix transforms space, most vectors get both stretched and rotated — but a special few, the eigenvectors, only get stretched, staying on the same line through the origin. CalculateEigenvalues computes those invariant directions and their scaling factors for a 2x2 matrix, then plots the transformation of a unit square alongside the eigenvectors so you can literally see which directions the matrix preserves and by how much it scales them.

Teaching Note

Calculating eigenvalues and eigenvectors is essential for:

  • Understanding linear transformations and their invariant directions
  • Visualizing the geometric impact of scalar multiplication on eigenvectors
  • Identifying system stability and resonance in physical applications
  • Analyzing principal directions in data dimensionality reduction (e.g., PCA)
  • Educational exploration of fundamental linear algebra concepts
  • Solving systems of linear differential equations

Parameters

ParameterTypeDefaultDescription
matrixrequiredThe 2x2 matrix to calculate the eigenvalues and eigenvectors of. Can be provided as a numpy.ndarray or a nested list.
show_plotTrueWhether to show a plot of the matrix transformation and eigenvectors. Defaults to True.
matrix_color'#033dfc'The color to use for the transformed matrix plot. Defaults to '#033dfc'.
eigenvector_color'#e82a53'The color to use for the eigenvector arrows in the plot. Defaults to '#e82a53'.
x_min-1The minimum x-axis value for the plot. Defaults to -1.
x_max5The maximum x-axis value for the plot. Defaults to 5.
y_min-1The minimum y-axis value for the plot. Defaults to -1.
y_max5The maximum y-axis value for the plot. Defaults to 5.
show_labelsTrueWhether to show descriptive labels on the plot elements. Defaults to True.
plot_with_gridTrueWhether to show a coordinate grid on the plot. Defaults to True.

Returns

None — the function prints the eigenvalues and eigenvectors to the console and displays a plot if show_plot is True.

Example

python
from analysistoolbox.linear_algebra import CalculateEigenvalues

# Calculate eigenvalues for a simple scaling matrix
CalculateEigenvalues([[2, 0], [0, 3]])