/// <summary> /// Вывод ответа /// </summary> private List <SimpleFractions> PrintAnswer(List <List <SimpleFractions> > table, List <int> basis, List <SimpleFractions> F) { List <SimpleFractions> answer = new List <SimpleFractions>(); string str = ""; for (int j = 1; j < table[0].Count; j++) { str += "x" + j + " = "; var id = basis.FindIndex(a => a == j - 1); if (id >= 0) { str += table[id][0].toString() + "\n"; answer.Add(table[id][0]); } else { str += "0\n"; answer.Add(new SimpleFractions(0, 1)); } } SimpleFractions fAnswer = new SimpleFractions(0, 1); for (int i = 0; i < answer.Count; i++) { fAnswer = sFM.Sum(fAnswer, sFM.Multiplication(answer[i], F[i])); } fAnswer = sFM.Sum(fAnswer, F[F.Count - 1]); answer.Add(fAnswer); str += "Z = " + fAnswer.toString(); if (Notify != null) { Notify(str); } return(answer); }
private void PrintAnswer(/*List<Tuple<string, SimpleFractions>> answer*/ MatrixFractions matrix) { if (Notify == null) { return; } SimpleFractionsMeneger sfm = new SimpleFractionsMeneger(); bool checkX; int countX; for (int strNum = 0, colNum = 0; strNum < matrix.N || colNum < matrix.N; strNum++, colNum++) { checkX = false; countX = 0; for (int i = 0; i < matrix.M - 1; i++) { if (matrix.Matrix[strNum, i].Numerator != 0) { if (colNum == i) { checkX = true; // обычный случай } countX++; } } if (countX == 1 && checkX == true) // обычный случай { SimpleFractions simpleAnswer = new SimpleFractions(); simpleAnswer = sfm.Division(matrix.Matrix[strNum, matrix.M - 1], matrix.Matrix[strNum, colNum]); Notify($"x{colNum + 1} = {simpleAnswer.toString()}\n"); } else if (countX == 0) // зануленная строка { if (matrix.Matrix[strNum, matrix.M - 1].Numerator == 0) { Notify($"x{colNum + 1} - любое\n"); } else { Notify($"Что-то пошло не так. Противоречие. Система не имеет решений\n"); } } else if (countX >= 1)//когда в строке остались еще не зануленные х { int col = 0; while (matrix.Matrix[strNum, col].Numerator == 0) { col++; if (col >= matrix.M) { Notify($"Что-то пошло не так\n"); break; } } string strAnswer = $"x{col + 1} = "; if (matrix.Matrix[strNum, col].Numerator != matrix.Matrix[strNum, col].Denominator) { strAnswer += "( "; } if (matrix.Matrix[strNum, matrix.M - 1].Numerator != 0) { strAnswer += $" {matrix.Matrix[strNum, matrix.M - 1].toString()}"; } int idCol = col + 1; while (idCol < matrix.M - 1) { if (matrix.Matrix[strNum, idCol].Numerator != 0) { if (matrix.Matrix[strNum, idCol].Numerator == matrix.Matrix[strNum, idCol].Denominator) { strAnswer += $" - x{idCol + 1}"; } else { strAnswer += $" - ({matrix.Matrix[strNum, idCol].toString()})*x{idCol + 1}"; } } idCol++; } if (matrix.Matrix[strNum, col].Numerator != matrix.Matrix[strNum, col].Denominator) { strAnswer += $" ) / ( {matrix.Matrix[strNum, col].toString()} )"; } Notify($"{strAnswer}\n"); //string strAnswer = $"x{colNum + 1} = "; //if (matrix.Matrix[strNum, colNum].Numerator != matrix.Matrix[strNum, colNum].Denominator) // strAnswer += "( "; //if (matrix.Matrix[strNum, matrix.M - 1].Numerator != 0) // strAnswer += $" {matrix.Matrix[strNum, matrix.M - 1].toString()}"; //int idCol = matrix.N; //while (idCol < matrix.M - 1) //{ // if (matrix.Matrix[strNum, idCol].Numerator != 0) // { // if (matrix.Matrix[strNum, idCol].Numerator == matrix.Matrix[strNum, idCol].Denominator) // { // strAnswer += $" - x{colNum + 1}"; // } // else // { // strAnswer += $" - ({matrix.Matrix[strNum, idCol].toString()})*x{idCol + 1}"; // } // } // idCol++; //} /*SimpleFractions simpleAnswer = new SimpleFractions(); * simpleAnswer = sfm.Division(matrix.Matrix[strNum, matrix.M - 1], matrix.Matrix[strNum, idCol]); * strAnswer += $"{simpleAnswer.toString()}";*/ //if (matrix.Matrix[strNum, colNum].Numerator != matrix.Matrix[strNum, colNum].Denominator) // strAnswer += $" ) / ( {matrix.Matrix[strNum, colNum].toString()} )"; //Notify($"{strAnswer}\n"); } else { Notify($"Это не было предусмотрено(\n"); } } //if (Notify == null) return; //foreach (var a in answer) //{ // if (a.Item2 != null) // Notify($"{a.Item1} = {a.Item2.toString()}\n"); // else // Notify($"{a.Item1} - любое\n"); //} }