예제 #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++;
            }
        }