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

View File

@ -3,7 +3,7 @@
* Bietet Funktionen fuer Operationen mit Matrizen
*
* Datum: Autor: Grund der Aenderung:
*
*
*
\**********************************************************************/
@ -18,7 +18,7 @@
* Erstellt eine neue Matrix (cM)
* - reserviert lediglich den notwendigen Speicher
* - 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 m;
@ -37,7 +37,7 @@ Matrix createMatrixZero(unsigned int spalten, unsigned int zeilen) {
Matrix m = createMatrix(spalten, zeilen);
if (m.mElement != NULL) {
for (unsigned int i = 0; i < spalten * zeilen; i++) {
m.mElement[i] = 0.0f;
m.mElement[i] = 0.0;
}
}
return m;
@ -52,7 +52,7 @@ Matrix createMatrixRand(unsigned int spalten, unsigned int zeilen) {
Matrix m = createMatrix(spalten, zeilen);
srand((unsigned int)time(NULL));
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;
}
@ -106,7 +106,7 @@ MatTyp getEntryAt(const Matrix ma, unsigned int xPos, unsigned int yPos) {
\*--------------------------------------------------------------------*/
Bool setEntryAt(Matrix ma, unsigned int xPos, unsigned int yPos, MatTyp value) {
if (xPos >= ma.spalten || yPos >= ma.zeilen) return FALSE;
ma.mElement[yPos * ma.spalten + xPos] = value;
ma.mElement[yPos * ma.spalten + xPos] = value;
return TRUE;
}
@ -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)
\*--------------------------------------------------------------------*/
void printMatrix(const Matrix ma) {
printf("(\n");
printf("\n");
for (unsigned int y = 0; y < ma.zeilen; y++) {
printf(" ");
printf("( ");
for (unsigned int x = 0; x < ma.spalten; x++) {
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);
for (unsigned int y = 0; y < result.zeilen; y++) {
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++) {
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
\*--------------------------------------------------------------------*/
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 b = getEntryAt(ma, 1, 0);
float c = getEntryAt(ma, 0, 1);