My matrix result has encountered an issue of being undefined. The error message displayed in my chrome console at line 25 is: "Cannot set property "0" of undefined."
After researching similar problems, I've noticed that most solutions for matrix multiplication involve 3 nested loops compared to my 4 nested loops. While the former seems to be more efficient, I find it necessary to use four loops as my iteration spans over two distinct rows and columns. If this difference is causing the bug problem, I would appreciate an explanation on why that is so.
const A = [ [-4,0,5], [-3,-1,2], [6,7,-2], [1, 1, 2]],B = [ [1, 0, 3, 0], [4,5,-1, 2], [2, 4, 3, 1]],C = [];
for (var i = 0; i < A.length; i++) {
//C[i] = 0;
for (var j = 0; j < A[j].length; j++) {
//console.log(A[i][j]);
for (var y = 0; y < B[0].length; y++) {
C[i][y] = 0;
for (var x = 0; x < B.length; x++) {
//console.log(B[x][y]+ "["+x+","+y+"]");
console.log(C[i][y] + "[" + i + "," + y);
C[i][y] += A[i][j] * B[x][y];
}
console.log(C[i][y] + "[" + i + "," + y + "] is the resultant matrix");
}
}
}