showing results for - "matrix multiplication js"
Thea
09 Mar 2020
1function multiplyMatrix(matrixA, matrixB)
2{
3    var result = new Array();//declare an array   
4
5    //var numColsRows=$("#matrixRC").val();
6    numColsRows=2;
7    
8    //iterating through first matrix rows
9    for (var i = 0; i < numColsRows; i++) 
10    {
11        //iterating through second matrix columns
12        for (var j = 0; j < numColsRows; j++) 
13        { 
14            var matrixRow = new Array();//declare an array
15            var rrr = new Array();
16            var resu = new Array();
17            //calculating sum of pairwise products
18            for (var k = 0; k < numColsRows; k++) 
19            {
20                rrr.push(parseInt(matrixA[i][k])*parseInt(matrixB[k][j]));
21            }//for 3
22            resu.push(parseInt(rrr[i])+parseInt(rrr[i+1]));
23
24            result.push(resu);
25            //result.push(matrixRow);
26        }//for 2
27    }//for 1
28    return result;
29}// function multiplyMatrix
Henry
14 May 2016
1function multiply(a, b) {
2  var aNumRows = a.length, aNumCols = a[0].length,
3      bNumRows = b.length, bNumCols = b[0].length,
4      m = new Array(aNumRows);  // initialize array of rows
5  for (var r = 0; r < aNumRows; ++r) {
6    m[r] = new Array(bNumCols); // initialize the current row
7    for (var c = 0; c < bNumCols; ++c) {
8      m[r][c] = 0;             // initialize the current cell
9      for (var i = 0; i < aNumCols; ++i) {
10        m[r][c] += a[r][i] * b[i][c];
11      }
12    }
13  }
14  return m;
15}
similar questions
matrix multiplication