当前位置: 首页>>代码示例>>C#>>正文


C# Matrix.Initialize方法代码示例

本文整理汇总了C#中Matrix.Initialize方法的典型用法代码示例。如果您正苦于以下问题:C# Matrix.Initialize方法的具体用法?C# Matrix.Initialize怎么用?C# Matrix.Initialize使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Matrix的用法示例。


在下文中一共展示了Matrix.Initialize方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Main

        static void Main(string[] args)
        {
            Matrix matrix = new Matrix();

            matrix.Initialize();
            bool[,] passedCells = new bool[Matrix.SIZE, Matrix.SIZE];
            List<Matrix> result = new List<Matrix>();
            for (int row = 0; row < Matrix.SIZE; row++)
            {
                for (int col = 0; col < Matrix.SIZE; col++)
                {
                    if (!passedCells[row, col] && matrix[row, col] != Matrix.OBSTACLE_SYMBOL)
                    {
                        Console.WriteLine(1);
                        Program.currCellCount = 0;
                        Program.FindAllAreaOfEmptyCells(matrix, row, col, passedCells);
                        Matrix currMatrix = new Matrix();
                        Matrix.Copy(matrix,currMatrix);
                        result.Add(currMatrix);
                        matrix.Reset();
                    }
                }
            }
            Console.WriteLine();
            Console.WriteLine("Possible areas:");

            foreach (Matrix currMatrix in result)
            {
                Console.WriteLine();
                currMatrix.PrintOnConsole();
            }
        }
开发者ID:vaster,项目名称:Telerik.vasko,代码行数:32,代码来源:Program.cs

示例2: MultiplyByMatrix_MATLAB

        /*
        需要添加matlab的运行库作为引用
        /// <summary>
        /// 使用matlab库运算矩阵乘法
        /// </summary>
        /// <param name="m"></param>
        /// <returns></returns>
        public Matrix MultiplyByMatrix_MATLAB(Matrix m)
        {
            MLAppClass matlab = new MLAppClass();
            double[,] pia = new double[m.nRows, m.nColumns];
            double[,] pib = new double[this.nRows, this.nColumns];
            matlab.PutFullMatrix("A", "base", m.Cell, pia);
            matlab.PutFullMatrix("B", "base", this.Cell, pib);
            matlab.Execute("C = A*B;");
            Matrix result =new Matrix(m.nRows, this.nColumns);
            System.Array pir = new double[m.nRows,this.nColumns];
            System.Array prr = new double[m.nRows, this.nColumns];
            matlab.GetFullMatrix("C", "base",ref prr,ref pir);
            for(int i =0;i<prr.GetLength(0);i++)
            {
                for (int j = 0; j < prr.GetLength(1); j++) result.Cell[i, j] = (double)(prr.GetValue(i, j));
            }
            return result;
        }
        */
        /// <summary>
        /// 求实对称矩阵特征值与特征向量的雅可比法(来自http://download.csdn.net/detail/jian_5030624/1082723)
        /// </summary>
        /// <param name="dblEigenValue">一维数组,长度为矩阵的阶数,返回时存放特征值</param>
        /// <param name="mtxEigenVector">返回时存放特征向量矩阵,其中第i列为与数组dblEigenValue中第i个特征值对应的特征向量</param>
        /// <param name="nMaxIt">迭代次数</param>
        /// <param name="eps">计算精度</param>
        /// <returns>bool型,求解是否成功</returns>
        public bool ComputeEvJacobi(double[] dblEigenValue, Matrix mtxEigenVector, int nMaxIt, double eps)
        {
            int i, j, p = 0, q = 0, l;
            //int u, w, t, s;
            double fm, cn, sn, omega, x, y, d;

            //SyncElements();
            mtxEigenVector.Initialize(this.numColumns, this.numColumns);
            l = 1;
            for (i = 0; i <= numColumns - 1; i++)
            {

                mtxEigenVector.Cell[i, i] = 1.0;
                for (j = 0; j <= numColumns - 1; j++)
                    if (i != j)
                        mtxEigenVector.Cell[i, j] = 0.0;

            }

            while (true)
            {
                fm = 0.0;
                for (i = 1; i <= numColumns - 1; i++)
                {
                    for (j = 0; j <= i - 1; j++)
                    {

                        d = Math.Abs(cell[i, j]);
                        if ((i != j) && (d > fm))
                        {
                            fm = d;
                            p = i;
                            q = j;
                        }
                    }
                }

                if (fm < eps || l>nMaxIt)
                {
                    //this.SyncCell();
                    for (i = 0; i < numColumns; ++i)
                        dblEigenValue[i] = cell[i, i];
                    //mtxEigenVector.SyncCell();

                    return true;
                }

                /*if (l > nMaxIt)
                    return false;*/

                l = l + 1;
                //u = p * numColumns + q;
               // w = p * numColumns + p;
                //t = q * numColumns + p;
                //s = q * numColumns + q;
                x = -cell[p,q];
                y = (cell[q,q] - cell[p,p]) / 2.0;
                omega = x / Math.Sqrt(x * x + y * y);

                if (y < 0.0)
                    omega = -omega;

                sn = 1.0 + Math.Sqrt(1.0 - omega * omega);
                sn = omega / Math.Sqrt(2.0 * sn);
                cn = Math.Sqrt(1.0 - sn * sn);
                fm = cell[p, p];
//.........这里部分代码省略.........
开发者ID:againcy,项目名称:Examples,代码行数:101,代码来源:Matrix.cs

示例3: Matrix

        public static Matrix operator *(Matrix lMat,Matrix rMat)
        {
            if(lMat.Columns == rMat.Rows)
            {
                Matrix temp = new Matrix(lMat.Rows,rMat.Columns);
                temp.Initialize();
                for(int rw=0;rw<temp.Rows;rw++)
                    for(int cl=0;cl<temp.Columns;cl++)
                        for(int cl2=0;cl2<lMat.Columns;cl2++)
                            temp.m_MatArr[rw,cl] =temp.m_MatArr[rw,cl] + lMat.m_MatArr[rw,cl2] * rMat.m_MatArr[cl2,cl];

                return temp;
            }
            else
            {
                throw new Exception("Number of Columns of Left Matrix must be equal to Rows of Right Matrix.");
            }
        }
开发者ID:samwiise,项目名称:DistributedMatlab,代码行数:18,代码来源:ASMMath.cs


注:本文中的Matrix.Initialize方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。