Compare commits
No commits in common. "5b32e1475c1c0840a325066a1e176a0880cb1e33" and "f3b964f17e3b741397fd7741de4dcf615369f3bd" have entirely different histories.
5b32e1475c
...
f3b964f17e
42
matrix.c
42
matrix.c
@ -1,6 +1,5 @@
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include "matrix.h"
|
||||
|
||||
// TODO Matrix-Funktionen implementieren
|
||||
@ -153,49 +152,8 @@ return matrix_erg;
|
||||
|
||||
|
||||
}
|
||||
static int can_multiply (Matrix matrix1, Matrix matrix2)
|
||||
{
|
||||
int can_multiply = 0;
|
||||
|
||||
if(matrix1.cols == matrix2.rows)
|
||||
can_multiply = 1;
|
||||
|
||||
return can_multiply;
|
||||
}
|
||||
|
||||
|
||||
Matrix multiply(const Matrix matrix1, const Matrix matrix2)
|
||||
{
|
||||
int ok = can_multiply(matrix1,matrix2);
|
||||
unsigned int erg_rows = matrix1.rows;
|
||||
unsigned int erg_cols = matrix2.cols;
|
||||
Matrix matrix_erg = createMatrix(erg_rows, erg_cols);
|
||||
|
||||
|
||||
if (ok == 1)
|
||||
{
|
||||
|
||||
for (int i = 0; i < erg_rows; i++)
|
||||
{
|
||||
for (int j = 0; j < erg_cols; j++)
|
||||
{
|
||||
MatrixType sum = 0;
|
||||
|
||||
for (int k = 0; k < matrix1.cols; k++)
|
||||
{
|
||||
sum += matrix1.data[i * matrix1.cols + k] * matrix2.data[k * matrix2.cols + j];
|
||||
}
|
||||
|
||||
matrix_erg.data [i * erg_cols + j] = sum;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return matrix_erg;
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("Matrix multiplication not possible\n");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user