예제 #1
0
        static void EveryKOnSizesFrom3To10()
        {
            SystemOfLinearEquations SoLE;
            TridiagonalMatrix       m;
            Vector f, xAccurate;

            double error;

            for (int n = 3; n <= 10; ++n)
            {
                xAccurate = new Vector(n);
                xAccurate.FillRandomly(1, 9);

                for (int k = 1; k <= n - 2; ++k)
                {
                    m = new TridiagonalMatrix(n);
                    m.FillRandomly(1, 10, k);

                    f = m * xAccurate;

                    SoLE = new SystemOfLinearEquations(m, f);

                    try
                    {
                        error = (SoLE.Solve() - xAccurate).Norm();

                        Console.WriteLine("n = " + n + ", k = " + k + ", погрешность: " + error);
                    }
                    catch (DivideByZeroException)
                    {
                        --k;
                    }
                }
            }
        }
예제 #2
0
        static void TestMode()
        {
            Console.WriteLine("1 - Сгенерировать полностью случайную СЛАУ" + Environment.NewLine +
                              "2 - Решить кастомную задачу");

            switch (Convert.ToInt32(Console.ReadLine()))
            {
            case 1:
                Random rnd = new Random();

                int Size            = rnd.Next(3, 9);
                TridiagonalMatrix m = new TridiagonalMatrix(Size);
                m.FillRandomly(1, 9);

                Vector xAccurate = new Vector(Size);
                xAccurate.FillRandomly(1, 9);

                Vector f = m * xAccurate;

                SystemOfLinearEquations SoLE = new SystemOfLinearEquations(m, f);
                SoLE.TestSolve(xAccurate);
                break;

            case 2:
                // Кастомная задача

                //EveryKOnSizesFrom3To10();
                //GiganticSizeWithBigNumbers();
                MatrixWithLargeNumbersOnDiagonalAndKodiagonalVectors();

                break;
            }
        }
예제 #3
0
        static void MeanErrorMode()
        {
            SystemOfLinearEquations SoLE;
            TridiagonalMatrix       m;
            Vector f, xAccurate;

            double error, sumError, maxError;

            Console.WriteLine("Введите количество итераций для каждой размерности матрицы:");
            int numOfTests = Convert.ToInt32(Console.ReadLine());

            Console.WriteLine();

            StringBuilder sB = new StringBuilder();

            sB.Append(" Размерность\t|\tСредняя погрешность\t|\tМаксимальная погрешность" + Environment.NewLine);

            int numOfSpaces = 13;

            for (int i = 10; i <= 100000; i *= 10)
            {
                sumError = 0;
                maxError = -1;

                for (int j = 1; j <= numOfTests; ++j)
                {
                    m = new TridiagonalMatrix(i);
                    m.FillRandomly(1, 99);

                    xAccurate = new Vector(i);
                    xAccurate.FillRandomly(1, 99);

                    f = m * xAccurate;

                    SoLE = new SystemOfLinearEquations(m, f);

                    try
                    {
                        error     = (SoLE.Solve() - xAccurate).Norm();
                        sumError += error;
                        if (error > maxError)
                        {
                            maxError = error;
                        }
                    }
                    catch (DivideByZeroException)
                    {
                        --j;
                    }
                }

                sB.Append(" " + i);
                sB.Insert(sB.Length, " ", numOfSpaces--);
                sB.Append("|      " + sumError / numOfTests + "\t|        " + maxError + Environment.NewLine);
            }

            Console.WriteLine(sB.ToString());
        }
예제 #4
0
        static void GiganticSizeWithBigNumbers()
        {
            SystemOfLinearEquations SoLE;
            TridiagonalMatrix       m;
            Vector f, xAccurate;

            xAccurate = new Vector(50000000);
            xAccurate.FillRandomly(1, 10000);

            m = new TridiagonalMatrix(50000000);
            m.FillRandomly(1, 10000);

            f = m * xAccurate;

            SoLE = new SystemOfLinearEquations(m, f);

            Console.WriteLine("Погрешность: " + (SoLE.Solve() - xAccurate).Norm());
        }