Guest User

Untitled

a guest
Dec 10th, 2012
193
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.51 KB | None | 0 0
  1. mMatrix* Math::matrixMatrixMultiplication(mMatrix *M1, mMatrix *M2){
  2.         mMatrix *result = new mMatrix(M1->rows,M2->columns);
  3.  
  4.         //Do the multiplication
  5.         for (int i = 0; i < M1->rows; i++) { //the result is M1_RowsxM2_Columns
  6.             for (int j = 0; j < M2->columns; j++) { //the result is M1_Rows x M2_Columns
  7.                 for (int k = 0; k < M2->rows; k++) { //for each column in M1 / row in M2
  8.                     result->theMatrix[i][j]+=M1->theMatrix[i][k]*M2->theMatrix[k][j];
  9.                 }
  10.             }
  11.         }
  12.  
  13.         return result;
  14.     }
  15.  
  16. fabio bento library
Advertisement
Add Comment
Please, Sign In to add comment