addMatrix Impelmentierung

This commit is contained in:
dehmfl103364 committed 2026-10-26 18:58:25 +01:00
1 parent e8eb227d44
commit 4a391e4319
1 file changed
+38 -5
+38 -5
View File
@@ -50,8 +50,43 @@ MatrixType getMatrixAt(const Matrix matrix, unsigned int rowIdx, unsigned int co
Matrix add(const Matrix matrix1, const Matrix matrix2) Matrix add(const Matrix matrix1, const Matrix matrix2)
{ {
Matrix testHelp = {NULL, 0,0};
return testHelp; if(matrix1.rows == matrix2.rows && matrix1.cols == matrix2.cols){
Matrix resultMatrix = createMatrix(matrix1.rows,matrix1.cols);
for(int i = 0; i < matrix1.rows * matrix1.cols; i++){
resultMatrix.buffer[i] = matrix1.buffer[i] + matrix2.buffer[i];
}
return resultMatrix;
}else if(matrix1.rows == matrix2.rows && matrix1.cols == 1){ // Matrix1 ist Vektor
Matrix resultMatrix = createMatrix(matrix1.rows,matrix2.cols);
for(int i = 0; i < matrix2.cols; i++){
for(int j = 0; j < matrix1.rows; j++){
resultMatrix.buffer[i + j * matrix2.cols]= matrix2.buffer[i + j * matrix2.cols] + matrix1.buffer[j];
}
}
return resultMatrix;
}else if(matrix1.rows == matrix2.rows && matrix2.cols == 1){ // Matrix ist Vektor
Matrix resultMatrix = createMatrix(matrix1.rows,matrix1.cols);
for(int i = 0; i < matrix1.cols; i++){
for(int j = 0; j < matrix1.rows; j++){
resultMatrix.buffer[i + j * matrix1.cols]= matrix1.buffer[i + j * matrix1.cols] + matrix2.buffer[j];
}
}
return resultMatrix;
}else{
Matrix emptyMatrix = {NULL,0,0};
return emptyMatrix;
}
} }
Matrix multiply(const Matrix matrix1, const Matrix matrix2) Matrix multiply(const Matrix matrix1, const Matrix matrix2)
@@ -76,9 +111,7 @@ Matrix multiply(const Matrix matrix1, const Matrix matrix2)
return resultMatrix; return resultMatrix;
}else{ }else{
resultMatrix.buffer = NULL; clearMatrix(&resultMatrix);
resultMatrix.rows = 0;
resultMatrix.cols = 0;
return resultMatrix; return resultMatrix;
} }