diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..178135c --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +/dist/ diff --git a/README.md b/README.md new file mode 100644 index 0000000..24b0ff2 --- /dev/null +++ b/README.md @@ -0,0 +1,92 @@ +# MatrixMania + +This Package contains a few fundamental function which can be used for **matrices**. + +## Functions: + +- matmul function +- transpose function +- rot_2D function + +## matmul function: + +This function calculates the matrix multiplication with 2 matrices. +It also checks if the matrices are compatible for multiplication. + +**Example:** + +``` +matrix_a = [[3, 4, -1, 4], + [-2, 2, 5, 1]] + +matrix_b = [[1, 3, -2], + [2, 5, 1], + [-1, 4, -4], + [2, 3, 6]] + +matrix_c = matmul(matrix_a, matrix_b) +print("matrix c:") +print(tabulate(matrix_c)) +``` + +**Result:** + +``` +matrix c: +-- -- -- +20 37 26 +-1 27 -8 +-- -- -- +``` + + +## transpose function: + +This function transposes a matrix. + +**Example:** + +``` +matrix = [[1, 2, 3], + [4, 5, 6]] + +new_matrix = transpose(matrix) +print("transposed matrix:") +print(tabulate(new_matrix)) +``` + +**Result:** + +``` +transposed matrix: +- - +1 4 +2 5 +3 6 +- - + +``` + +## rot_2D function: + +This function returns the rotation matrix for a given angle. + +**Example:** + +``` +theta = math.pi / 2 +R = rot_2D(theta) + +print("rotation matrix for 90°:") +print(tabulate(R)) +``` + +**Result** + +``` +rotation matrix for 90°: +----------- ------------ +6.12323e-17 -1 +1 6.12323e-17 +----------- ------------ +``` \ No newline at end of file diff --git a/matrixmania/__init__.py b/matrixmania/__init__.py new file mode 100644 index 0000000..2dbdec6 --- /dev/null +++ b/matrixmania/__init__.py @@ -0,0 +1 @@ +from .compute import matmul, transpose, rot_2D diff --git a/compute.py b/matrixmania/compute.py similarity index 92% rename from compute.py rename to matrixmania/compute.py index 84c3f80..4c0c7cf 100644 --- a/compute.py +++ b/matrixmania/compute.py @@ -68,9 +68,10 @@ if __name__ == "__main__": ] matrix_c = matmul(matrix_a, matrix_b) - print("Ergebnis C = A * B:") - for row in matrix_c: - print(row) + print("Matrix C:") + print(tabulate(matrix_c)) + #for row in matrix_c: + # print(row) matrix = [ [1, 2, 3], @@ -78,8 +79,9 @@ if __name__ == "__main__": ] new_matrix = transpose(matrix) print("transposed matrix:") - for row in new_matrix: - print(row) + print(tabulate(new_matrix)) + #for row in new_matrix: + # print(row) #empty_matrix = [] #transpose(empty_matrix) @@ -87,7 +89,7 @@ if __name__ == "__main__": theta = math.pi / 2 R = rot_2D(theta) print("Rotatiosnmatrix für 90 Grad:") - print(R) + print(tabulate(R)) p = [[1, 0]] rotated = matmul(p, R) diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..52c7d87 --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,16 @@ +[project] +name = "matrixmania_benkertmo99686" +version = "0.1.0" +description = "MatrixMania: Simple linear algebra functions for teaching (matmul, transpose, rot_2D)." +authors = [ + { name="Mona Benkert", email="benkertmo99686@th-nuernberg.de" } +] +readme = "README.md" +license = { text = "MIT" } +requires-python = ">=3.7" +dependencies = ["tabulate"] +[build-system] +requires = ["hatchling"] +build-backend = "hatchling.build" +[tool.hatch.build.targets.wheel] +packages = ["matrixmania"] \ No newline at end of file