I am trying to put the finishing touches on my Matrix project, but my calculation for multiplying matrices appears to be wrong.

Here is my code first of all, then I will explain:

MATRIX MATRIX::MultMat(MATRIX MatB) { //create a result matrix MATRIX result; for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { result.Mat[i][j] = 0; for (int k = 0; k < 3; k++) { result.Mat[i][j] = result.Mat[i][j] + Mat[i][k]*MatB.Mat[k][j]; } } }

When multiplying Matrices, we take the sum of the multiplication of the first row's cells and the first column's cells.

An example of this would be:

[1 2] [5 6] = [19 22]

[3 4] [7 8] = [43 50]

To find the first # of matrix 3, we do:

(1*5) + (2*7) = 19

Next value (to the right of 19) would be:

(1*6) + (2*8) = 22

Completing the Result Matrix:

(3*5) + (4*7) = 43

(3*6) + (4*8) = 50

I hope I'm doing this correctly.

Can you all please help me derive the correct formula for computing this?

It involves a bunch of nasty for loops, and I THOUGHT I had it but I don't appear to be correct.

Thank you so much!