Exemplo n.º 1
0
        static int ChoosePivotIndex(PivotMethod pivotMethod, List <int> inputList, int left, int right)
        {
            switch (pivotMethod)
            {
            case PivotMethod.First:
            {
                return(left);
            }

            case PivotMethod.Last:
            {
                return(right - 1);
            }

            case PivotMethod.Median:
            {
                float x           = (left + right - 1) / 2;
                var   middleIndex = Convert.ToInt32(Math.Floor(x));

                List <int> y = new List <int>
                {
                    inputList[left],
                    inputList[right - 1],
                    inputList[middleIndex],
                };

                y.Sort();
                return(inputList.IndexOf(y[1]));
            }
            }

            return(0);
        }
Exemplo n.º 2
0
        static void test3()
        {
            PivotMethod.createAllSubMatrix();

            testPivotDeterminant("-76 2 10 8 2");
            testPivotDeterminant("0 5 9 10 18");
            testPivotDeterminant("-358 6 3 8 2 4 10 8 9 3");
            testPivotDeterminant("0 6 3 8 12 6 16 8 9 3");

            //testDefinitionDeterminant("358 6 3 8 2 4 10 8 9 3"); // Will Fail
            //testDefinitionDeterminant("10 6 3 8 12 6 16 8 9 3"); // Will Fail

            testPivotDeterminant("-648 10 2 6 1 5 10 3 6 7 2 9 7 4 6 8 9");
            testPivotDeterminant("1718 6 4 10 1 10 5 1 9 3 2 9 10 6 2 6 2");

            testPivotDeterminant("52 4 6 10 7 1 4 9 8 10 2 10 7 10 7 6 10 3 6 1 10 10 7 1 8 3");
        }
Exemplo n.º 3
0
        static bool testPivotDeterminant(string s, bool printAll = true)
        {
            var l0   = s.Split(' ').Select(int.Parse).ToList();
            var det0 = l0[0];
            var l1   = l0.Skip(1).ToList();
            var mat0 = list2matrix(l1);
            var mat1 = list2matrix(l1);

            var det1 = Math.Round(PivotMethod.ComputeDeterminant(mat1), 6);

            if (printAll || det0 != det1)
            {
                foreach (var r in mat0)
                {
                    Console.WriteLine(string.Join(" ", r));
                }

                var info = det0 != det1 ? $"Bad;  {det0,10} != {det1}" : $"Good; {det0,10} == {det1}";
                Console.WriteLine($"=> {info} pivotDeterminant");
                Console.WriteLine();
            }

            return(det0 == det1);
        }