Hi C Wizards,
I have this routine, which work perfectly fine if the matrix is small (5x5), but fails miserably with the matrix is larger (15 x 15).. ... I need to operate with matrices that are at least 500 x 500 (or even 2000 x 2000 and they are float units). My basic routine is:
float *MatrixMultiply (int r1, int c1, float Array1[][c1], int c2, float Array2[][c2], float Result[r1][c2])
{
int i, j, k;
for (i = 0; i < r1; i++)
{
for (j = 0; j < c2; j++)
{
Result[j] = 0.0;
for (k = 0; k < c1; k++) // c1 == r2
{
Result[j] += Array1[k] * Array2[k][j];
}
}
}
return Result[0];
}
If I test this with
float malo [3][3] ={1.0, 0.7, 0.1, 0.56, 1.43, 0.21, 0.56, 0.43, 1.21};
float bueno [3][3] ={2.0, 7.0, 5.1, 5.6, 4.3, 2.1, 6.8, 4.83, 2.1};
it works perfectly, but it fails when I try a larger matrix (15 x 15). Does any one knows what is going on?
On the other hand, apparently, I am not doing a good work by sending the matrix as an argument, and instead I should be sending pointers (so the matrices are manipulated directly). Does anyone knows how I can change this to use pointers???
Thanks in advanced
Regards