Matrix 用高斯消去法求矩阵的逆

Matrix 用高斯消去法求矩阵的逆,matrix,inverse,Matrix,Inverse,如何求矩阵的逆?我试着用高斯消去法。我知道如何手工求解,但无法理解如何编码。这里清楚地解释了Guass Jordan消元法: 也是一个C++方法实现,它更适合于求矩阵的逆: 注意,请尝试理解该方法背后的推理。如果我正在学习这个主题,我可能会先尝试自己编写描述中的代码,然后在遇到问题时才查看编码解决方案 此外,如果你只是在谷歌上做一个有意义的搜索,可能还有其他语言的实现 祝你好运 这个问题本应得到10亿次的回答,但还行。首先,我不认为Gauss-Jordan方法是性能最好的方法。我假设矩阵在列表示

如何求矩阵的逆?我试着用高斯消去法。我知道如何手工求解,但无法理解如何编码。

这里清楚地解释了Guass Jordan消元法:

也是一个C++方法实现,它更适合于求矩阵的逆:

注意,请尝试理解该方法背后的推理。如果我正在学习这个主题,我可能会先尝试自己编写描述中的代码,然后在遇到问题时才查看编码解决方案

此外,如果你只是在谷歌上做一个有意义的搜索,可能还有其他语言的实现


祝你好运

这个问题本应得到10亿次的回答,但还行。首先,我不认为Gauss-Jordan方法是性能最好的方法。我假设矩阵在列表示法中是固定大小的3x3。下面的代码是Javascript代码,但很容易转换到任何其他语言

Matrix.prototype.inverse = function() {
  var c, l, det, ret = new Matrix();
  ret._M[0][0] =  (this._M[1][1] * this._M[2][2] - this._M[2][1] * this._M[1][2]);
  ret._M[0][1] = -(this._M[0][1] * this._M[2][2] - this._M[2][1] * this._M[0][2]);
  ret._M[0][2] =  (this._M[0][1] * this._M[1][2] - this._M[1][1] * this._M[0][2]);

  ret._M[1][0] = -(this._M[1][0] * this._M[2][2] - this._M[2][0] * this._M[1][2]);
  ret._M[1][1] =  (this._M[0][0] * this._M[2][2] - this._M[2][0] * this._M[0][2]);
  ret._M[1][2] = -(this._M[0][0] * this._M[1][2] - this._M[1][0] * this._M[0][2]);

  ret._M[2][0] =  (this._M[1][0] * this._M[2][1] - this._M[2][0] * this._M[1][1]);
  ret._M[2][1] = -(this._M[0][0] * this._M[2][1] - this._M[2][0] * this._M[0][1]);
  ret._M[2][2] =  (this._M[0][0] * this._M[1][1] - this._M[1][0] * this._M[0][1]);

  det = this._M[0][0] * ret._M[0][0] + this._M[0][1] * ret._M[1][0] + this._M[0][2] * ret._M[2][0];

  for (c = 0; c < 3; c++) {
    for (l = 0; l < 3; l++) {
      ret._M[c][l] = ret._M[c][l] / det;
    }
  }
  this._M = ret._M;
};

用什么语言?你是怎么尝试的?