Fehler aus Vorlesung verbessert (in Uni)
This commit is contained in:
parent
d5466ae1fd
commit
542d94eac8
33
matrix.c
33
matrix.c
@ -5,7 +5,7 @@
|
||||
|
||||
// TODO Matrix-Funktionen implementieren
|
||||
|
||||
enum addModes{sameDimensions, colVec, rowVec};
|
||||
enum addModes{SAMEDIMENSIONS, COLVEC, ROWVEC};
|
||||
|
||||
Matrix createMatrix(unsigned int rows, unsigned int cols)
|
||||
{
|
||||
@ -44,7 +44,7 @@ void clearMatrix(Matrix *matrix)
|
||||
matrix->rows = 0;
|
||||
matrix->cols = 0;
|
||||
matrix->buffer = NULL;
|
||||
return matrix;
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -83,31 +83,31 @@ MatrixType getMatrixAt(const Matrix matrix, unsigned int rowIdx, unsigned int co
|
||||
|
||||
static int get_add_mode(Matrix matrix1, Matrix matrix2) {
|
||||
|
||||
int get_add_mode;
|
||||
int get_add_mode = 0;
|
||||
|
||||
if(matrix1.cols == matrix2.cols && matrix1.rows == matrix2.rows){
|
||||
|
||||
get_add_mode = sameDimensions;
|
||||
get_add_mode = SAMEDIMENSIONS;
|
||||
|
||||
}
|
||||
else if(matrix1.cols == 1 && matrix1.rows == matrix2.rows){
|
||||
|
||||
get_add_mode = colVec;
|
||||
get_add_mode = COLVEC;
|
||||
|
||||
}
|
||||
else if(matrix2.cols == 1 && matrix1.rows == matrix2.rows){
|
||||
|
||||
get_add_mode = colVec;
|
||||
get_add_mode = COLVEC;
|
||||
|
||||
}
|
||||
else if(matrix1.rows == 1 && matrix1.cols == matrix2.cols){
|
||||
|
||||
get_add_mode = rowVec;
|
||||
get_add_mode = ROWVEC;
|
||||
|
||||
}
|
||||
else if(matrix2.rows == 1 && matrix1.cols == matrix2.cols){
|
||||
|
||||
get_add_mode = rowVec;
|
||||
get_add_mode = ROWVEC;
|
||||
|
||||
}
|
||||
return get_add_mode;
|
||||
@ -203,21 +203,21 @@ static int get_add_mode(Matrix matrix1, Matrix matrix2) {
|
||||
{
|
||||
|
||||
|
||||
case sameDimensions:
|
||||
case SAMEDIMENSIONS:
|
||||
|
||||
addSameDim(matrix1, matrix2);
|
||||
matrix_erg = addSameDim(matrix1, matrix2);
|
||||
|
||||
break;
|
||||
|
||||
case colVec:
|
||||
case COLVEC:
|
||||
|
||||
addColVec(matrix1, matrix2);
|
||||
matrix_erg = addColVec(matrix1, matrix2);
|
||||
|
||||
break;
|
||||
|
||||
case rowVec:
|
||||
case ROWVEC:
|
||||
|
||||
addRowVec(matrix1, matrix2);
|
||||
matrix_erg = addRowVec(matrix1, matrix2);
|
||||
|
||||
break;
|
||||
|
||||
@ -258,7 +258,7 @@ Matrix multiply(const Matrix matrix1, const Matrix matrix2)
|
||||
|
||||
for (int k = 0; k < matrix1.cols; k++)
|
||||
{
|
||||
sum += getMatrixAt(matrix1, k, j) * getMatrixAt(matrix2, j, k);
|
||||
sum += getMatrixAt(matrix1, i, k) * getMatrixAt(matrix2, k, j);
|
||||
}
|
||||
|
||||
setMatrixAt(sum, matrix_erg, i, j);
|
||||
@ -266,8 +266,9 @@ Matrix multiply(const Matrix matrix1, const Matrix matrix2)
|
||||
|
||||
}
|
||||
|
||||
return matrix_erg;
|
||||
|
||||
}
|
||||
return matrix_erg;
|
||||
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user