This commit is contained in:
Daniel Zwanzig 2025-05-22 14:35:18 +02:00
parent 82f7af17c3
commit 7b1b698fd3

View File

@ -18,7 +18,7 @@
* Erstellt eine neue Matrix (cM) * Erstellt eine neue Matrix (cM)
* - reserviert lediglich den notwendigen Speicher * - reserviert lediglich den notwendigen Speicher
* - dynamische Verwaltung von Speicher muss mit malloc() und free() * - dynamische Verwaltung von Speicher muss mit malloc() und free()
* durchgef<EFBFBD>hrt werden; dynamische Arrays sind nicht erlaubt !!! * durchgef<65>hrt werden; dynamische Arrays sind nicht erlaubt !!!
\*--------------------------------------------------------------------*/ \*--------------------------------------------------------------------*/
Matrix createMatrix(unsigned int spalten, unsigned int zeilen) { Matrix createMatrix(unsigned int spalten, unsigned int zeilen) {
Matrix m; Matrix m;
@ -37,7 +37,7 @@ Matrix createMatrixZero(unsigned int spalten, unsigned int zeilen) {
Matrix m = createMatrix(spalten, zeilen); Matrix m = createMatrix(spalten, zeilen);
if (m.mElement != NULL) { if (m.mElement != NULL) {
for (unsigned int i = 0; i < spalten * zeilen; i++) { for (unsigned int i = 0; i < spalten * zeilen; i++) {
m.mElement[i] = 0.0f; m.mElement[i] = 0.0;
} }
} }
return m; return m;
@ -52,7 +52,7 @@ Matrix createMatrixRand(unsigned int spalten, unsigned int zeilen) {
Matrix m = createMatrix(spalten, zeilen); Matrix m = createMatrix(spalten, zeilen);
srand((unsigned int)time(NULL)); srand((unsigned int)time(NULL));
for (unsigned int i = 0; i < spalten * zeilen; i++) { for (unsigned int i = 0; i < spalten * zeilen; i++) {
m.mElement[i] = ((float)rand() / RAND_MAX) * 200.0f - 100.0f; m.mElement[i] = ((float)rand() / RAND_MAX) * 200.0 - 100.0;
} }
return m; return m;
} }
@ -115,9 +115,9 @@ Bool setEntryAt(Matrix ma, unsigned int xPos, unsigned int yPos, MatTyp value) {
* Gibt eine Matrix im Kommandofenster "schoen formatiert" aus (pM) * Gibt eine Matrix im Kommandofenster "schoen formatiert" aus (pM)
\*--------------------------------------------------------------------*/ \*--------------------------------------------------------------------*/
void printMatrix(const Matrix ma) { void printMatrix(const Matrix ma) {
printf("(\n"); printf("\n");
for (unsigned int y = 0; y < ma.zeilen; y++) { for (unsigned int y = 0; y < ma.zeilen; y++) {
printf(" "); printf("( ");
for (unsigned int x = 0; x < ma.spalten; x++) { for (unsigned int x = 0; x < ma.spalten; x++) {
printf("%6.2f ", getEntryAt(ma, x, y)); printf("%6.2f ", getEntryAt(ma, x, y));
} }
@ -170,7 +170,7 @@ Matrix multMatrix(const Matrix ma, const Matrix mb) {
Matrix result = createMatrix(mb.spalten, ma.zeilen); Matrix result = createMatrix(mb.spalten, ma.zeilen);
for (unsigned int y = 0; y < result.zeilen; y++) { for (unsigned int y = 0; y < result.zeilen; y++) {
for (unsigned int x = 0; x < result.spalten; x++) { for (unsigned int x = 0; x < result.spalten; x++) {
float sum = 0.0f; float sum = 0.0;
for (unsigned int k = 0; k < ma.spalten; k++) { for (unsigned int k = 0; k < ma.spalten; k++) {
sum += getEntryAt(ma, k, y) * getEntryAt(mb, x, k); sum += getEntryAt(ma, k, y) * getEntryAt(mb, x, k);
} }
@ -202,7 +202,7 @@ Matrix transposeMatrix(const Matrix ma) {
* wer moechte kann auch ein effizientes Verfahren implementieren * wer moechte kann auch ein effizientes Verfahren implementieren
\*--------------------------------------------------------------------*/ \*--------------------------------------------------------------------*/
double determMatrix(const Matrix ma) { double determMatrix(const Matrix ma) {
if (ma.spalten != 2 || ma.zeilen != 2) return ERROR; if (ma.spalten < 2 || ma.zeilen < 2) return ERROR;
float a = getEntryAt(ma, 0, 0); float a = getEntryAt(ma, 0, 0);
float b = getEntryAt(ma, 1, 0); float b = getEntryAt(ma, 1, 0);
float c = getEntryAt(ma, 0, 1); float c = getEntryAt(ma, 0, 1);