From 39ec6e2061e8ae4c90197a0e049c4c83a3f7ae9b Mon Sep 17 00:00:00 2001 From: marcelbls Date: Wed, 5 Nov 2025 14:43:19 +0100 Subject: [PATCH] compute added --- .idea/.gitignore | 8 ++ .idea/MatrixMania.iml | 10 +++ .idea/inspectionProfiles/Project_Default.xml | 6 ++ .../inspectionProfiles/profiles_settings.xml | 6 ++ .idea/misc.xml | 6 ++ .idea/modules.xml | 8 ++ .idea/vcs.xml | 6 ++ compute..py | 80 +++++++++++++++++++ 8 files changed, 130 insertions(+) create mode 100644 .idea/.gitignore create mode 100644 .idea/MatrixMania.iml create mode 100644 .idea/inspectionProfiles/Project_Default.xml create mode 100644 .idea/inspectionProfiles/profiles_settings.xml create mode 100644 .idea/misc.xml create mode 100644 .idea/modules.xml create mode 100644 .idea/vcs.xml create mode 100644 compute..py diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..13566b8 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,8 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Editor-based HTTP Client requests +/httpRequests/ +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml diff --git a/.idea/MatrixMania.iml b/.idea/MatrixMania.iml new file mode 100644 index 0000000..51bcf32 --- /dev/null +++ b/.idea/MatrixMania.iml @@ -0,0 +1,10 @@ + + + + + + + + + + \ No newline at end of file diff --git a/.idea/inspectionProfiles/Project_Default.xml b/.idea/inspectionProfiles/Project_Default.xml new file mode 100644 index 0000000..cd83845 --- /dev/null +++ b/.idea/inspectionProfiles/Project_Default.xml @@ -0,0 +1,6 @@ + + + + \ No newline at end of file diff --git a/.idea/inspectionProfiles/profiles_settings.xml b/.idea/inspectionProfiles/profiles_settings.xml new file mode 100644 index 0000000..105ce2d --- /dev/null +++ b/.idea/inspectionProfiles/profiles_settings.xml @@ -0,0 +1,6 @@ + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..96db2e4 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,6 @@ + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..55c2805 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..94a25f7 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/compute..py b/compute..py new file mode 100644 index 0000000..1625b83 --- /dev/null +++ b/compute..py @@ -0,0 +1,80 @@ +from typing import List +import math +from tabulate import tabulate + +def matmul(matrix_a: List[List[int]], matrix_b: List[List[int]]) -> List[List[int]]: + """ + Matrix multiplication + :param matrix_a: Matrix A + :param matrix_b: Matrix B + :return: product of matrix_a and matrix_b + :raises: ValueError: wenn Matrix A and Matrix B nicht multipliezierbar sind + """ + + if len(matrix_a[0]) != len(matrix_b): + print(len(matrix_a[0])) + print(len(matrix_b)) + raise ValueError("Matrix kann nicht multipliziert werden") + + ergebnis1 = [] + ergebnis2 = [] + result = 0 + spalte_max = len(matrix_b[0]) + zeile = 0 + + for spalte in range(len(matrix_a)): + for zeile in range(spalte_max): + for z in range(len(matrix_a[0])): + zahl = matrix_a[spalte][z] * matrix_b[z][zeile] + result = result + zahl + ergebnis1.append(result) + result = 0 + ergebnis2.append(ergebnis1) + ergebnis1 = [] + + return ergebnis2 + +def transpose(matrix: list[list[int]]) -> list[list[int]]: + """ + Transpose a matrix + :param matrix: valid matrix + :return: transpose of matrix + """ + if len(matrix) == 0: + raise ValueError("Matrix leer") + mindest_länge = len(matrix[0]) + for zeile in range(len(matrix)): + if len(matrix[zeile]) != mindest_länge : + raise ValueError("Matrix falsch") + + anzahl_spalten= len(matrix) + anzahl_zeilen= len(matrix[0]) + ergebnis1 = [] + ergebnis2 = [] + for z in range(anzahl_zeilen): + for s in range(anzahl_spalten): + ergebnis1.append(matrix[s][z]) + + ergebnis2.append(ergebnis1) + ergebnis1 = [] + + return ergebnis2 + + +def rot_2D(angle: int) -> List[List[int]]: + """ + Rotation matrix + :param angle: any angle + :return: rotation matrix + """ + zahl1 = math.cos(math.radians(angle)) + zahl2 = -math.sin(math.radians(angle)) + zahl3 = math.sin(math.radians(angle)) + zahl4 = math.cos(math.radians(angle)) + + return [[zahl1, zahl2], [zahl3, zahl4]] + + +if __name__ == "__main__": + + print(rot_2D()) \ No newline at end of file