public EigenValues(FullMatrix mat, int maxSteps, double eps) { this.maxSteps = maxSteps; this.eps = eps; this.mat = mat; size = mat.size; MaxEigenValueVector = new double[size]; MinEigenValueVector = new double[size]; findMaxValue(); findMinValue(); }
public static FullMatrix Parse(string str) { string[] lines = str.Split('\n'); FullMatrix matrix = new FullMatrix(lines.Length); for (int i = 0; i < matrix.size; i++) { string[] row = lines[i].Split(' '); for (int j = 0; j < matrix.size; j++) { matrix[i, j] = double.Parse(row[j]); } } return(matrix); }
public static void SolveGauss(FullMatrix mat, Vector vec) { for (int i = 0; i < mat.size - 1; i++) { double maxValue = mat[i, i]; int maxValueIndex = i; for (int j = i + 1; j < mat.size; j++) { if (mat[j, i] > maxValue) { maxValue = mat[j, i]; maxValueIndex = j; } } if (maxValueIndex != i) { double tmp = vec[i]; vec[i] = vec[maxValueIndex]; vec[maxValueIndex] = tmp; for (int j = 0; j < mat.size; j++) { tmp = mat[i, j]; mat[i, j] = mat[maxValueIndex, j]; mat[maxValueIndex, j] = tmp; } } for (int j = i + 1; j < mat.size; j++) { double coef = mat[j, i] / mat[i, i]; for (int k = i; k < mat.size; k++) { mat[j, k] -= mat[i, k] * coef; } vec[j] -= vec[i] * coef; } } for (int i = mat.size - 1; i >= 0; i--) { for (int j = i + 1; j < mat.size; j++) { vec[i] -= mat[i, j] * vec[j]; } vec[i] /= mat[i, i]; } }