Neural Mastery
← Practice
Matrix Determinant for Low-Order Systemseasy

Matrix Determinant for Low-Order Systems

easy Math for ML 10-15 min

NumPy allowed · plain Python earns 10 bonus points

Linear algebra step 1/4

A vector transforms

Matrix multiplication is the first computation behind every model.
Open lesson →
01vector
02matrix
03transform
04result
[2, −1] × [[1, 2], [−.5, 1]] = [0, −2]

Computed matrix × vector transformation

Compute the determinant of 1x1, 2x2, or 3x3 square matrices.

Task

Implement matrix_determinant(A): calculate det(A) for matrices of dimension up to 3x3 using direct algebraic formulas / Laplace cofactor expansion. Round result to 4 decimals.

Function Signature

matrix_determinant(A: list[list[float]]) -> float

Examples

Example 1: 2x2 Determinant
Input: A = [[3, 8], [4, 6]]
Output: -14
Explanation: Standard 2x2 determinant ad - bc.
Example 2: 3x3 Triangular
Input: A = [[2, 3, 1], [0, 4, 5], [0, 0, 6]]
Output: 48
Explanation: Upper triangular product of diagonals.

Constraints

  • Matrix dimension n in {1, 2, 3}.
Python3Saved ✓
def matrix_determinant(A: list[list[float]]) -> float:
"""Compute determinant of 1x1, 2x2, or 3x3 matrix A.
Return float rounded to 4 decimals."""
# Your implementation here
pass

Case 1: 2x2 Determinant
Input: A = [[3, 8], [4, 6]]
Expected: -14
Case 2: 3x3 Triangular
Input: A = [[2, 3, 1], [0, 4, 5], [0, 0, 6]]
Expected: 48