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
| Parameter | Type | Default | Description |
|---|---|---|---|
matrixrequired | | — | The 2x2 matrix to calculate the eigenvalues and eigenvectors of. Can be provided as a numpy.ndarray or a nested list. |
show_plot | | True | Whether 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 | | -1 | The minimum x-axis value for the plot. Defaults to -1. |
x_max | | 5 | The maximum x-axis value for the plot. Defaults to 5. |
y_min | | -1 | The minimum y-axis value for the plot. Defaults to -1. |
y_max | | 5 | The maximum y-axis value for the plot. Defaults to 5. |
show_labels | | True | Whether to show descriptive labels on the plot elements. Defaults to True. |
plot_with_grid | | True | Whether 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]])