/// <summary>
        /// Implementation of addition operation for diagonal matrix.
        /// </summary>
        /// <param name="matrix">The matrix for addition.</param>
        /// <returns>Result of addition.</returns>
        protected override SquareMatrixBase <T> Add(SquareMatrixBase <T> matrix)
        {
            if (this.Size != matrix.Size)
            {
                throw new ArgumentException("Matrixes must have the same size.", nameof(matrix));
            }

            SquareMatrixBase <T> result;

            if (matrix.GetType() == typeof(DiagonalMatix <T>))
            {
                result = new DiagonalMatix <T>(Size);
                for (int i = 0; i < Size; i++)
                {
                    result[i, i] = (dynamic)this[i, i] + (dynamic)matrix[i, i];
                }

                return(result);
            }

            else
            {
                result = new SquareMatrix <T>(Size);
            }

            for (int i = 0; i < Size; i++)
            {
                for (int j = 0; j < Size; j++)
                {
                    result[i, j] = (dynamic)this[i, j] + (dynamic)matrix[i, j];
                }
            }

            return(result);
        }
        /// <summary>
        /// Implementation of addition operation for square matrix.
        /// </summary>
        /// <param name="matrix">The matrix for addition.</param>
        /// <returns>Result of addition.</returns>
        protected override SquareMatrixBase <T> Add(SquareMatrixBase <T> matrix)
        {
            if (this.Size != matrix.Size)
            {
                throw new ArgumentException("Matrices must have the same size.", nameof(matrix));
            }

            var result = new SquareMatrix <T>(Size);

            for (int i = 0; i < Size; i++)
            {
                for (int j = 0; j < Size; j++)
                {
                    result[i, j] = (dynamic)this[i, j] + (dynamic)matrix[i, j];
                }
            }

            return(result);
        }
示例#3
0
 protected abstract SquareMatrixBase <T> Add(SquareMatrixBase <T> matrix);