Addition funktioniert

This commit is contained in:
Niklas Kegelmann 2025-11-10 15:23:28 +01:00
parent a18cdfded1
commit 2dbcc110fc

View File

@ -41,15 +41,45 @@ void setMatrixAt(MatrixType value, Matrix matrix, unsigned int rowIdx, unsigned
MatrixType getMatrixAt(const Matrix matrix, unsigned int rowIdx, unsigned int colIdx)
{
}
Matrix add(const Matrix matrix1, const Matrix matrix2)
{
//Überprüfen, ob die Matrizen die gleichen Dimensionen haben
//wenn nicht muss die matrix "rows/cols=0 und buffer = NULL" leer zurückgegeben werden
if (matrix1.rows != matrix2.rows || matrix1.cols != matrix2.cols)
{
Matrix result;
result.rows = 0;
result.cols = 0;
result.buffer = NULL;
return result;
}
else
{
//Matrix result ist die neue Matrix für das Ergebnis
Matrix result;
result.rows = matrix1.rows;
result.cols = matrix1.cols;
//Addition der beiden Matrizen
for (int i = 0; i < result.rows * result.cols; i++)
{
result.buffer[i] = matrix1.buffer[i] + matrix2.buffer[i];
}
return result;
}
}
Matrix multiply(const Matrix matrix1, const Matrix matrix2)
{
}