I try to make a JavaScript function to show steps of solving a Linear Equation System using the Gauss method.(我尝试制作一个JavaScript函数来显示使用高斯方法求解线性方程组的步骤 。)
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.(我得到的是window.GaussMatrixSteps
是相同矩阵的数组(最后一步),而不是来自不同步骤的不同矩阵。) Is it really how JavaScript works?(这真的是JavaScript的工作方式吗?)
ask by aryafilan translate from so
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…