I have class with
double *matrix;
int _row;
int _col;
in loop:
for (int i = 0; i < _row; i++) {
for (int j = 0; j < _col; j++) {
matrix[i * _col + j] = 0.0;
}
}
I need to multiply two matrix and get a new one:
Matrix MatrixOperations::Mul(const Matrix &m1, const Matrix &m2) {
if (m1.CheckMul(m2)) {
Matrix temp(m1._row, m2._col);
for (int i = 0; i < temp._row; i++) {
for (int j = 0; j < temp._col; j++) {
for (int k = 0; k <= temp._col; k++) {
temp.matrix[i * temp._col + j] += m1.matrix[i * temp._col + k] * m2.matrix[k * temp._col + j];
}
}
}
return temp;
}
}
The code is incorrect. I think the indexes are wrong, but I can't understand nor see which ones.
Does anyone have any idea? Thanks.