public void CheckSetDefaultVector()
        {
            double[] vector = IterationMethodsOperations.SetDefaultVector(4);
            double[] expect = { 0, 0, 0, 0 };

            Assert.Equal(expect, vector);
        }
Esempio n. 2
0
        public static void CountXVector(double[] xVector, int numberOfIterations, double[,] matrix, double[] bVector)
        {
            int numberOfRows = matrix.GetLength(0);

            for (int i = 0; i < numberOfIterations; i++)
            {
                for (int j = 0; j < numberOfRows; j++)
                {
                    xVector[j] = IterationMethodsOperations.ValueFromIterationForRow(xVector, matrix, j, bVector);
                }
            }
        }
        public void CheckCountResultOfActionsForGivenRowOfXVector()
        {
            double[,] matrix1 = { { 1, 2 }, { 2, 1 } };
            double[,] matrix2 = { { 4, -1, -0.2, 2 }, { -1, 5, 0, -2 }, { 0.2, 1, 10, -1 }, { 0, -2, -1, 4 } };
            double[] xVector1 = IterationMethodsOperations.SetDefaultVector(2);
            double[] xVector2 = IterationMethodsOperations.SetDefaultVector(4);

            double result1 = IterationMethodsOperations.CountResultOfActionsForGivenRowOfXVector(2, 0, xVector1, matrix1);
            double result2 = IterationMethodsOperations.CountResultOfActionsForGivenRowOfXVector(4, 0, xVector2, matrix2);

            double expect1 = 0;
            double expect2 = 0;


            Assert.Equal(expect1, result1);
            Assert.Equal(expect2, result2);
        }
        public void CheckCountXVectorForJacobi()
        {
            double[,] matrix1 = { { 1, 2 }, { 2, 1 } };
            double[,] matrix2 = { { 4, -1, -0.2, 2 }, { -1, 5, 0, -2 }, { 0.2, 1, 10, -1 }, { 0, -2, -1, 4 } };
            double[] xVector1 = IterationMethodsOperations.SetDefaultVector(2);
            double[] xVector2 = IterationMethodsOperations.SetDefaultVector(4);
            double[] bVector1 = { 1, 1 };
            double[] bVector2 = { 30, 0, -10, 5 };

            JacobiOperations.CountXVector(xVector1, matrix1, bVector1);
            JacobiOperations.CountXVector(xVector2, matrix2, bVector2);

            double[] expect1 = { 1, 1 };
            double[] expect2 = { 6.825, 2, -1.025, 1 };

            //Assert.Equal(expect1, xVector1);
            Assert.Equal(expect2, xVector2);
        }
Esempio n. 5
0
        public static void CountXVector(double[] xVector, int numberOfIterations, double[,] matrix, double[] bVector)
        {
            int numberOfRows = matrix.GetLength(0);

            while (true)
            {
                double[] lastIterationXVector = (double[])xVector.Clone();

                for (int j = 0; j < numberOfRows; j++)
                {
                    xVector[j] = IterationMethodsOperations.ValueFromIterationForRow(xVector, matrix, j, bVector);
                }

                if (IterationMethodsOperations.CheckIsVectorSameAfterNextIteration(lastIterationXVector, xVector))
                {
                    break;
                }
            }
        }
        public void CheckValueFromIterationForRow()
        {
            double[,] matrix1 = { { 4, -1, -0.2, 2 }, { -1, 5, 0, -2 }, { 0.2, 1, 10, -1 }, { 0, -2, -1, 4 } };
            double[] bVector1 = { 30, 0, -10, 5 };
            double[] xVector1 = IterationMethodsOperations.SetDefaultVector(4);

            double result1 = IterationMethodsOperations.ValueFromIterationForRow(xVector1, matrix1, 0, bVector1);
            double result2 = IterationMethodsOperations.ValueFromIterationForRow(xVector1, matrix1, 1, bVector1);
            double result3 = IterationMethodsOperations.ValueFromIterationForRow(xVector1, matrix1, 2, bVector1);
            double result4 = IterationMethodsOperations.ValueFromIterationForRow(xVector1, matrix1, 3, bVector1);

            double expect1 = 7.5;
            double expect2 = 0;
            double expect3 = -1;
            double expect4 = 1.25;

            Assert.Equal(expect1, result1);
            Assert.Equal(expect2, result2);
            Assert.Equal(expect3, result3);
            Assert.Equal(expect4, result4);
        }
        public static void CountXVector(double[] xVector, int numberOfIterations, double[,] matrix, double[] bVector)
        {
            var stopwatch = new Stopwatch();

            stopwatch.Reset();
            stopwatch.Start();
            int numberOfRows = matrix.GetLength(0);

            double[] lastIterationXVector = new double[numberOfRows];
            int      l = 1;

            while (true)
            {
                stopwatch.Reset();
                stopwatch.Start();
                for (int i = 0; i < numberOfRows; i++)
                {
                    countXFirstFor++;
                    lastIterationXVector[i] = xVector[i];
                }

                countXFirstForTime = stopwatch.Elapsed.TotalMilliseconds;
                //Console.WriteLine("While: {0}, firstfor:{1}", l, firstfor);


                stopwatch.Reset();
                stopwatch.Start();
                for (int j = 0; j < numberOfRows; j++)
                {
                    countXSecondFor++;
                    xVector[j] = IterationMethodsOperations.ValueFromIterationForRow(xVector, matrix, j, bVector);
                }
                countXSecondForTime = stopwatch.Elapsed.TotalMilliseconds;
                //Console.WriteLine("While: {0}, secondfor:{1}", l, secondfor);

                if (IterationMethodsOperations.CheckIsVectorSameAfterNextIteration(lastIterationXVector, xVector))
                {
                    break;
                }
                countXwhile++;
            }

            countXTime = stopwatch.Elapsed.TotalMilliseconds;

            Console.WriteLine("CountXVector Time: " + String.Format("{0:N16}", countXTime));
            Console.WriteLine("CountXVector While Count: " + countXwhile);
            Console.WriteLine("CountXVector first for time: " + String.Format("{0:N16}", countXFirstForTime));
            Console.WriteLine("CountXVector first for count: " + countXFirstFor);
            Console.WriteLine("CountXVector second for time: " + String.Format("{0:N16}", countXSecondForTime));
            Console.WriteLine("CountXVector second for count: " + countXSecondFor);
            Console.WriteLine("ValueFrom Time: " + String.Format("{0:N16}", IterationMethodsOperations.valueFromTime));
            Console.WriteLine("ValueFrom1 Time: " + String.Format("{0:N16}", IterationMethodsOperations.valueFrom1Time));
            Console.WriteLine("ValueFrom count: " + IterationMethodsOperations.valueFrom);
            Console.WriteLine("CountResult Time: " + String.Format("{0:N16}", IterationMethodsOperations.countResultTime));
            Console.WriteLine("CountResult count: " + IterationMethodsOperations.countResult);
            Console.WriteLine("CountResult For count: " + IterationMethodsOperations.countResultFor);
            Console.WriteLine("CountResult If count: " + IterationMethodsOperations.countResultIf);
            Console.WriteLine("CheckIsVectorSame Time: " + String.Format("{0:N16}", IterationMethodsOperations.checkIsVectorSameTime));
            Console.WriteLine("CheckIsVectorSame Count: " + IterationMethodsOperations.checkIsVectorSame);
            Console.WriteLine("CheckIsVectorSame For Count: " + IterationMethodsOperations.checkIsVectorSameFor);
            Console.WriteLine("CheckIsDoubleZero count: " + IterationMethodsOperations.checkZero);
        }
 public double[] Seidel(double[] bVector, int numberOfIterations)
 {
     double[] xVector = IterationMethodsOperations.SetDefaultVector(numberOfColumns);
     SeidelOperations.CountXVector(xVector, numberOfIterations, matrix, bVector);
     return(xVector);
 }
 public double[] Jacobi(double[] bVector, int numberOfIterations)
 {
     double[] xVector = IterationMethodsOperations.SetDefaultVector(numberOfColumns);
     JacobiOperations.CountXVector(xVector, matrix, bVector);
     return(xVector);
 }