Пример #1
0
        private string TransRatioCalculationSubsit(int outSignal, int inSignal, string[,] array2Solve,
                                                   double[,] numberArr)
        {
            string tempResult1, tempResult2, cell;

            tempResult1 = tempResult2 = cell = string.Empty;
            int i, count, varsCount;

            count = array2Solve.GetLength(0);
            string[] tempArray  = new string[count];
            string[] substitArr = new string[count];

            varsCount = ModelVars.Count;
            for (i = 0; i < count; i++)
            {
                tempArray[i] = array2Solve[i, outSignal];
                if (isSymbolic.IsMatch(cell = RowArray[i].RowB))
                {
                    cell = ValueSubstitution(cell);
                }
                if (cell == "-0")
                {
                    cell = "0";
                }
                substitArr[i] = cell;
                double.TryParse(array2Solve[i, outSignal] = cell, out numberArr[i, outSignal]);
            }
            tempResult1 = DetCalc.SolvePathApproach(array2Solve, numberArr);
            for (i = 0; i < count; i++)
            {
                double.TryParse(array2Solve[i, outSignal] =
                                    tempArray[i], out numberArr[i, outSignal]);
            }

            if (inSignal != -1)
            {
                for (i = 0; i < count; i++)
                {
                    tempArray[i] = array2Solve[i, inSignal];
                    double.TryParse(array2Solve[i, inSignal] =
                                        substitArr[i], out numberArr[i, inSignal]);
                }
                tempResult2 = DetCalc.SolvePathApproach(array2Solve, numberArr);
                for (i = 0; i < count; i++)
                {
                    double.TryParse(array2Solve[i, inSignal] =
                                        tempArray[i], out numberArr[i, inSignal]);
                }

                return("(" + tempResult1 + ")/(" + tempResult2 + ")");
            }
            else
            {
                return(tempResult1);
            }
        }
Пример #2
0
        private void SolveWithoutErrors()
        {
            int    i, j, count;
            string result = string.Empty, systemDeterminant = string.Empty;

            count = RowArray.GetLength(0);
            string[,] array2Solve = new string[count, count];
            double[,] numberArr   = new double[count, count];
            for (j = 0; j < count; j++)
            {
                for (i = 0; i < count; i++)
                {
                    if (RowArray[i].Row[j].Equals("-0"))
                    {
                        array2Solve[i, j] = "0";
                    }
                    else
                    {
                        array2Solve[i, j] = RowArray[i].Row[j];
                    }
                    if (!array2Solve[i, j].Equals("0"))
                    {
                        double.TryParse(array2Solve[i, j], out numberArr[i, j]);
                    }
                }
            }

            if (SystemDeterminant.IsChecked == true)
            {            //Визначник системи
                systemDeterminant = Results[0] = DetCalc.SolvePathApproach(array2Solve, numberArr);
            }
            if (CompleteTransRatio.IsChecked == true)
            {            //Повний коефіцієнт передачі
                Results[1] = TransRatioCalculation(count - 1, 0, array2Solve, numberArr);
            }
            if (!string.IsNullOrEmpty(SignalOut) &&
                !string.IsNullOrEmpty(SignalIn))
            {            //Коефіцієнт передачі
                Results[2] = TransRatioCalculation(int.Parse(SignalOut) - 1, int.Parse(SignalIn) - 1,
                                                   array2Solve, numberArr);
            }
            else if (!string.IsNullOrEmpty(SignalOut))
            {
                string signal = string.Empty;

                if (string.IsNullOrEmpty(systemDeterminant))
                {
                    systemDeterminant = DetCalc.SolvePathApproach(array2Solve, numberArr);
                }

                signal = TransRatioCalculation(int.Parse(SignalOut) - 1, -1,
                                               array2Solve, numberArr);
                Results[2] = "(" + signal + ")/(" + systemDeterminant + ")";
            }
        }
Пример #3
0
        private string TransRatioCalculation(int outSignal, int inSignal, string[,] array2Solve,
                                             double[,] numberArr)
        {
            string tempResult1, tempResult2, result;

            tempResult1 = tempResult2 = result = string.Empty;
            int i, count = array2Solve.GetLength(0);

            string[] cells = new string[count];

            for (i = 0; i < count; i++)
            {
                cells[i] = RowArray[i].RowB;
                if (cells[i] == "-0")
                {
                    cells[i] = "0";
                }
                double.TryParse(array2Solve[i, outSignal] = cells[i], out numberArr[i, outSignal]);
            }
            tempResult1 = DetCalc.SolvePathApproach(array2Solve, numberArr);
            for (i = 0; i < count; i++)
            {
                double.TryParse(array2Solve[i, outSignal] = RowArray[i].Row[outSignal], out numberArr[i, outSignal]);
            }

            if (inSignal != -1)
            {
                for (i = 0; i < count; i++)
                {
                    double.TryParse(array2Solve[i, inSignal] = cells[i], out numberArr[i, inSignal]);
                }
                tempResult2 = DetCalc.SolvePathApproach(array2Solve, numberArr);
                for (i = 0; i < count; i++)
                {
                    double.TryParse(array2Solve[i, inSignal] = RowArray[i].Row[inSignal], out numberArr[i, inSignal]);
                }
                result = "(" + tempResult1 + ")/(" + tempResult2 + ")";
            }
            else
            {
                result = tempResult1;
            }

            return(result);
        }
Пример #4
0
        private string SolveWithSubstitution()
        {
            int    i, j, count;
            bool   ok;
            double dbl;
            string cell, tempCell, result, systemDeterminant;

            cell = tempCell = result = systemDeterminant = string.Empty;
            string[,] array2Solve;
            double[,] numberArr;

            Array.Clear(SubstitutionResults, 0, SubstitutionResults.Length);

            if (ModelVars.Count == 0)
            {
                return(string.Empty);
            }

            count = ResCount - 3;
            for (i = 0; (i < count) && (string.IsNullOrEmpty(Results[i])); i++)
            {
            }
            if (i >= count)
            {
                return("Не розраховано формульний результат");
            }

            j     = 0;
            ok    = true;
            count = ModelVars.Count;
            for (i = 0; (i < count) && ok; i++)
            {
                if (ModelVars[i].IsUsed == true)
                {
                    if (!string.IsNullOrEmpty(ModelVars[i].VarValue))
                    {
                        ok = true;
                        j  = 1;
                    }
                    else
                    {
                        ok = false;
                    }
                }
            }
            if (!ok)
            {
                return("Відсутнє значення підстановки");
            }
            else if (j == 0)
            {
                return(string.Empty);
            }
            else
            {
                count       = RowArray.GetLength(0);
                array2Solve = new string[count, count];
                numberArr   = new double[count, count];

                for (j = 0; j < count; j++)
                {
                    for (i = 0; i < count; i++)
                    {
                        cell = RowArray[i].Row[j];
                        if (cell == "-0")
                        {
                            cell = "0";
                        }
                        if (isSymbolic.IsMatch(cell))
                        {
                            cell = ValueSubstitution(cell);
                        }
                        if (cell != "0")
                        {
                            double.TryParse(cell, out numberArr[i, j]);
                        }
                        array2Solve[i, j] = cell;
                    }
                }

                if (!string.IsNullOrEmpty(Results[0]))
                {//Визначник системи
                    if (double.TryParse(Results[0], out dbl))
                    {
                        SubstitutionResults[0] = Results[0];
                    }
                    else
                    {
                        systemDeterminant = SubstitutionResults[0] =
                            DetCalc.SolvePathApproach(array2Solve, numberArr);
                    }
                }

                if (!string.IsNullOrEmpty(Results[1]))
                {//Повний коефіцієнт передачі
                    if (double.TryParse(Results[1], out dbl))
                    {
                        SubstitutionResults[1] = Results[1];
                    }
                    else
                    {
                        SubstitutionResults[1] =
                            TransRatioCalculationSubsit(count - 1, 0, array2Solve, numberArr);
                    }
                }

                if (!string.IsNullOrEmpty(Results[2]))
                {
                    if ((!string.IsNullOrEmpty(SignalOut)) &&
                        (!string.IsNullOrEmpty(SignalIn)))
                    {//Коефіцієнт передачі
                        if (double.TryParse(Results[2], out dbl))
                        {
                            SubstitutionResults[2] = Results[2];
                        }
                        else
                        {
                            SubstitutionResults[2] =
                                TransRatioCalculationSubsit(int.Parse(SignalOut) - 1,
                                                            int.Parse(SignalIn) - 1, array2Solve, numberArr);
                        }
                    }
                    else
                    {//одиничний сигнал
                        if (double.TryParse(Results[2], out dbl))
                        {
                            SubstitutionResults[2] = Results[2];
                        }
                        else
                        {
                            if (string.IsNullOrEmpty(systemDeterminant))
                            {
                                systemDeterminant = DetCalc.SolvePathApproach(array2Solve, numberArr);
                            }
                            SubstitutionResults[2] = "(" +
                                                     TransRatioCalculationSubsit(int.Parse(SignalOut) - 1, -1,
                                                                                 array2Solve, numberArr) + ")/(" + systemDeterminant + ")";
                        }
                    }
                }
                return(SubstResFormation());
            }
        }