class Kramer Matrix mMatrix const double eps 00001 public Kramer Matri

 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
class Kramer
{
Matrix mMatrix;
const double eps = 0.00001;
public Kramer(Matrix matrix)
{
mMatrix = matrix;
}
public double[] getSolve()
{
Matrix main_koef = mMatrix.GetMainKoeff();
Matrix free_koef_column = mMatrix.GetFreeKoeff();
double[] solve = new double[main_koef.GetLength(0)];
double main_det = main_koef.GetDet();
if (Math.Abs(main_det) < eps) {
throw new Exception("Вырожденная матрица коэффициентов. Определитель равен нулю.");
}
for (int i = 0; i < solve.Length; ++i)
{
double new_det = replaceColumn(main_koef, free_koef_column, i).GetDet();
solve[i] = new_det / main_det;
}
return solve;
}
private Matrix replaceColumn(Matrix cur_matr, Matrix replacement_column, int column_index)
{
Matrix new_matrix = new Matrix(cur_matr);
for (int i = 0; i < cur_matr.GetLength(0); ++i)
{
new_matrix[i, column_index] = replacement_column[i, 0];
}
return new_matrix;
}
}