There are 3 matrices. The output of the matrices A and B should be output into the matrix C. The question is how to divide the data of the array and output each value separately in the input? I understand you need a cycle in which there will be a separation of values and output to the required place. While it is worth outputting the work only to the console.
I understand the easiest way to decompose an array is through foreach? But it doesn’t seem to work in ie8.
Below, the first function reads the values from the inputs of the matrices A and B and, even lower, the function that multiplies them. http://codepen.io/anon/pen/vGPEde full code.
function readMatrixFromDom(aClassName) { var result = []; var rows = $('.' + aClassName).find('tr'); for (var i = 0; i < rows.length; i++) { result.push([]); var cells = $(rows[i]).find('td > input'); for (var j = 0; j < cells.length; j++) { result[i].push(+$(cells[j]).val()); } } return result; } function MultiplyMatrix(A,B){ var A = readMatrixFromDom('matrix_a'); var B = readMatrixFromDom('matrix_b'); var c_mat = readMatrixFromDom('matrix_c'); var rowsA = A.length, colsA = A[0].length, rowsB = B.length, colsB = B[0].length, C = []; if (colsA != rowsB) return false; for (var i = 0; i < rowsA; i++) C[i] = []; for (var k = 0; k < colsB; k++){ for (var i = 0; i < rowsA; i++){ var t = 0; for (var j = 0; j < rowsB; j++) t += A[i][j]*B[j][k]; C[i][k] = t; } } console.log(C); }); return C; } $(document).on('click', '.umn' , function () { MultiplyMatrix(); });