Пример #1
0
        /// <summary>
        /// Multiplies a matrix by a scalar to produce a new matrix.
        /// </summary>
        /// <param name="a">A scalar.</param>
        /// <param name="b">A matrix.</param>
        /// <returns>The matrix <paramref name="a"/>*<paramref name="b"/>.</returns>
        public static Matrix Multiply(double a, MatrixSet b)
        {
            Vector[] vectors = new Vector[b.Col];

            for (int i = 0; i < b.Col; i++)
            {
                vectors[i] = new Vector(a * b.Cols[i]);
            }

            return(new Matrix(vectors));
        }
Пример #2
0
 /// <summary>
 /// Determines whether two vectors are exactly equal.
 /// </summary>
 /// <param name="a">The first vector.</param>			/// <param name="b">The second vector.</param>
 /// <returns><c>true</c> if the two vectors are equal; otherwise, <c>false</c>.</returns>
 public static bool Compare(MatrixSet a, MatrixSet b)
 {
     if ((object)a == null && (object)b == null)
     {
         return(true);
     }
     else if ((object)a == null && (object)b != null)
     {
         return(false);
     }
     else
     {
         return(a.Equals(b));
     }
 }
Пример #3
0
        /// <summary>
        /// Subtracts a matrix from a matrix to produce a new matrix.
        /// </summary>
        /// <param name="a">The first matrix.</param>
        /// <param name="b">The second matrix.</param>
        /// <returns>The matrix <paramref name="a"/> - <paramref name="b"/>.</returns>
        public static Matrix Subtract(MatrixSet a, MatrixSet b)
        {
            if (a.Dimension != b.Dimension)
            {
                throw (new DimensionsNotEqualException());
            }

            Vector[] vectors = new Vector[a.Col];

            for (int i = 0; i < a.Col; i++)
            {
                vectors[i] = new Vector(a.Cols[i] - b.Cols[i]);
            }

            return(new Matrix(vectors));
        }
Пример #4
0
        /// <summary>
        /// Multiplies a matrix by a matrix to produce a new matrix.
        /// </summary>
        /// <param name="a">the first matrix.</param>
        /// <param name="b">the second matrix.</param>
        /// <returns>The matrix <paramref name="a"/>*<paramref name="b"/>.</returns>
        public static Matrix Multiply(MatrixSet a, MatrixSet b)
        {
            if (a.Col != b.Row)
            {
                throw (new MatrixMultiplyException());
            }

            Matrix m = new Matrix(a.Row, b.Col);

            for (int i = 0; i < a.Row; i++)
            {
                for (int j = 0; j < b.Col; j++)
                {
                    m.Val[i][j] = a.Rows[i] * b.Cols[j];
                }
            }

            return(m);
        }
Пример #5
0
        protected MatrixSet(MatrixSet m)
        {
            col = m.Col;
            row = m.Row;

            Val = new double[row][];
            for (int i = 0; i < row; i++)
            {
                Val[i] = new double[col];
            }

            int j = 0;

            foreach (Vector vector in m.Cols)
            {
                for (int i = 0; i < vector.Dimension; i++)
                {
                    Val[i][j] = vector[i];
                }

                j++;
            }
        }
Пример #6
0
 public Matrix(MatrixSet m) : base(m)
 {
 }
Пример #7
0
 public static Matrix Negative(MatrixSet a)
 {
     return(Multiply(-1, a));
 }
Пример #8
0
        /// <summary>
        /// Subtracts a matrix from a matrix to produce a new matrix.
        /// </summary>
        /// <param name="a">The first matrix.</param>
        /// <param name="b">The second matrix.</param>
        /// <returns>The matrix <paramref name="a"/> - <paramref name="b"/>.</returns>
        public static Matrix Subtract(MatrixSet a, MatrixSet b)
        {
            if (a.Dimension != b.Dimension)
            {
                throw (new DimensionsNotEqualException());
            }

            Vector[] vectors = new Vector[a.Col];

            for (int i = 0; i < a.Col; i++)
            {
                vectors[i] = new Vector(a.Cols[i] - b.Cols[i]);
            }

            return new Matrix(vectors);
        }
Пример #9
0
 public Matrix(MatrixSet m)
     : base(m)
 {
 }
Пример #10
0
 public static Matrix Negative(MatrixSet a)
 {
     return Multiply(-1, a);
 }
Пример #11
0
        /// <summary>
        /// Multiplies a matrix by a matrix to produce a new matrix.
        /// </summary>
        /// <param name="a">the first matrix.</param>
        /// <param name="b">the second matrix.</param>
        /// <returns>The matrix <paramref name="a"/>*<paramref name="b"/>.</returns>		
        public static Matrix Multiply(MatrixSet a, MatrixSet b)
        {
            if (a.Col != b.Row)
            {
                throw (new MatrixMultiplyException());
            }

            Matrix m = new Matrix(a.Row, b.Col);

            for (int i = 0; i < a.Row; i++)
            {
                for (int j = 0; j < b.Col; j++)
                {
                    m.Val[i][j] = a.Rows[i] * b.Cols[j];
                }
            }

            return m;
        }
Пример #12
0
        /// <summary>
        /// Multiplies a matrix by a scalar to produce a new matrix.
        /// </summary>
        /// <param name="a">A scalar.</param>
        /// <param name="b">A matrix.</param>
        /// <returns>The matrix <paramref name="a"/>*<paramref name="b"/>.</returns>		
        public static Matrix Multiply(double a, MatrixSet b)
        {
            Vector[] vectors = new Vector[b.Col];

            for (int i = 0; i < b.Col; i++)
            {
                vectors[i] = new Vector(a * b.Cols[i]);
            }

            return new Matrix(vectors);
        }
Пример #13
0
 /// <summary>
 /// Determines whether two vectors are exactly equal.
 /// </summary>
 /// <param name="a">The first vector.</param>			/// <param name="b">The second vector.</param>
 /// <returns><c>true</c> if the two vectors are equal; otherwise, <c>false</c>.</returns>
 public static bool Compare(MatrixSet a, MatrixSet b)
 {
     if ((object)a == null && (object)b == null)
     {
         return true;
     }
     else if ((object)a == null && (object)b != null)
     {
         return false;
     }
     else
     {
         return a.Equals(b);
     }
 }
Пример #14
0
        protected MatrixSet(MatrixSet m)
        {
            col = m.Col;
            row = m.Row;

            Val = new double[row][];
            for (int i = 0; i < row; i++)
            {
                Val[i] = new double[col];
            }

            int j = 0;

            foreach (Vector vector in m.Cols)
            {
                for (int i = 0; i < vector.Dimension; i++)
                {
                    Val[i][j] = vector[i];
                }

                j++;
            }
        }