funktionalität erweitert add

This commit is contained in:
Jonas Urban 2025-11-10 20:39:35 +01:00
parent db7617e046
commit f8035cc4db

View File

@ -63,7 +63,7 @@ Matrix add(const Matrix matrix1, const Matrix matrix2)
{
Matrix result;
if (matrix1.buffer == NULL || matrix2.buffer == NULL || matrix1.rows != matrix2.rows || matrix1.cols != matrix2.cols)
if (matrix1.buffer == NULL || matrix2.buffer == NULL || matrix1.rows != matrix2.rows)
{
result.rows = 0;
result.cols = 0;
@ -71,17 +71,51 @@ Matrix add(const Matrix matrix1, const Matrix matrix2)
return result;
}
result = createMatrix(matrix1.rows, matrix1.cols);
for (int i = 0; i < matrix1.rows; i++)
if (matrix1.cols == matrix2.cols)
{
for (int j = 0; j < matrix1.cols; j++)
result = createMatrix(matrix1.rows, matrix1.cols);
for (int i = 0; i < matrix1.rows; i++)
{
MatrixType value = getMatrixAt(matrix1, i, j) + getMatrixAt(matrix2, i, j);
setMatrixAt(value, result, i, j);
for (int j = 0; j < matrix1.cols; j++)
{
MatrixType value = getMatrixAt(matrix1, i, j) + getMatrixAt(matrix2, i, j);
setMatrixAt(value, result, i, j);
}
}
return result;
}
if (matrix1.cols == 1 && matrix2.cols > 1)
{
result = createMatrix(matrix1.rows, matrix2.cols);
for (int i = 0; i < matrix1.rows; i++)
{
for (int j = 0; j < matrix2.cols; j++)
{
MatrixType value = getMatrixAt(matrix1, i, 0) + getMatrixAt(matrix2, i, j);
setMatrixAt(value, result, i, j);
}
}
return result;
}
else if (matrix2.cols == 1 && matrix1.cols > 1)
{
result = createMatrix(matrix1.rows, matrix1.cols);
for (int i = 0; i < matrix1.rows; i++)
{
for (int j = 0; j < matrix1.cols; j++)
{
MatrixType value = getMatrixAt(matrix1, i, j) + getMatrixAt(matrix2, i, 0);
setMatrixAt(value, result, i, j);
}
}
return result;
}
//Fall: Unterschiedliche Spaltenanzahl, beide ungleich 1
result.rows = 0;
result.cols = 0;
result.buffer = NULL;
return result;
}