want create matrix multiplaction but my web-site calculate wrong. can you see where the error is, can you fix it.Thank you so much for helping.
I want create matrix multiplaction but my web-site calculate wrong. can you see where the error is, can you fix it.Thank you so much for helping.
<script>
window.multiply = function() {
var matrix1Arr=[], matrix2Arr=[];
for (var k=0; k<5; k++) {
matrix1Arr[k] = []; p=0;
for (var p = 0; p < 5; p++) {
matrix1Arr[k][p] = document.getElementById("mat1_"+k+p).value;
}
}
for (var k=0; k<5; k++) {
matrix2Arr[k] = []; p=0;
for (var p = 0; p < 5; p++) {
matrix2Arr[k][p] = document.getElementById("mat2_"+k+p).value;
}
}
var result = multiplyMatrix(matrix1Arr, matrix2Arr);
for (var l=0; l<5; l++) {
for (var m=0; m<5; m++) {
document.getElementById("mat3_"+l+m).value=result[l][m];
}
}
}
function multiplyMatrix(m1, m2) {
var result = [];
for(var j = 0; j < m2.length; j++) {
result[j] = [];
for(var k = 0; k < m1[0].length; k++) {
var sum = 0;
for(var i = 0; i < m1.length; i++) {
sum += m1[i][k] * m2[j][i];
}
result[j].push(sum);
}
}
return result;
}
</script
Trending now
This is a popular solution!
Step by step
Solved in 2 steps