예제 #1
0
        //матрица на вектор
        private void button1_Click_1(object sender, EventArgs e)
        {
            int N = 4;
            int M = 10;

            double[] a = new double[M * N];
            double[] b = new double[N];
            double[] c;
            for (int i = 0; i < M; i++)
            {
                for (int j = 0; j < N; j++)
                {
                    a[i * N + j] = i + j;
                }
            }

            for (int j = 0; j < N; j++)
            {
                b[j] = j;
            }

            MathFuncsMatrix myfunc = new MathFuncsMatrix();

            c = myfunc.MultVector(a, b, M, N);
        }
예제 #2
0
        public void MatrixVector()
        {
            MathFuncsMatrix    mymatr1 = new MathFuncsMatrix();
            MathFuncsMatrixSeq mymatr2 = new MathFuncsMatrixSeq();
            int N = 1000;
            int M = 500;

            double[] a = new double[M * N];
            double[] b = new double[N];
            for (int i = 0; i < M; i++)
            {
                for (int j = 0; j < N; j++)
                {
                    a[i * N + j] = i + j;
                }
            }

            for (int j = 0; j < N; j++)
            {
                b[j] = j;
            }

            Stopwatch sw1 = new Stopwatch();

            sw1.Start();
            mymatr1.MultVector(a, b, M, N);
            sw1.Stop();
            double secPar = sw1.ElapsedMilliseconds / 1000.0;


            Stopwatch sw2 = new Stopwatch();

            sw2.Start();
            mymatr2.MultVector(a, b, M, N);
            sw2.Stop();
            double secSeq = sw2.ElapsedMilliseconds / 1000.0;

            Assert.IsTrue(secPar < secSeq, "последовательный вариант быстрее!");
        }
예제 #3
0
        public void MatrixMultVector()
        {
            int N = 4;
            int M = 10;

            double[] a = new double[M * N];
            double[] b = new double[N];
            double[] c;
            for (int i = 0; i < M; i++)
            {
                for (int j = 0; j < N; j++)
                {
                    a[i * N + j] = i + j;
                }
            }

            for (int j = 0; j < N; j++)
            {
                b[j] = j;
            }

            c = mymatr.MultVector(a, b, M, N);
            Assert.AreEqual(c[5], 44);
        }