コード例 #1
0
ファイル: Approximation.cs プロジェクト: pzaleszczyk/Studies
        public static MyMatrix CountEquation(double[,] data, int power)
        {
            if (data.GetLength(1) != 2 || data.GetLength(0) < 1)
            {
                throw new Exception("Wrong data table! Count requires 2 columns of data.");
            }
            int dataLength = data.GetLength(0);
            int sCount     = (2 * power) + 1;
            int tCount     = power + 1;
            int size       = power + 1;

            double[,] sTab = new double[dataLength, sCount];
            double[,] tTab = new double[dataLength, tCount];
            double[] sResults = new double[sCount];
            double[] tResults = new double[tCount];

            for (int i = 0; i < sTab.GetLength(0); i++)     //GetLength(0) == dataLen == rowsy
            {
                for (int j = 0; j < sTab.GetLength(1); j++) //GetLength(1) == sCount == kolumny
                {
                    sTab[i, j]   = Math.Pow(data[i, 0], j);
                    sResults[j] += sTab[i, j];
                }
                for (int j = 0; j < tTab.GetLength(1); j++)
                {
                    tTab[i, j]   = data[i, 1] * sTab[i, j];
                    tResults[j] += tTab[i, j];
                }
            }
            MyMatrix matrix = new MyMatrix(size, size);
            MyMatrix vector = new MyMatrix(size, 1);
            int      helper = 0;

            for (int i = 0; i < size; i++)
            {
                vector[i, 0] = tResults[i];
                for (int j = 0; j < size; j++)
                {
                    matrix[i, j] = sResults[j + helper];
                }
                helper++;
            }
            MyMatrix resultVector = MyMatrix.gauss(MyMatrix.matrixJoinVector(matrix, vector), true);

            return(resultVector);
        }
コード例 #2
0
ファイル: Program.cs プロジェクト: pzaleszczyk/Studies
        public static void countInfo(MyMatrix matrix, MyMatrix vector, double generationTime)
        {
            double[]  executionTime = new double[3];
            int       size          = matrix.rowCount;
            Stopwatch stopWatch     = new Stopwatch();
            MyMatrix  result;
            MyMatrix  matrixTMP;
            MyMatrix  vectorTMP;

            Console.WriteLine("-------------------------GAUSS PARTIAL BEZ OPTYMALIZACJI-------------------------");
            matrixTMP = MyMatrix.matrixJoinVector(matrix, vector);
            stopWatch.Start();
            result = MyMatrix.gauss(matrixTMP, false);
            stopWatch.Stop();
            Console.WriteLine("Wynik : " + result[0, 0]);
            Console.WriteLine("Czas : " + stopWatch.ElapsedMilliseconds);
            executionTime[0] = stopWatch.ElapsedMilliseconds;
            Console.WriteLine("-------------------------GAUSS PARTIAL Z OPTYMALIZACJA-------------------------");
            matrixTMP = MyMatrix.matrixJoinVector(matrix, vector);
            stopWatch.Restart();
            result = MyMatrix.gauss(matrixTMP, true);
            stopWatch.Stop();
            Console.WriteLine("Wynik : " + result[0, 0]);
            Console.WriteLine("Czas : " + stopWatch.ElapsedMilliseconds);
            executionTime[1] = stopWatch.ElapsedMilliseconds;
            Console.WriteLine("-------------------------GAUSS ITERACYJNY : SEIDEL-------------------------");
            matrixTMP = new MyMatrix(matrix);
            vectorTMP = new MyMatrix(vector);
            stopWatch.Restart();
            result = MyMatrix.gaussSeidel(matrixTMP, vectorTMP);
            stopWatch.Stop();
            Console.WriteLine("Wynik : " + result[0, 0]);
            Console.WriteLine("Czas : " + stopWatch.ElapsedMilliseconds);
            executionTime[2] = stopWatch.ElapsedMilliseconds;
            FileHelper.saveStatsAprox(infoOutput, size, generationTime, executionTime);
        }