kommentaare update

This commit is contained in:
Max-R 2025-11-22 15:23:50 +01:00
parent 5075c34983
commit e7930c7eb0

View File

@ -168,18 +168,21 @@ Matrix multiply(const Matrix matrix1, const Matrix matrix2) {
//Spalten1 müssen gleich zeilen2 sein! dann multiplizieren //Spalten1 müssen gleich zeilen2 sein! dann multiplizieren
if (matrix1.cols == matrix2.rows){ if (matrix1.cols == matrix2.rows){
Matrix multMatrix = createMatrix(matrix1.rows,matrix2.cols); Matrix multMatrix = createMatrix(matrix1.rows,matrix2.cols);
//durch neue matrix iterieren
for (int r=0; r< matrix1.rows; r++){ for (int r=0; r< matrix1.rows; r++){
for (int c=0; c< matrix2.cols; c++){ for (int c=0; c< matrix2.cols; c++){
MatrixType sum = 0.0; MatrixType sum = 0.0;
//skalarprodukte berechnen, k damit die ganze zeile mal die ganze spalte genommen wird quasi
for (int k=0; k< matrix1.cols; k++){ for (int k=0; k< matrix1.cols; k++){
sum+= matrix1.buffer[r*matrix1.cols+k]*matrix2.buffer[k*matrix2.cols+c]; sum+= matrix1.buffer[r*matrix1.cols+k]*matrix2.buffer[k*matrix2.cols+c];
} }
//Ergebnisse in neue matrix speichern
multMatrix.buffer[r*multMatrix.cols+c] = sum; multMatrix.buffer[r*multMatrix.cols+c] = sum;
} }
} }
return multMatrix; return multMatrix;
} }
//sonst fehler //sonst fehler, kein multiply möglich
else{ else{
Matrix errorMatrix = {0, 0, NULL}; Matrix errorMatrix = {0, 0, NULL};
return errorMatrix; return errorMatrix;