Calculate Eigenvalues of a Matrix

Medium
Machine Learning

Write a Python function that calculates the eigenvalues of a 2x2 matrix. The function should return a list containing the eigenvalues, sort values from highest to lowest.

Examples

Example 1:
Input: matrix = [[2, 1], [1, 2]]
Output: [3.0, 1.0]
Explanation: The eigenvalues of the matrix are calculated using the characteristic equation of the matrix, which for a 2x2 matrix is $\lambda^2 - trace(A)\lambda + det(A) = 0$, where $\lambda$ are the eigenvalues.

Starter Code

def calculate_eigenvalues(matrix: list[list[float|int]]) -> list[float]:
	return eigenvalues
Lines: 1Characters: 0
Ready
The AI Interview - Master AI/ML Interviews