コード例 #1
0
ファイル: Form1.cs プロジェクト: BakaldinAndrej/MatrixMathnet
        private void _btnCalc_Click(object sender, EventArgs e)
        {
            IMatrix   matrix = new MathnetMatrixSolver();
            Stopwatch stopwatch = new Stopwatch();
            string    formulaA = _tbAformula.Text, formulaB = _tbBformula.Text;
            int       columnA = Convert.ToInt32(_tbAcolumn.Text), rowA = Convert.ToInt32(_tbArow.Text);
            int       columnB = Convert.ToInt32(_tbBcolumn.Text), rowB = Convert.ToInt32(_tbBrow.Text);
            bool      sparse = _chbSparseA.Checked && _chbSparseB.Checked;
            int       opp    = _cmbbOpperation.SelectedIndex;

            Cursor.Current = Cursors.WaitCursor;
            stopwatch.Start();
            double[,] m = matrix.ParsedSolve(formulaA, formulaB, columnA, rowA, columnB, rowB, sparse, opp);
            stopwatch.Stop();
            _rtbDialog.Text = "Время вычисления: " + stopwatch.ElapsedMilliseconds.ToString() + "милисекунд\n";
            for (int i = 0; i < 5 && i < m.GetLength(0); i++)
            {
                for (int j = 0; j < 5 && j < m.GetLength(1); j++)
                {
                    _rtbDialog.Text += m[i, j] + "      ";
                }
                _rtbDialog.Text += "\n";
            }
            Cursor.Current = Cursors.Default;
        }
コード例 #2
0
        public double[,] ParsedSolve(string formulaA, string formulaB, int columnA, int rowA, int columnB, int rowB, bool sparse, int opperation)
        {
            SymbolicExpression parsedA = SymbolicExpression.Parse(formulaA);
            SymbolicExpression parsedB = SymbolicExpression.Parse(formulaB);

            if (parsedA != null && parsedB != null)
            {
                Stopwatch       stopwatch = new Stopwatch();
                Matrix <double> mA, mB;
                Func <double, double, double> funcA = parsedA.Compile("x", "y");
                Func <double, double, double> funcB = parsedB.Compile("x", "y");
                IMatrix matrix = new MathnetMatrixSolver();

                switch (opperation)
                {
                case 0:
                {
                    if (!sparse)
                    {
                        mA = Matrix <double> .Build.Dense(columnA, rowA, (i, j) => funcA(i, j));

                        mB = Matrix <double> .Build.Dense(columnB, rowB, (i, j) => funcB(i, j));

                        return((mA * mB).ToArray());
                    }
                    mA = Matrix <double> .Build.Sparse(columnA, rowA, (i, j) => funcA(i, j));

                    mB = Matrix <double> .Build.Sparse(columnB, rowB, (i, j) => funcB(i, j));

                    return((mA * mB).ToArray());
                }

                case 1:
                {
                    if (!sparse)
                    {
                        mA = Matrix <double> .Build.Dense(columnA, rowA, (i, j) => funcA(i, j)).Transpose();

                        return(mA.ToArray());
                    }
                    mA = Matrix <double> .Build.Sparse(columnA, rowA, (i, j) => funcA(i, j)).Transpose();

                    return(mA.ToArray());
                }
                }
            }
            double[,] err = { { 0.0 } };
            return(err);
        }
コード例 #3
0
        public void TestLargeMultiply()
        {
            IMatrix matrix = new MathnetMatrixSolver();
            string  formulaA = "1", formulaB = "x+y";
            int     columnA = 100, rowA = 100;
            int     columnB = 100, rowB = 100;
            bool    sparse       = false;
            int     opp          = 0;
            bool    testComplete = true;

            double[,] m = matrix.ParsedSolve(formulaA, formulaB, columnA, rowA, columnB, rowB, sparse, opp);

            for (int i = 0; i < columnA; i++)
            {
                for (int j = 0; j < rowB; j++)
                {
                    if (m[i, j] != 4950 + j * 100)
                    {
                        testComplete = false;
                    }
                }
            }
            Assert.True(testComplete);
        }
コード例 #4
0
        public void TestTransponse()
        {
            IMatrix matrix = new MathnetMatrixSolver();
            string  formulaA = "x*2", formulaB = "y*3";
            int     columnA = 100, rowA = 100;
            int     columnB = 100, rowB = 100;
            bool    sparse       = false;
            int     opp          = 1;
            bool    testComplete = true;

            double[,] m = matrix.ParsedSolve(formulaA, formulaB, columnA, rowA, columnB, rowB, sparse, opp);

            for (int i = 0; i < columnA; i++)
            {
                for (int j = 0; j < rowA; j++)
                {
                    if (m[i, j] != j * 2)
                    {
                        testComplete = false;
                    }
                }
            }
            Assert.True(testComplete);
        }