fixed matrix errors

This commit is contained in:
Tobias Grampp 2025-11-20 16:28:10 +01:00
parent 3adc90e98c
commit 963eb3b3a4
2 changed files with 13 additions and 10 deletions

View File

@ -5,11 +5,11 @@
// TODO Matrix-Funktionen implementieren
typedef struct Matrix {
typedef struct Matrix{
unsigned int rows;
unsigned int cols;
MatrixType* buffer;
} Matrix;
}Matrix;
Matrix createMatrix(unsigned int rows, unsigned int cols)
@ -31,10 +31,10 @@ void setMatrixAt(MatrixType value, Matrix matrix, unsigned int rowIdx, unsigned
{
if (rowIdx >= matrix.rows || colIdx >= matrix.cols){
printf("Index out of bounds\n"); //Error Message because Index Input exceeds Matrix
}
}
else{
matrix.buffer[rowIdx * matrix.cols + colIdx] = value; //Writes Value of value variable in the selected place in Matrix
}
}
}
MatrixType getMatrixAt(const Matrix matrix, unsigned int rowIdx, unsigned int colIdx)
@ -47,8 +47,8 @@ MatrixType getMatrixAt(const Matrix matrix, unsigned int rowIdx, unsigned int co
MatrixType value = matrix.buffer[rowIdx * matrix.cols + colIdx]; //Stores value of selected place of Matrix in value variable
return value;
}
}
}
Matrix add(const Matrix matrix1, const Matrix matrix2)
{
@ -65,16 +65,15 @@ Matrix add(const Matrix matrix1, const Matrix matrix2)
//Adding Matrix Elements of same row and col index together and store in new Matrix
MatrixErgebnis.buffer[i * matrix1.cols + j] = matrix1.buffer[i * matrix1.cols + j] + matrix2.buffer[i * matrix1.cols + j];
}
}
}
}
return MatrixErgebnis;
}
return MatrixErgebnis;
}
Matrix multiply(const Matrix matrix1, const Matrix matrix2)
{
Matrix result;
result.rows = matrix1.rows;
result.cols = matrix2.cols;

View File

@ -7,7 +7,11 @@ typedef float MatrixType;
// TODO Matrixtyp definieren
typedef struct Matrix Matrix;
typedef struct Matrix{
unsigned int rows;
unsigned int cols;
MatrixType* buffer;
}Matrix;