Matrix Toolkit offers classroom-friendly matrix calculations that keep arithmetic exact through Python's fractions.Fraction. The core logic lives in a reusable package, and the interactive command line interface is in Portuguese, while all documentation stays in English.
- Addition, subtraction, scalar multiplication – Standard matrix arithmetic
- Matrix multiplication – Standard product A × B
- Hadamard product – Element-wise multiplication A ⊙ B
- Matrix power – Raise matrices to integer powers (including A⁻¹)
- Transpose – Flip rows and columns
- Determinant – Recursive Laplace expansion
- Cofactor matrix – Matrix of cofactors
- Adjugate – Transpose of cofactor matrix
- Inverse – Via adjugate method with singularity checks
- Minor and cofactor – Individual (i,j) minor and cofactor
- RREF – Reduced Row Echelon Form with step-by-step log
- LU Decomposition – Factor A = L × U (without pivoting)
- Solve Ax = b – Gaussian elimination with step-by-step display
- Rank – Number of linearly independent rows/columns
- Nullity – Dimension of null space (cols - rank)
- Trace – Sum of diagonal elements
- Diagonal extraction – Get main diagonal as list
- Property checks: symmetric, diagonal, identity, zero, upper/lower triangular
- Identity matrix – Create I_n
- Zero matrix – Create m×n zero matrix
- Frobenius norm – √(sum of squared entries)
- Submatrix extraction – Extract rectangular regions
- Concatenation – Horizontal and vertical matrix joining
- Exact arithmetic via
fractions.Fraction; no third-party dependencies - Interactive CLI in Portuguese with colored output and categorized menu
- Step-by-step display for educational purposes
- Python 3.8 or newer; standard library only.
Run the unified menu-driven CLI:
python scripts/matrix_cli.py
# or
python -m matrix_toolkit.cliThe CLI features:
- Categorized menu with 19 operations organized into 6 groups
- Colored output (ANSI) for better readability (auto-disabled if not a TTY)
- Step-by-step display for RREF, LU decomposition, and system solving
- Help system with input examples and operation descriptions
- Fraction support – Enter values like
1/2,-3/4directly
Available categories:
- Operacoes Basicas – Sum, subtract, scalar multiply, matrix multiply, Hadamard, power
- Estrutura e Propriedades – Transpose, trace, diagonal, property checks
- Determinante e Inversa – Determinant, inverse with cofactors
- Reducao e Decomposicao – RREF, LU decomposition
- Sistemas Lineares e Posto – Solve Ax=b, rank/nullity
- Geradores e Normas – Identity, zero matrix, Frobenius norm
Legacy-style entry points remain for single tasks:
python scripts/matriz_fera.py– RREF with printed row operations.python scripts/matriz_inversa_cofatores.py– Determinant, cofactors, adjugate, and inverse.
from matrix_toolkit import (
add_matrices, determinant, inverse, trace, rank,
identity_matrix, is_symmetric, lu_decomposition,
solve_system, matrix_power, rref
)
a = [[1, 2], [3, 4]]
b = [[2, 0], [1, 2]]
# Basic operations
sum_ab = add_matrices(a, b)
det_a = determinant(a)
inv_a = inverse(a) # raises ValueError if singular
# New operations
tr = trace(a) # Sum of diagonal: 1 + 4 = 5
r = rank(a) # Matrix rank
I3 = identity_matrix(3) # 3x3 identity
sym = is_symmetric(a) # False
L, U = lu_decomposition(a) # A = L × U
a_squared = matrix_power(a, 2) # A²
reduced = rref(a) # Row echelon form
# Solve linear system Ax = b
A = [[2, 1], [1, 3]]
b = [[5], [10]]
x = solve_system(A, b) # Solution vectorAll functions accept any numeric input coercible to Fraction and perform validation (shape checks, square requirements, etc.).
README.md
LICENSE
matrix_toolkit/
__init__.py # Package exports
cli.py # Portuguese CLI with colored menu
interactive.py # Input/output helpers (Portuguese prompts)
operations.py # Pure matrix operations built on Fraction
scripts/
matrix_cli.py # Entry point for the CLI menu
matriz_fera.py # RREF demo script
matriz_inversa_cofatores.py # Inverse demo script
This project is distributed under the MIT License. See LICENSE for details.