/// <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)); }
/// <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)); } }
/// <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)); }
/// <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); }
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++; } }
public Matrix(MatrixSet m) : base(m) { }
public static Matrix Negative(MatrixSet a) { return(Multiply(-1, a)); }
/// <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); }
public static Matrix Negative(MatrixSet a) { return Multiply(-1, a); }
/// <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; }
/// <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); }
/// <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); } }