Пример #1
0
        //重载*号晕算法,第一个矩阵的列必须与第二个矩阵的行相等才可以计算
        public static martix operator *(martix m1, martix m2)
        {
            if (m1.Col != m2.Row)
            {
                Console.WriteLine("Wrong");
            }
            martix result = new martix(m1.Row, m2.Col);

            result.ReturnZeroMartix();

            for (int i = 0; i < result.Row; i++)
            {
                for (int j = 0; j < result.Col; j++)
                {
                    int sum = 0;
                    for (int _j = 0; _j < m1.Col; _j++)
                    {
                        sum += m1.A[i, _j] * m2.A[_j, j];
                    }

                    result.A[i, j] = sum;
                }
            }
            return(result);
        }
Пример #2
0
        /// <summary>
        /// 矩阵的幂运算
        /// </summary>
        /// <param name="m1">第一个参数是一个矩阵</param>
        /// <param name="level">第二个参数是数量级</param>
        /// <returns></returns>
        public static martix Pow(martix m1, int level)
        {
            martix result = new martix(m1.Row, m1.Col);

            result.ReturnZeroMartix();
            result = result + 1;
            for (int i = 0; i < level; i++)
            {
                result *= m1;
            }
            return(result);
        }
Пример #3
0
        public static martix operator *(martix m1, int m2)
        {
            martix result = m1;

            for (int i = 0; i < result.Row; i++)
            {
                for (int j = 0; j < result.Col; j++)
                {
                    result.A[i, j] -= m2;
                }
            }
            return(result);
        }
Пример #4
0
        /// <summary>
        /// 返回当前对象的一个转置矩阵
        /// </summary>
        /// <returns></returns>
        public martix ReturnTransposeMartix()
        {
            martix result = new martix(this.Col, this.Row);

            result.ReturnZeroMartix();
            for (int i = 0; i < this.Row; i++)
            {
                for (int j = 0; j < this.Col; j++)
                {
                    result.A[j, i] = this.A[i, j];
                }
            }
            return(result);
        }