This commit is contained in:
MiraSchütz committed 2026-11-15 18:26:00 +01:00
1 parent 85369b3bad
commit d4e329e098
1 file changed
+24
+24
View File
@@ -103,5 +103,29 @@ Matrix add(const Matrix matrix1, const Matrix matrix2)
Matrix multiply(const Matrix matrix1, const Matrix matrix2)
{
if(matrix.cols !=matrix2.rows){
Matrix result;
result.rows = 0;
result.cols = 0;
result.buffer = NULL;
return result;
}
Matrix resultMatrix = createMatrix(matrix1.rows, matrix2.cols);
if (resultMatrix.buffer == NULL) {
return resultMatrix;
}
for (unsigned int i = 0; i < matrix1.rows; i++) {
for (unsigned int j = 0; j < matrix2.cols; j++) {
MatrixType sum = 0;
for (unsigned int k = 0; k < matrix1.cols; k++) {
sum += getMatrixAt(matrix1, i, j) * getMatrixAt(matrix2, k, j);
}
setMatrixAt(sum, resultMatrix, i, j);
}
}
return resultMatrix;
}