示例#1
0
        /// <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);
        }
        /// <summary>
        /// Сложение строк. True - удачно, False - невозможно
        /// </summary>
        /// <param name="num1">Строка, к которой прибалять и в которую записывается ответ</param>
        /// <returns></returns>
        public bool LineDifference(MatrixFractions matrix, int num1, int num2, SimpleFractions koeff)
        {
            MatrixFractions matrixFractions = matrix;

            if (num1 > matrixFractions.N || num2 > matrixFractions.N || num1 < 0 || num2 < 0)
            {
                return(false);
            }
            SimpleFractionsMeneger sFM = new SimpleFractionsMeneger();

            for (int j = 0; j < matrixFractions.M; j++)
            {
                matrixFractions.Matrix[num1, j] = sFM.Sum(matrixFractions.Matrix[num1, j],
                                                          sFM.Multiplication(koeff, matrixFractions.Matrix[num2, j]));
            }
            matrix = matrixFractions;
            return(true);
        }