nächster Termin
This commit is contained in:
1 parent
c229a6b2d4
commit
eefb2829c1
1 file changed
+46
-3
+46
-3
@@ -9,29 +9,72 @@ Matrix createMatrix(unsigned int rows, unsigned int cols)
|
||||
Matrix m;
|
||||
m.rows = rows;
|
||||
m.cols = cols;
|
||||
m.Memory = malloc(rows*cols*sizeof(MatrixType)) //
|
||||
return m;
|
||||
}
|
||||
|
||||
void clearMatrix(Matrix *matrix)
|
||||
{
|
||||
|
||||
for (unsigned int i = 0; i < (*matrix).rows; i++) {
|
||||
for (unsigned int j = 0; j < (*matrix).cols; j++) {
|
||||
(*matrix).Memory[i * (*matrix).cols + j] = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void setMatrixAt(MatrixType value, Matrix matrix, unsigned int rowIdx, unsigned int colIdx)
|
||||
{
|
||||
|
||||
if (rowIdx >= matrix.rows || colIdx >= matrix.cols) {
|
||||
printf("Fehler: Index außerhalb der Matrix\n");
|
||||
return;
|
||||
}
|
||||
matrix.Memory[rowIdx * matrix.cols + colIdx] = value;
|
||||
}
|
||||
|
||||
MatrixType getMatrixAt(const Matrix matrix, unsigned int rowIdx, unsigned int colIdx)
|
||||
{
|
||||
|
||||
if (rowIdx >= matrix.rows || colIdx >= matrix.cols) {
|
||||
printf("Fehler: Index außerhalb der Matrix\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
return matrix.Memory[rowIdx * matrix.cols + colIdx];
|
||||
}
|
||||
|
||||
Matrix add(const Matrix matrix1, const Matrix matrix2)
|
||||
{
|
||||
|
||||
//2 fälle 1. 2 matrizen exakt gleich groß, dann einfach jeden wert mit der selben pos addieren
|
||||
// 2. 1 matrix beliebig groß und einen vektor, 1 spalte aber dafür rows gleich viele, dann einfach in jeder spalte einmal die row zahl vom vektor drauf addieren
|
||||
if (matrix1.rows == matrix2.rows && matrix1.cols == matrix2.cols){
|
||||
|
||||
}
|
||||
|
||||
ifelse(matrix1.cols == 1 || matrix2.cols == 1)
|
||||
{
|
||||
|
||||
//sub fälle (1matrix vektor) (2matrix vektor) (beides vektoren)
|
||||
|
||||
|
||||
}
|
||||
|
||||
else{
|
||||
printf("Fehler: Matrizen können nicht miteinander addiert werden\n");
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
Matrix multiply(const Matrix matrix1, const Matrix matrix2)
|
||||
{
|
||||
if (matrix1.rows == matrix2.cols);
|
||||
|
||||
|
||||
|
||||
|
||||
else{
|
||||
printf("Fehler: Matrizen können nicht miteinander multipliziert werden\n");
|
||||
}
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user