private void RunGaussElimination() { long s = 0; RationalNumber t = new(0, 1); for (long k = 0; k < m; k++) { long i_max = -1; while (true) { if (k + s == n) { return; } for (long i = k; i < m; i++) { if (!A[i][k + s].IsEqualsTo0()) { i_max = i; } } if (i_max == -1) { s++; } else { break; } } (A[k], A[i_max]) = (A[i_max], A[k]); long p = k + s; RationalNumber[] Mk = A[k]; RationalNumber Mkp = Mk[p]; for (long i = k + 1; i < m; i++) { RationalNumber Mip = A[i][p]; if (Mip.IsEqualsTo0()) { continue; } RationalNumber[] Mi = A[i]; for (long j = p + 1; j < n + 1; j++) { RationalNumber Mkj = Mk[j]; if (Mkj.IsEqualsTo0()) { continue; } t.Assign(Mip); t.Div(Mkp); t.Mult(Mkj); t.Subtr(Mi[j]); Mi[j] = new RationalNumber(t); } Mip.Assign0(); } } }
private void RunGaussElimination() { long s = 0; RationalNumber t = new(0, 1); for (long k = 0; k < m; k++) { long i_max = -1; while (true) { if (k + s == n) { return; } for (long i = k; i < m; i++) { if (!(A.Get(i, k + s).IsEqualsTo0())) { i_max = i; } } if (i_max == -1) { s++; } else { break; } } A.SwapRows(k, i_max); long p = k + s; SortedDictionary <long, RationalNumber> Mk = A.GetRow(k); RationalNumber Mkp = SparseMatrix.Get(Mk, p); for (long i = k + 1; i < m; i++) { RationalNumber Mip = A.Get(i, p); if (Mip.IsEqualsTo0()) { continue; } SortedDictionary <long, RationalNumber> Mi = A.GetRow(i); for (long j = p + 1; j < n + 1; j++) { RationalNumber Mkj = SparseMatrix.Get(Mk, j); if (Mkj.IsEqualsTo0()) { continue; } t.Assign(Mip); t.Div(Mkp); t.Mult(Mkj); RationalNumber Mij = SparseMatrix.Get(Mi, j); Mij.Subtr(t); SparseMatrix.Set(Mi, j, Mij); } Mip.Assign0(); A.Set(i, p, Mip); } } }