lizfcm/notes/Oct-4.org
2023-10-09 21:08:25 -06:00

604 B

[[ a11 a12 ⋯ a1n | b_1] [ 0 (a22 - \frac{a_{}21}{a22}a11) ⋯ a2n | b_2 - \frac{a21}{a11}b_1 ]]

  for (int i = 1; i < n; i++) {
    float factor = -a[i][0] / a[0][0];
    for (int j = 1; j < n; j++) {
      a[i][j] = a[i][j] + factor * a[0][j];
    }
    b[i] = b[i] + factor * b[0];
  }

  for (int k = 0; k < (n - 1); k++) {
    for (int i = k+1; i < n; i++) {
      float factor = -a[i][k] / a[k][k];
      for (int j = k+1; j < n; j++) {
        a[i][j] = a[i][j] + factor * a[j][k];
      }
      b[i] = b[i] + factor*b[k];
    }
  }