From b187a13b1721d57ab05d88c346bb470de3f9ac57 Mon Sep 17 00:00:00 2001 From: Max-R Date: Sat, 22 Nov 2025 15:17:12 +0100 Subject: [PATCH] multiply, besteht MatrixTests --- matrix.c | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/matrix.c b/matrix.c index d3987b5..e1da69d 100644 --- a/matrix.c +++ b/matrix.c @@ -162,9 +162,27 @@ Matrix add(const Matrix matrix1, const Matrix matrix2) { Matrix errorMatrix = {0, 0, NULL}; return errorMatrix; } - - - return result; } -Matrix multiply(const Matrix matrix1, const Matrix matrix2) { return matrix1; } +Matrix multiply(const Matrix matrix1, const Matrix matrix2) { + //Spalten1 müssen gleich zeilen2 sein! dann multiplizieren + if (matrix1.cols == matrix2.rows){ + Matrix multMatrix = createMatrix(matrix1.rows,matrix2.cols); + for (int r=0; r< matrix1.rows; r++){ + for (int c=0; c< matrix2.cols; c++){ + MatrixType sum = 0.0; + for (int k=0; k< matrix1.cols; k++){ + sum+= matrix1.buffer[r*matrix1.cols+k]*matrix2.buffer[k*matrix2.cols+c]; + } + multMatrix.buffer[r*multMatrix.cols+c] = sum; + } + } + return multMatrix; + } + //sonst fehler + else{ + Matrix errorMatrix = {0, 0, NULL}; + return errorMatrix; + } + //return matrix1; +}