Esempio n. 1
0
        public static bool KnowedMatrixTestSize3(Cholesky method)
        {
            var a = new Matrix(3);

            a[0, 0] = 25;
            a[0, 1] = 15;
            a[0, 2] = -5;
            a[1, 0] = 15;
            a[1, 1] = 18;
            a[1, 2] = 0;
            a[2, 0] = -5;
            a[2, 1] = 0;
            a[2, 2] = 11;
            var x = new Vector(3);

            x[0] = 1;
            x[1] = 1;
            x[2] = 1;
            var b    = a * x;
            var Xnew = method.Run(a, b);

            return(VerifyResult(x, Xnew));
        }
Esempio n. 2
0
        static void Main(string[] args)
        {
            var sw = new Stopwatch();
            var a  = new Matrix(3);

            a[0, 0] = 25;
            a[0, 1] = 15;
            a[0, 2] = -5;
            a[1, 0] = 15;
            a[1, 1] = 18;
            a[1, 2] = 0;
            a[2, 0] = -5;
            a[2, 1] = 0;
            a[2, 2] = 11;
            var x = new Vector(3);

            x[0] = 1;
            x[1] = 1;
            x[2] = 1;
            var     b      = a * x;
            IMethod method = null;

            Console.WriteLine("*** Performance Test ***");
            Console.WriteLine("*** Successive Overrelaxation ***");
            method = new successive_overrelaxation();
            method.Run(a, b);
            var listRes = new List <TimeSpan>();

            for (int i = 0; i < 1000; i++)
            {
                sw.Start();
                var res = method.Run(a, b);
                sw.Stop();
                listRes.Add(sw.Elapsed);
                Console.WriteLine($"{sw.Elapsed.TotalMilliseconds} ms");
                sw.Reset();
            }
            Console.WriteLine($"Average - {listRes.Average(y => y.TotalMilliseconds)} ms");
            Console.WriteLine("*** LU ***");
            method  = new LUmet();
            listRes = new List <TimeSpan>();
            for (int i = 0; i < 1000; i++)
            {
                sw.Start();
                var res = method.Run(a, b);
                sw.Stop();
                listRes.Add(sw.Elapsed);
                Console.WriteLine($"{sw.Elapsed.TotalMilliseconds} ms");
                sw.Reset();
            }
            Console.WriteLine($"Average - {listRes.Average(y => y.TotalMilliseconds)} ms");
            Console.WriteLine("*** Gauss - Seidel ***");
            method  = new GaussSeidel();
            listRes = new List <TimeSpan>();
            for (int i = 0; i < 1000; i++)
            {
                sw.Start();
                var res = method.Run(a, b);
                sw.Stop();
                listRes.Add(sw.Elapsed);
                Console.WriteLine($"{sw.Elapsed.TotalMilliseconds} ms");
                sw.Reset();
            }
            Console.WriteLine($"Average - {listRes.Average(y => y.TotalMilliseconds)} ms");
            Console.WriteLine("*** Cholesky ***");
            method  = new Cholesky();
            listRes = new List <TimeSpan>();
            for (int i = 0; i < 1000; i++)
            {
                sw.Start();
                var res = method.Run(a, b);
                sw.Stop();
                listRes.Add(sw.Elapsed);
                Console.WriteLine($"{sw.Elapsed.TotalMilliseconds} ms");
                sw.Reset();
            }
            Console.WriteLine($"Average - {listRes.Average(y => y.TotalMilliseconds)} ms");
            Console.ReadLine();
        }