Example #1
0
        public static DLNPVector operator *(double scalar, DLNPVector vector)
        {
            DLNPVector result = new DLNPVector(vector.Size);

            for (int i = 0; i < vector.Size; i++)
            {
                result[i] = scalar * vector[i];
            }

            return(result);
        }
Example #2
0
        public static DLNPVector operator +(DLNPVector a, DLNPVector b)
        {
            if (a.Size == b.Size)
            {
                DLNPVector result = new DLNPVector(a.Size);

                for (int i = 0; i < a.Size; i++)
                {
                    result[i] = a[i] + b[i];
                }

                return(result);
            }
            else
            {
                throw new InvalidOperationException("Vectors must be of the same size!");
            }
        }
Example #3
0
        public IVector Add(IVector v)
        {
            if (this.Size == v.Size)
            {
                DLNPVector result = new DLNPVector(this.Size);

                for (int i = 0; i < this.Size; i++)
                {
                    result[i] = this[i] + v[i];
                }

                return(result);
            }
            else
            {
                throw new InvalidOperationException("Vectors must be of the same size!");
            }
        }
Example #4
0
        public IVector Mul(IVector v)
        {
            if (this.Columns == v.Size)
            {
                DLNPVector result = new DLNPVector(v.Size);

                for (int m = 0; m < v.Size; m++)
                {
                    for (int i = 0; i < v.Size; i++)
                    {
                        result[m] += this[m, i] * v[i];
                    }
                }

                return(result);
            }
            else
            {
                throw new InvalidOperationException("Matrix and vector size are not compatible!");
            }
        }
Example #5
0
        /// <summary>
        /// Multiplication of matrix and vector. Vector size must be equal to matrix columns.
        /// </summary>
        /// <param name="a"></param>
        /// <param name="b"></param>
        /// <returns>Vector modified by a matrix</returns>
        public static DLNPVector operator *(DLNPMatrix a, DLNPVector b)
        {
            if (a.Columns == b.Size)
            {
                DLNPVector result = new DLNPVector(b.Size);

                for (int m = 0; m < b.Size; m++)
                {
                    for (int i = 0; i < b.Size; i++)
                    {
                        result[m] += a[m, i] * b[i];
                    }
                }

                return(result);
            }
            else
            {
                throw new InvalidOperationException("Matrix and vector size are not compatible!");
            }
        }