Beispiel #1
0
        public static void DoubleArray(int SIZE)
        {
            double[] numbers     = new double[Configuration.BIGSIZE];
            var      fileNumbers = File.ReadLines("matrix.txt").Select(double.Parse);
            int      index       = 0;

            foreach (var number in fileNumbers)
            {
                numbers[index] = number;
                index++;
            }
            MyMatrix <double> A = new MyMatrix <double>();
            MyMatrix <double> B = new MyMatrix <double>();
            MyMatrix <double> X = new MyMatrix <double>();
            int k = 0;

            for (int i = 0; i < SIZE; i++)
            {
                for (int j = 0; j < SIZE; j++)
                {
                    {
                        double value = numbers[k];
                        A[i, j] = value;
                        B[i, j] = value;
                        if (k % SIZE == 0)
                        {
                            A[i, SIZE] = value;
                            X[i]       = value;
                        }
                    }
                    k++;
                }
            }
            var watch = System.Diagnostics.Stopwatch.StartNew();

            X = MyMatrix <double> .Gauss(SIZE, A);

            watch.Stop();
            double elapsedMs = watch.ElapsedMilliseconds;

            Console.WriteLine((elapsedMs / 1000));
        }
        public static void DoubleArray(int SIZE)
        {
            double[] numbers     = new double[Configuration.BIGSIZE];
            var      fileNumbers = File.ReadLines("matrix.txt").Select(double.Parse);
            int      index       = 0;

            foreach (var number in fileNumbers)
            {
                numbers[index] = number;
                index++;
            }
            MyMatrix <double> A = new MyMatrix <double>();
            MyMatrix <double> B = new MyMatrix <double>();
            MyMatrix <double> X = new MyMatrix <double>();
            // MyMatrix<double> dupa = new MyMatrix<double>();
            //MyMatrix<double> [,]array = new MyMatrix<double>[4,4];
            // MyMatrix<double>[] test = new MyMatrix<double>[4];
            int k = 0;

            for (int i = 0; i < SIZE; i++)
            {
                for (int j = 0; j < SIZE; j++)
                {
                    {
                        double value = numbers[k];
                        A[i, j] = value;
                        B[i, j] = value;
                        if (k % SIZE == 0)
                        {
                            A[i, SIZE] = value;
                            X[i]       = value;
                        }
                    }
                    k++;
                }
            }
            X = MyMatrix <double> .Gauss(SIZE, A);

            //X = A / X;
            for (int i = 0; i < 10; i++)
            {
                Console.WriteLine(X[i]);
            }
            MyMatrix <double> D = new MyMatrix <double>();
            MyMatrix <double> C = new MyMatrix <double>();
            //double z = A[0, 0] + B[0, 0];
            //Console.WriteLine(z);

            var    watch  = System.Diagnostics.Stopwatch.StartNew();
            double avrage = 0;

            X = MyMatrix <double> .Gauss(SIZE, A);

            //    C = B * A;     D = C * C;    //  (A*B)*C
            // D = A / B;     // C * wektor X (pierwsza kolumna macierzy B)
            //  C = A + B; D = C + C; D = D / B;

            watch.Stop();
            double elapsedMs = watch.ElapsedMilliseconds;

            Console.WriteLine((elapsedMs / 1000));


            MyMatrix <double> result = new MyMatrix <double>();

            ////////////////////////// srednia wierszy
            for (int i = 0; i < Configuration.SIZE; i++)
            {
                for (int j = 0; j < 1; j++)
                {
                    for (int s = 0; s < Configuration.SIZE; s++)
                    {
                        result[i, j] += D[i, s];
                    }
                }
            }
            /////////////////srednia calej macierzy
            for (int i = 0; i < Configuration.SIZE; i++)
            {
                avrage += result[i, 0];
            }
            avrage = avrage / 10;
            //     Console.WriteLine(avrage);
            for (int i = 0; i < Configuration.SIZE; i++)
            {
                for (int j = 0; j < Configuration.SIZE; j++)
                {
                    //Console.Write(string.Format("{0} ", A[i, j]));
                }
                //  Console.Write(Environment.NewLine + Environment.NewLine);
            }
        }