I'm doing a function that multiplies 2 matrices.
The matrices will always have the same number of rows and columns. (2x2, 5x5, 23x23, ...)
When I print it, it doesn't work. Why?
For example, if I create two 2x2 matrices:
matrixA:
[1][2]
[3][4]
matrixB:
[5][6]
[7][8]
The result should be:
[19][22]
[43][50]
(http://ncalculators.com/matrix/2x2-matrix-multiplication-calculator.htm)
But, I get:
[19][undefined]
[22][indefined]
function multiplyMatrix(matrixA, matrixB) {
var result = new Array(); //declare an array
//var numColsRows=$("#matrixRC").val();
numColsRows = 2;
//iterating through first matrix rows
for (var i = 0; i < numColsRows; i++) {
//iterating through second matrix columns
for (var j = 0; j < numColsRows; j++) {
var matrixRow = new Array(); //declare an array
var rrr = new Array();
var resu = new Array();
//calculating sum of pairwise products
for (var k = 0; k < numColsRows; k++) {
rrr.push(parseInt(matrixA[i][k]) * parseInt(matrixB[k][j]));
} //for 3
resu.push(parseInt(rrr[i]) + parseInt(rrr[i + 1]));
result.push(resu);
//result.push(matrixRow);
} //for 2
} //for 1
return result;
} // function multiplyMatrix