Exemplo n.º 1
0
        public IMatrix Multiply(IVectorMatrix right1)
        {
            var result = new VectorMatrix(right1.Count);

            for (int i = 0; i < result.Count; i++)
            {
                result[i] = right1[i] * this[i];
            }
            return(result);
        }
Exemplo n.º 2
0
        //public IMatrix Plus(IMatrix right)
        //{
        //    throw new NotImplementedException();
        //}

        //public IMatrix Minus(IMatrix right)
        //{
        //    throw new NotImplementedException();
        //}

        //public IMatrix Multiply(IMatrix right)
        //{
        //    throw new NotImplementedException();
        //}

        public IMatrix SubMatrix(int fromIndex, int count)
        {
            var vm = new VectorMatrix(count);
            var endIndexExcluded = fromIndex + count;

            for (int i = fromIndex, j = 0; i < endIndexExcluded; i++, j++)
            {
                vm.Data[j] = this.Data[i];
            }
            return(vm);
        }
Exemplo n.º 3
0
        IMatrix IArithmeticOperation <IMatrix> .Opposite()
        {
            VectorMatrix matrix = new VectorMatrix(this.Count);
            int          count  = this.Count;

            for (int i = 0; i < count; i++)
            {
                matrix[i] = -this[i];
            }
            return(matrix);
        }
Exemplo n.º 4
0
        IMatrix IArithmeticOperation <IMatrix> .Divide(double right)
        {
            VectorMatrix matrix = new VectorMatrix(this.Count);
            int          count  = this.Count;

            for (int i = 0; i < count; i++)
            {
                matrix[i] = this[i] / right;
            }
            return(matrix);
        }
Exemplo n.º 5
0
        /// <summary>
        /// 返回新的乘法结果。
        /// </summary>
        /// <param name="right"></param>
        /// <returns></returns>
        public IMatrix Multiply(VectorMatrix right)
        {
            int     row    = this.RowCount;
            int     col    = this.ColCount;
            IMatrix matrix = new ArrayMatrix(row, 1);

            for (int i = 0; i < row; i++)
            {
                matrix[i, 0] = this[i, i] * right[i, 0];
            }
            return(matrix);
        }
Exemplo n.º 6
0
        /// <summary>
        /// 矩阵乘法,左边列数应该等于右边行
        /// N * 1 列向量,只乘以 1 * M 的行向量,结果为 N*M 的矩阵。
        /// </summary>
        /// <param name="right"></param>
        /// <returns></returns>
        public IMatrix Multiply(IMatrix right)
        {
            if (ColCount != right.RowCount)
            {
                throw new ArgumentException("维数不正确!不可及操作。");
            }

            if (right.ColCount == 1)//返回仍然为列向量
            {
                VectorMatrix matrix = new VectorMatrix(this.Count);
                double       val    = right[0, 0];
                for (int i = 0; i < this.Count; i++)
                {
                    matrix[i] = this[i] * val;
                }
                return(matrix);
            }
            ArrayMatrix my = new ArrayMatrix(this);

            return(my.Multiply(right));
        }
Exemplo n.º 7
0
        public IMatrix Minus(IMatrix right)
        {
            if (right == null)
            {
                return(this);
            }

            if (this.RowCount != right.RowCount ||
                ColCount != right.ColCount
                )
            {
                throw new ArgumentException("维数不正确!不可及操作。");
            }

            VectorMatrix matrix = new VectorMatrix(this.Count);
            int          count  = this.Count;

            for (int i = 0; i < count; i++)
            {
                matrix[i] = this[i] - right[i, 0];
            }
            return(matrix);
        }