Exemplo n.º 1
0
 /// <summary>
 /// Создание первой таблицы
 /// </summary>
 private List <List <SimpleFractions> > CreateTable(MatrixFractions matrix, List <int> basis, List <SimpleFractions> F)
 {
     try
     {
         List <List <SimpleFractions> > list = new List <List <SimpleFractions> >();
         for (int i = 0; i < matrix.N; i++)
         {
             list.Add(new List <SimpleFractions>());
             list.LastOrDefault().Add(matrix.Matrix[i, matrix.M - 1]);
             for (int j = 0; j < matrix.M - 1; j++)
             {
                 list.LastOrDefault().Add(matrix.Matrix[i, j]);
             }
         }
         list.Add(new List <SimpleFractions>());
         for (int j = 0; j < matrix.M; j++)
         {
             SimpleFractions fractions;
             fractions = sFM.Multiplication(list[0][j], F[0]);
             for (int i = 1; i < matrix.N; i++)
             {
                 fractions = sFM.Sum(sFM.Multiplication(list[i][j], F[i]), fractions);
             }
             if (j != 0)
             {
                 fractions = sFM.Difference(fractions, F[j - 1]);
             }
             else
             {
                 fractions = sFM.Difference(fractions, F[F.Count - 1]);
             }
             list.LastOrDefault().Add(fractions);
         }
         return(list);
     }
     catch (Exception e)
     {
         return(null);
     }
 }
Exemplo n.º 2
0
        public bool Solutions_Jordan_Gauss_Metod(MatrixFractions matrix)
        {
            //if (matrix.M - 1 != matrix.N) { if (Notify != null) Notify($"Решение систем линейных уравнений методом Жордана-Гаусса.\nЭтот метод не подходит. Попробуйте другой!\n"); return false; }
            Rectangle rectangle = new Rectangle();

            rectangle.Notify += Message;
            var flag = rectangle.RectangleMetod(matrix);

            if (!flag)
            {
                if (Notify != null)
                {
                    Notify($"Метод прямоугольников выполнен не успешно или было найдено противоречие!\n");
                }
                return(false);
            }
            //var answer = Аnswer(matrix);
            if (Notify != null)
            {
                PrintAnswer(matrix);
            }
            return(true);
        }
Exemplo n.º 3
0
        static void Main(string[] args)
        {
            Console.Write("Номер примера (1-7): ");
            var    num  = Console.ReadLine();
            string path = @"matrix\" + num + ".txt";
            //StreamReader file = new StreamReader(path, Encoding.Default);
            //string str = file.ReadToEnd();
            //Console.Write(str);
            var matrix = read(path);

            if (matrix == null)
            {
                return;
            }
            MatrixFractions matrixFractions = new MatrixFractions(matrix);

            matrixFractions.Print();

            Solutions_Jordan_Gauss jordan_Gauss = new Solutions_Jordan_Gauss();

            jordan_Gauss.Notify += Message;
            jordan_Gauss.Solutions_Jordan_Gauss_Metod(matrixFractions);
        }
Exemplo n.º 4
0
        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");
            //}
        }