public void CheckGaussWithRowChoiceForSquareMatrix()
        {
            double[,] table = { { 4, -2, 4, -2 }, { 3, 1, 4, 2 }, { 2, 4, 2, 1 }, { 2, -2, 4, 2 } };
            double[] bVector = { 8, 7, 10, 2 };

            MyMatrix doubleMatrix = new MyMatrix(4, 4);

            doubleMatrix.ComplementMatrix(table);
            double[] xVector = doubleMatrix.GaussWithRowChoice(bVector, true);
            double[] expect  = { -1, 2, 3, -2 };

            Assert.Equal(expect, xVector);
        }
Esempio n. 2
0
        public static double[] ComputeAll()
        {
            Stan[] tableOfStans    = CreateTableOfStans();
            int    numberOfColumns = tableOfStans.Length;

            FillTableOfStans(tableOfStans);

            double[,] tableForMatrix = new double[numberOfColumns, numberOfColumns];
            double[] bVector      = new double[numberOfColumns];
            double[] resultVector = new double[3];

            FillTableForMatrixAndBVectorWithZeros(tableForMatrix, bVector, numberOfColumns);
            FillTableForMatrixWithStans(tableOfStans, numberOfColumns, tableForMatrix, bVector);

            MyMatrix matrix = new MyMatrix(numberOfColumns, numberOfColumns);

            matrix.ComplementMatrix(tableForMatrix);
            matrix.WriteMatrixToFile();
            WriteVectorToFile((double[])bVector.Clone());

            var stopwatch = new Stopwatch();

            stopwatch.Reset();
            stopwatch.Start();
            double[] gVector = matrix.GaussWithRowChoice((double[])bVector.Clone());
            stopwatch.Stop();
            gaussTime       = stopwatch.Elapsed.TotalMilliseconds;
            resultVector[0] = gVector[0];

            stopwatch.Reset();
            stopwatch.Start();
            double[] jVector = matrix.Jacobi((double[])bVector.Clone(), 100);
            stopwatch.Stop();
            jacobiTime      = stopwatch.Elapsed.TotalMilliseconds;
            resultVector[1] = jVector[0];
            stopwatch.Reset();
            stopwatch.Start();
            double[] sVector = matrix.Seidel((double[])bVector.Clone(), 100);
            stopwatch.Stop();
            resultVector[2] = sVector[0];
            seidelTime      = stopwatch.Elapsed.TotalMilliseconds;
            return(resultVector);
        }