# using System using System Collections Generic using System Linq using

 ``` 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72``` ```using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace L1 { class ModifyGauss { Matrix mMatrix; Matrix b; public ModifyGauss(Matrix matrix, Matrix b) { this.mMatrix = matrix; this.b = b; } public double[] getSolve() { double[] x = new double[b.GetLength(0)]; int n = x.Length; for (int k = 0; k < n - 1; ++k) { int p = k; for (int m = k + 1; m < n; ++m) { if (mMatrix[p, k] < mMatrix[m, k]) { p = m; } } double r; for (int j = k; j < n; ++j) { r = mMatrix[k, j]; mMatrix[k, j] = mMatrix[p, j]; mMatrix[p, j] = r; } r = b[k, 0]; b[k, 0] = b[p, 0]; b[p, 0] = r; for (int m = k + 1; m < n; ++m) { double c = mMatrix[m, k] / mMatrix[k, k]; b[m, 0] -= c * b[k, 0]; for (int i = k; i < n; ++i) { mMatrix[m, i] -= c * mMatrix[k, i]; } } } x[n - 1] = b[n - 1, 0] / mMatrix[n - 1, n - 1]; for (int k = n - 2; k >= 0; --k) { double s = 0; for (int i = k + 1; i < n; ++i) { s += mMatrix[k, i] * x[i]; } x[k] = (b[k, 0] - s) / mMatrix[k, k]; } return x; } } } ```