This commit is contained in:
Kristin 2025-11-23 16:44:13 +01:00
commit da4eaa718d

View File

@ -89,7 +89,28 @@ Matrix broadCastRows(const Matrix matrix, const unsigned int rows,
}
Matrix add(const Matrix matrix1, const Matrix matrix2) {
Matrix result;
const int cols1 = matrix1.cols;
const int rows1 = matrix1.rows;
const int cols2 = matrix2.cols;
const int rows2 = matrix2.rows;
const int colsEqu = (matrix1.cols == matrix2.cols) ? 1 : 0;
const int rowsEqu = (matrix1.rows == matrix2.rows) ? 1 : 0;
if(colsEqu && rowsEqu)
{
Matrix result = createMatrix(matrix1.rows, matrix1.cols);
for(int i = 0; i < rows1; i++)
{
for (int j = 0; j < cols1; j++)
{
int valueM1 = getMatrixAt(matrix1, i, j);
int valueM2 =getMatrixAt(matrix2, i, j);
int sum = valueM1 + valueM2;
setMatrixAt(sum, result,i,j);
}
}
<<<<<<< HEAD
// Broadcasting nur bei Vektor und Matrix, Fehlermeldung bei zwei unpassenden
// Matrizen
@ -217,6 +238,10 @@ Matrix add(const Matrix matrix1, const Matrix matrix2) {
Matrix error = {0, 0, NULL};
return error;
}
=======
return result;
}
>>>>>>> 7f3c6d1d3f7d4ee08747df6a4999e1908f5dd56d
}
Matrix multiply(const Matrix matrix1, const Matrix matrix2) {