예제 #1
0
        public void RunFloat(GaussType gausstype)
        {
            MyMatrix <float> matrix = new MyMatrix <float>(dimensions);
            Random           r      = new Random(1234);
            float            num;

            for (int y = 0; y < dimensions; y++)
            {
                matrix.SetVectorB(y, 0);
                num = (float)(short)r.Next() / 32768;
                matrix.SetVectorX(y, num);
                for (int x = 0; x < dimensions; x++)
                {
                    num = (float)(short)r.Next() / 32768;
                    matrix.SetMatrixA(x, y, num);
                }
            }
            matrix.Multiplication();

            Stopwatch sw = new Stopwatch();

            switch (gausstype)
            {
            case GaussType.Basic:
                //Console.WriteLine("  bez wyboru elementu podstawowego");
                sw.Start();
                matrix.CalculateG();
                sw.Stop();
                time[0] = sw.Elapsed.TotalMilliseconds;
                diff[0] = matrix.CalculateDiff();
                break;

            case GaussType.Part:
                //Console.WriteLine("  z czesciowym wyborem elementu podstawowego");
                sw.Start();
                matrix.CalculateGP();
                sw.Stop();
                time[1] = sw.Elapsed.TotalMilliseconds;
                diff[1] = matrix.CalculateDiff();
                break;

            case GaussType.Full:
                //Console.WriteLine("  z pelnym wyborem elementu podstawowego");
                sw.Start();
                matrix.CalculateGF();
                sw.Stop();
                time[2] = sw.Elapsed.TotalMilliseconds;
                diff[2] = matrix.CalculateDiff();
                break;
            }

            sw.Stop();
            //Console.WriteLine("    Czas: {0}", sw.Elapsed.TotalMilliseconds);
            //Console.WriteLine("    błąd: " + matrix.CalculateDiff());
        }
예제 #2
0
        public void RunFloat(GaussType gausstype)
        {
            MyMatrix <float> matrix = new MyMatrix <float>(dimensions);
            Random           rnd    = new Random();
            int range = 65536; //2**16

            for (int y = 0; y < dimensions; y++)
            {
                int   rr = rnd.Next(-1 * range, range - 1);
                float f1 = (float)rr / (float)range;
                matrix.SetVectorX(y, f1);
                matrix.SetVectorB(y, 0);
                for (int x = 0; x < dimensions; x++)
                {
                    rr = rnd.Next(-1 * range, range - 1);
                    f1 = (float)rr / (float)range;
                    matrix.SetMatrixA(x, y, f1);
                }
            }
            matrix.ComputeVectorB();

            Stopwatch sw = new Stopwatch();

            switch (gausstype)
            {
            case GaussType.Basic:
                //Console.WriteLine(" G");
                sw.Start();
                matrix.ComputeG();
                sw.Stop();
                time[0] = sw.Elapsed.TotalMilliseconds;
                diff[0] = matrix.GetDiff();
                break;

            case GaussType.Part:
                //Console.WriteLine(" PG");
                sw.Start();
                matrix.ComputePG();
                sw.Stop();
                time[1] = sw.Elapsed.TotalMilliseconds;
                diff[1] = matrix.GetDiff();
                break;

            case GaussType.Full:
                //Console.WriteLine(" FG");
                sw.Start();
                matrix.ComputeFG();
                sw.Stop();
                time[2] = sw.Elapsed.TotalMilliseconds;
                diff[2] = matrix.GetDiff();
                break;
            }
            sw.Stop();
        }
예제 #3
0
        public void RunFraction(GaussType gausstype)
        {
            MyMatrix <Fraction> matrix = new MyMatrix <Fraction>(dimensions);
            Random rnd   = new Random();
            int    range = 65536; //2**16

            for (int y = 0; y < dimensions; y++)
            {
                int      rr  = rnd.Next(-1 * range, range - 1);
                Fraction fra = new Fraction(rr, range);
                matrix.SetVectorX(y, fra);
                matrix.SetVectorB(y, 0);
                for (int x = 0; x < dimensions; x++)
                {
                    rr  = rnd.Next(-1 * range, range - 1);
                    fra = new Fraction(rr, range);
                    matrix.SetMatrixA(x, y, fra);
                }
            }
            matrix.ComputeVectorB();

            Stopwatch sw = new Stopwatch();

            switch (gausstype)
            {
            case GaussType.Basic:
                //Console.WriteLine("  G");
                sw.Start();
                matrix.ComputeG();
                sw.Stop();
                time[6] = sw.Elapsed.TotalMilliseconds;
                diff[6] = matrix.GetDiff().ToDouble();
                break;

            case GaussType.Part:
                //Console.WriteLine("  PG");
                sw.Start();
                matrix.ComputePG();
                sw.Stop();
                time[7] = sw.Elapsed.TotalMilliseconds;
                diff[7] = matrix.GetDiff().ToDouble();
                break;

            case GaussType.Full:
                //Console.WriteLine("  z FG");
                sw.Start();
                matrix.ComputeFG();
                sw.Stop();
                time[8] = sw.Elapsed.TotalMilliseconds;
                diff[8] = matrix.GetDiff().ToDouble();
                break;
            }
        }
예제 #4
0
        public void RunFloat(GaussType gausstype, int[,] matrix, int[] vector)
        {
            var floatMatrix = new MyMatrix <float>(_dimensions);

            for (int y = 0; y < _dimensions; y++)
            {
                floatMatrix.SetVectorB(y, 0);
                floatMatrix.SetVectorX(y, ((float)vector[y] / _maxValue));
                for (int x = 0; x < _dimensions; x++)
                {
                    floatMatrix.SetMatrixA(x, y, ((float)matrix[y, x] / _maxValue));
                }
            }
            floatMatrix.Multiplication();

            var sw = new Stopwatch();

            switch (gausstype)
            {
            case GaussType.Basic:
                sw.Start();
                floatMatrix.CalculateG();
                sw.Stop();
                _time[0] = sw.Elapsed.TotalMilliseconds;
                _diff[0] = floatMatrix.CalculateDiff();
                break;

            case GaussType.Part:
                sw.Start();
                floatMatrix.CalculateGP();
                sw.Stop();
                _time[1] = sw.Elapsed.TotalMilliseconds;
                _diff[1] = floatMatrix.CalculateDiff();
                break;

            case GaussType.Full:
                sw.Start();
                floatMatrix.CalculateGF();
                sw.Stop();
                _time[2] = sw.Elapsed.TotalMilliseconds;
                _diff[2] = floatMatrix.CalculateDiff();
                break;
            }

            sw.Stop();
        }
예제 #5
0
        public void RunFraction(GaussType gausstype, int[,] matrix, int[] vector)
        {
            var fractionMatrix = new MyMatrix <Fraction>(_dimensions);

            for (int y = 0; y < _dimensions; y++)
            {
                fractionMatrix.SetVectorB(y, 0);
                fractionMatrix.SetVectorX(y, new Fraction(vector[y], _maxValue));
                for (int x = 0; x < _dimensions; x++)
                {
                    fractionMatrix.SetMatrixA(x, y, new Fraction(matrix[y, x], _maxValue));
                }
            }
            fractionMatrix.Multiplication();

            var sw = new Stopwatch();

            switch (gausstype)
            {
            case GaussType.Basic:
                sw.Start();
                fractionMatrix.CalculateG();
                sw.Stop();
                _time[6] = sw.Elapsed.TotalMilliseconds;
                _diff[6] = fractionMatrix.CalculateDiff();
                break;

            case GaussType.Part:
                sw.Start();
                fractionMatrix.CalculateGP();
                sw.Stop();
                _time[7] = sw.Elapsed.TotalMilliseconds;
                _diff[7] = fractionMatrix.CalculateDiff();
                break;

            case GaussType.Full:
                sw.Start();
                fractionMatrix.CalculateGF();
                sw.Stop();
                _time[8] = sw.Elapsed.TotalMilliseconds;
                _diff[8] = fractionMatrix.CalculateDiff();
                break;
            }
        }
예제 #6
0
        public void RunDouble(GaussType gausstype, int[,] matrix, int[] vector)
        {
            var doubleMatrix = new MyMatrix <double>(_dimensions);

            for (int y = 0; y < _dimensions; y++)
            {
                doubleMatrix.SetVectorB(y, 0);
                doubleMatrix.SetVectorX(y, ((double)vector[y] / _maxValue));
                for (int x = 0; x < _dimensions; x++)
                {
                    doubleMatrix.SetMatrixA(x, y, ((double)matrix[y, x] / _maxValue));
                }
            }
            doubleMatrix.Multiplication();

            var sw = new Stopwatch();

            switch (gausstype)
            {
            case GaussType.Basic:
                sw.Start();
                doubleMatrix.CalculateG();
                sw.Stop();
                _time[3] = sw.Elapsed.TotalMilliseconds;
                _diff[3] = doubleMatrix.CalculateDiff();
                break;

            case GaussType.Part:
                sw.Start();
                doubleMatrix.CalculateGP();
                sw.Stop();
                _time[4] = sw.Elapsed.TotalMilliseconds;
                _diff[4] = doubleMatrix.CalculateDiff();
                break;

            case GaussType.Full:
                sw.Start();
                doubleMatrix.CalculateGF();
                sw.Stop();
                _time[5] = sw.Elapsed.TotalMilliseconds;
                _diff[5] = doubleMatrix.CalculateDiff();
                break;
            }
        }