1. ## Matrix Multiplication

Am I correct? Because the program is not running correctly!

Code:
for(loop1 = 0; loop1 < no_of_rows1; loop1++)
{
for(loop2 = 0; loop2 < no_of_cols2; loop2++)
{
result[loop1][loop2] = 0;
for(loop3 = 0; loop3 < no_of_cols1; loop3++)
result[loop1][loop2] += matrix1[loop1][loop3] * matrix2[loop3][loop2];
printf("%d\t",result[loop1][loop2]);
}
printf("\n");
}

2. %d worries me a little bit, but if your matrices are integers then that's fine. Otherwise the logic is correct.

3. I think your first (outer most) loop should be columns and the second loop should be rows. I think you're getting result = BA but you're expecting result = AB.

4. Originally Posted by Zlatko
I think your first (outer most) loop should be columns and the second loop should be rows. I think you're getting result = BA but you're expecting result = AB.
I'm not sure about that, usually row comes first, but that depends on if its row-major or column-major.

5. Originally Posted by Spidey
I'm not sure about that, usually row comes first, but that depends on if its row-major or column-major.
My mistake.

6. Originally Posted by Spidey
I'm not sure about that, usually row comes first, but that depends on if its row-major or column-major.
True, when you define your matrix; but in the code you are needing to navigate across the columns in A's matrix to multiply against the rows of matrix B.

7. Originally Posted by slingerland3g
True, when you define your matrix; but in the code you are needing to navigate across the columns in A's matrix to multiply against the rows of matrix B.
Except, of course, that's exactly backwards. (The rows of the first matrix are multiplied agianst the columns of the second.)

8. Originally Posted by slingerland3g
True, when you define your matrix; but in the code you are needing to navigate across the columns in A's matrix to multiply against the rows of matrix B.
Nope, Rows of A against Colums of B.

9. Ok, my logic is correct but definition was not clear. I meant that you multiply across your rows in matrix A and then down each column in matric B. My saving grace was I stated "Across the columns in Matric A". It was just my point of view. In other words multiply the first row vector in matrix A against the column vector of matrix B.

10. Originally Posted by slingerland3g
Ok, my logic is correct but definition was not clear. I meant that you multiply across your rows in matrix A and then down each column in matric B. My saving grace was I stated "Across the columns in Matric A". It was just my point of view. In other words multiply the first row vector in matrix A against the column vector of matrix B.
And in other words, that's exactly what was posted. (The second index is changing for matrix A -- so we're keeping the row and moving from column to column; this is what we mean by "a row of A".)

11. You cannot concatenate two arbitrary sized matrices together and expect a meaningful result. Your code will not work for all matrices yet attempts to give the illusion that it does.

12. Program works correctly for square and non-square matrices.

13. Okay thanks a lot..