예제 #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());
        }
        public void FillMatrix()
        {
            float[] test = { 4, -2, 4, -2, -1, 3, 1, 4, 2, 2, 2, 4, 2, 1, 3, 2, -2, 4, 2, -2 };
            int     t    = 0;

            for (int y = 0; y < 4; y++)
            {
                for (int x = 0; x < 4; x++)
                {
                    matrixfloat.SetMatrixA(x, y, test[t]);
                    matrixdouble.SetMatrixA(x, y, test[t]);
                    matrixfraction.SetMatrixA(x, y, test[t]);
                    t++;
                }
                matrixfloat.SetVectorX(y, test[t]);
                matrixdouble.SetVectorX(y, test[t]);
                matrixfraction.SetVectorX(y, test[t]);

                matrixfloat.SetVectorB(y, 0);
                matrixdouble.SetVectorB(y, 0);
                matrixfraction.SetVectorB(y, 0);
                t++;
            }
        }