A simple Python project that implements 2×2 matrix operations using Object-Oriented Programming (OOP) and operator overloading (magic methods).
- ➕ Matrix Addition
- ➖ Matrix Subtraction
- ✖️ Matrix Multiplication
- 🧩 Clean matrix output formatting
- 🐍 Uses Python magic methods (
__add__,__sub__,__mul__,__str__)
matrix.py
x = Matrix(1,2,3,4)
y = Matrix(4,7,8,9)
print(x)
print(y)
print(x + y)
print(x - y)
print(x * y)[1 2]
[3 4]
[4 7]
[8 9]
Addition:
[5 9]
[11 13]
Subtraction:
[-3 -5]
[-5 -5]
Multiplication:
[20 25]
[44 57]
- Object-Oriented Programming (OOP)
- Classes & Objects
- Constructor (
__init__) - Magic Methods
- Operator Overloading
- Matrix Arithmetic
- Support matrices of any size (NxN)
- Matrix transpose
- Determinant calculation
- Matrix inverse
- Scalar multiplication
- Input matrices from the user
- Error handling for invalid dimensions
Nayan Samadhiya