I try to make a JavaScript function to show steps of solving a Linear Equation System using the Gauss method. What I got so far (only small part of Gauss elimination method, constructing leading zeros):
let mt = [[2, 3, -1, 5], [4, 0, -3, 3], [-2, 3, -1, 1]];
gaussMethod(mt);
function gaussMethod(mtx) {
window.GaussMatrixSteps = [];
window.GaussMatrixSteps[0] = mtx;
let n = mtx.length;
for (i = 0; i < n; i++) {
for (k = i + 1; k < n; k++) {
var multiplier = mtx[k][i] / mtx[i][i];
for (j = 0; j <= n; j++) {
mtx[k][j] = mtx[k][j] - mtx[i][j] * multiplier;
}
}
window.GaussMatrixSteps[i + 1] = mtx;
}
}
What I get, window.GaussMatrixSteps is an array of same matrices (the last step) instead of different matrices from the different steps. Is it really how JavaScript works?