public void CheckJacobi()
        {
            double[,] table1 = { { 1, 2 }, { 2, 1 } };
            double[,] table2 =
            {
                { 10.0,   -1,    2,  0 },
                {   -1, 11.0, -1.0,  3 },
                {  2.0, -1.0, 10.0, -1 },
                {    0,    3,   -1,  8 }
            };

            double[] bVector1      = { 1, 1 };
            double[] bVector2      = { 6, 25.0, -11.0, 15 };
            MyMatrix doubleMatrix1 = new MyMatrix(2, 2);
            MyMatrix doubleMatrix2 = new MyMatrix(4, 4);

            doubleMatrix1.ComplementMatrix(table1);
            doubleMatrix2.ComplementMatrix(table2);

            double[] xVector1 = doubleMatrix1.Jacobi(bVector1, 1);
            double[] xVector2 = doubleMatrix2.Jacobi(bVector2, 8);

            double[] expect1 = { 1, 1 };
            double[] expect2 = { 1.0006, 1.9987, -0.9990, 0.9989 };


            Assert.Equal(expect1, xVector1);
            Assert.Equal(expect2[0], Math.Round(xVector2[0], 4));
            Assert.Equal(expect2[1], Math.Round(xVector2[1], 4));
            Assert.Equal(expect2[2], Math.Round(xVector2[2], 4));
            Assert.Equal(expect2[3], Math.Round(xVector2[3], 4));
        }
Пример #2
0
        static void Main(string[] args)
        {
            Random rand = new Random();

            MyMatrix firstMatrix  = new MyMatrix(size, size);
            MyMatrix secondMatrix = new MyMatrix(size, size);
            MyMatrix thirdMatrix  = new MyMatrix(size, size);

            double[] firstVector = new double[size];

            /*
             * for (int j = 0; j < size; j++)
             * {
             *  for (int k = 0; k < size; k++)
             *  {
             *      int a = rand.Next(1, 10);
             *      int b = rand.Next(1, 10);
             *      firstMatrix.matrix[j, k] = (double)a / b;
             *      a = rand.Next(1, 10);
             *      b = rand.Next(1, 10);
             *      secondMatrix.matrix[j, k] = (double)a / b;
             *      a = rand.Next(1, 10);
             *      b = rand.Next(1, 10);
             *      thirdMatrix.matrix[j, k] = (double)a / b;
             *      a = rand.Next(1, 10);
             *      b = rand.Next(1, 10);
             *      firstVector[j] = (double)a / b;
             *  }
             *
             * }
             */
            // firstMatrix.PrintMatrix();
            // Console.WriteLine("First Matrix End!");

            // secondMatrix.PrintMatrix();
            // Console.WriteLine("Second Matrix End!");

            //thirdMatrix.PrintMatrix();
            // Console.WriteLine("Third Matrix End!");

            double[,] table =
            {
                { 10.0,   -1,    2,  0 },
                {   -1, 11.0, -1.0,  3 },
                {  2.0, -1.0, 10.0, -1 },
                {    0,    3,   -1,  8 }
            };
            double[] vector = { 6, 25.0, -11.0, 15 };

            MyMatrix test = new MyMatrix(4, 4);

            test.ComplementMatrix(table);
            vector = test.Seidel(vector, 5);

            MyMatrix.PrintVector(vector);

            Console.ReadKey();
        }
        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);
        }
Пример #4
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);
        }
Пример #5
0
        public static double[] ComputeAll()
        {
            Stan[] tableOfStans    = CreateTableOfStans();
            int    numberOfColumns = tableOfStans.Length;

            var stopwatch = new Stopwatch();

            stopwatch.Reset();
            stopwatch.Start();
            FillTableOfStans(tableOfStans);

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

            double[,] matrixPoints = new double[numberOfColumns * Stan.numberOfCubeWalls + numberOfColumns, 3];
            double[,] vectorPoints = new double[numberOfColumns, 3];

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

            MyMatrix matrix = new MyMatrix(numberOfColumns, numberOfColumns);

            matrix.ComplementMatrix(tableForMatrix);

            buildMatrixTime = stopwatch.Elapsed.TotalMilliseconds;

            matrix.WriteMatrixToFile();
            WriteVectorToFile((double[])bVector.Clone());
            MyMatrix.PrintVector(bVector);
            WriteVectorWithoutZero((double[])bVector.Clone());

            stopwatch.Reset();
            stopwatch.Start();
            double[] sVector = matrix.Seidel((double[])bVector.Clone(), 100);
            stopwatch.Stop();
            resultVector[2] = sVector[0];
            seidelTime      = stopwatch.Elapsed.TotalMilliseconds;
            return(resultVector);
        }
        public void CheckSeidel()
        {
            double[,] table =
            {
                { 10.0,   -1,    2,  0 },
                {   -1, 11.0, -1.0,  3 },
                {  2.0, -1.0, 10.0, -1 },
                {    0,    3,   -1,  8 }
            };
            double[] bVector1      = { 6, 25.0, -11.0, 15 };
            MyMatrix doubleMatrix1 = new MyMatrix(4, 4);

            doubleMatrix1.ComplementMatrix(table);

            double[] xVector1 = doubleMatrix1.Seidel(bVector1, 5);

            double[] expect1 = { 1.0001, 2.0000, -1.0000, 1.0000 };


            Assert.Equal(expect1[0], Math.Round(xVector1[0], 4));
            Assert.Equal(expect1[1], Math.Round(xVector1[1], 4));
            Assert.Equal(expect1[2], Math.Round(xVector1[2], 4));
            Assert.Equal(expect1[3], Math.Round(xVector1[3], 4));
        }