/// <summary> /// Subtracts a matrix from a matrix and put the result in a third matrix. /// </summary> /// <param name="a">A <see cref="MatrixD"/> instance to subtract from.</param> /// <param name="b">A <see cref="MatrixD"/> instance to subtract.</param> /// <param name="result">A <see cref="MatrixD"/> instance to hold the result.</param> /// <remarks>result[x][y] = a[x][y] - b[x][y]</remarks> /// <exception cref="System.ArgumentException">Matrix dimentions do not match.</exception> public static void Subtract(MatrixD a, MatrixD b, MatrixD result) { if ((!MatrixD.EqualDimentions(a, b)) && (!MatrixD.EqualDimentions(a, result))) { throw new ArgumentException("Matrix dimentions do not match."); } for (int r = 0; r < a.Rows; r++) { for (int c = 0; c < a.Columns; c++) { result._data[r][c] = a._data[r][c] - b._data[r][c]; } } }
/// <summary> /// Subtracts a matrix from a matrix. /// </summary> /// <param name="a">A <see cref="MatrixD"/> instance to subtract from.</param> /// <param name="b">A <see cref="MatrixD"/> instance to subtract.</param> /// <returns>A new <see cref="MatrixD"/> instance containing the difference.</returns> /// <remarks>result[x][y] = a[x][y] - b[x][y]</remarks> /// <exception cref="System.ArgumentException">Matrix dimentions do not match.</exception> public static MatrixD Subtract(MatrixD a, MatrixD b) { if (!MatrixD.EqualDimentions(a, b)) { throw new ArgumentException("Matrix dimentions do not match."); } MatrixD result = new MatrixD(a.Rows, a.Columns); for (int r = 0; r < a.Rows; r++) { for (int c = 0; c < a.Columns; c++) { result._data[r][c] = a._data[r][c] - b._data[r][c]; } } return(result); }