matrixMultiply erstellt
This commit is contained in:
parent
f3b964f17e
commit
c96311347e
36
matrix.c
36
matrix.c
@ -152,8 +152,44 @@ 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;
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user