Calculate Eigenvalues of a Matrix
Calculate Eigenvalues of a Matrix
Calculate the eigenvalues of a square matrix.
Eigenvalue Definition:
Av=λvCharacteristic Equation:
det(A−λI)=0Where: A = matrix, λ = eigenvalue, v = eigenvector, I = identity matrix, det = determinant
Function Arguments
matrix: list[list[float]] | np.ndarray- Input matrix (should be square)
Examples
Input: matrix=[[4, 1], [2, 3]]
Output: [2.0, 5.0] (approximately)
Input: matrix=[[0, -1], [1, 0]]
Output: [-1j, 1j] (pure imaginary)
Input: matrix=[[1, 2, 3], [4, 5]]
Output: None (non-square)
Hint 1
Use np.asarray() to convert input to numpy array. Check matrix dimensions with .shape and .ndim.
Hint 2
Use np.linalg.eigvals() to compute eigenvalues. Use np.lexsort() for consistent sorting by real then imaginary parts.
Hint 3
Handle edge cases: check if matrix is square with matrix.shape[0] == matrix.shape[1]. Return None for invalid inputs.
Requirements
- Return
np.ndarrayof eigenvalues (complex dtype if needed) - Return
Nonefor non-square matrices or invalid input - Handle empty matrices gracefully
- Sort eigenvalues by real part, then imaginary part for consistency
- Use NumPy's linear algebra functions
Constraints
- Matrix size ≤ 100×100
- Numerical precision: relative tolerance ≤ 1e-8
- Libraries: NumPy only
Try Similar Problems
Log in to take notes on this problem
Accepts: array
Calculate Eigenvalues of a Matrix
Calculate Eigenvalues of a Matrix
Calculate the eigenvalues of a square matrix.
Eigenvalue Definition:
Av=λvCharacteristic Equation:
det(A−λI)=0Where: A = matrix, λ = eigenvalue, v = eigenvector, I = identity matrix, det = determinant
Function Arguments
matrix: list[list[float]] | np.ndarray- Input matrix (should be square)
Examples
Input: matrix=[[4, 1], [2, 3]]
Output: [2.0, 5.0] (approximately)
Input: matrix=[[0, -1], [1, 0]]
Output: [-1j, 1j] (pure imaginary)
Input: matrix=[[1, 2, 3], [4, 5]]
Output: None (non-square)
Hint 1
Use np.asarray() to convert input to numpy array. Check matrix dimensions with .shape and .ndim.
Hint 2
Use np.linalg.eigvals() to compute eigenvalues. Use np.lexsort() for consistent sorting by real then imaginary parts.
Hint 3
Handle edge cases: check if matrix is square with matrix.shape[0] == matrix.shape[1]. Return None for invalid inputs.
Requirements
- Return
np.ndarrayof eigenvalues (complex dtype if needed) - Return
Nonefor non-square matrices or invalid input - Handle empty matrices gracefully
- Sort eigenvalues by real part, then imaginary part for consistency
- Use NumPy's linear algebra functions
Constraints
- Matrix size ≤ 100×100
- Numerical precision: relative tolerance ≤ 1e-8
- Libraries: NumPy only
Try Similar Problems
Log in to take notes on this problem
Accepts: array