Loading content...
In linear algebra and spectral theory, eigenvalues are fundamental scalar quantities that characterize the behavior of linear transformations. For a square matrix A, an eigenvalue λ is a scalar such that there exists a non-zero vector v (called an eigenvector) satisfying:
$$A \cdot v = \lambda \cdot v$$
This equation reveals that when the matrix A acts on its eigenvector v, the result is simply a scaled version of v by the factor λ. Eigenvalues capture the "stretching factors" of the transformation along special directions.
The Characteristic Polynomial Approach:
For a 2×2 matrix of the form:
$$A = \begin{bmatrix} a & b \ c & d \end{bmatrix}$$
The eigenvalues can be found by solving the characteristic equation:
$$\det(A - \lambda I) = 0$$
This expands to the quadratic equation:
$$\lambda^2 - \text{trace}(A) \cdot \lambda + \det(A) = 0$$
Where:
Using the quadratic formula, the two eigenvalues are:
$$\lambda_{1,2} = \frac{\text{trace}(A) \pm \sqrt{\text{trace}(A)^2 - 4 \cdot \det(A)}}{2}$$
Your Task: Write a Python function that computes the eigenvalues of a 2×2 matrix. The function should:
matrix = [[2, 1], [1, 2]][3.0, 1.0]For this symmetric matrix:
• trace(A) = 2 + 2 = 4 • det(A) = (2 × 2) - (1 × 1) = 4 - 1 = 3
Applying the quadratic formula: • discriminant = 4² - 4(3) = 16 - 12 = 4 • λ₁ = (4 + √4) / 2 = (4 + 2) / 2 = 3.0 • λ₂ = (4 - √4) / 2 = (4 - 2) / 2 = 1.0
The eigenvalues are [3.0, 1.0], already sorted from highest to lowest.
matrix = [[4, 0], [0, 2]][4.0, 2.0]This is a diagonal matrix, where eigenvalues are simply the diagonal elements:
• trace(A) = 4 + 2 = 6 • det(A) = (4 × 2) - (0 × 0) = 8
Applying the quadratic formula: • discriminant = 6² - 4(8) = 36 - 32 = 4 • λ₁ = (6 + 2) / 2 = 4.0 • λ₂ = (6 - 2) / 2 = 2.0
For diagonal matrices, the eigenvalues always equal the diagonal entries.
matrix = [[1, 0], [0, 1]][1.0, 1.0]This is the identity matrix I₂. The identity transformation scales all vectors by 1, so both eigenvalues equal 1:
• trace(A) = 1 + 1 = 2 • det(A) = (1 × 1) - (0 × 0) = 1
Applying the quadratic formula: • discriminant = 2² - 4(1) = 4 - 4 = 0 • λ₁ = λ₂ = 2 / 2 = 1.0
This is a case of repeated (degenerate) eigenvalues. Both eigenvalues are equal to 1.0.
Constraints