Example #1
0
 /// <summary>
 /// Subtracts two real, rectangular matrices.
 /// </summary>
 /// <param name="A">The first matrix.</param>
 /// <param name="B">The second matrix.</param>
 /// <returns>The sum matrix <paramref name="A"/> - <paramref name="B"/>.</returns>
 public static RectangularMatrix operator -(RectangularMatrix A, RectangularMatrix B)
 {
     if (A == null)
     {
         throw new ArgumentNullException(nameof(A));
     }
     if (B == null)
     {
         throw new ArgumentNullException(nameof(B));
     }
     if (A.rows != B.rows)
     {
         throw new DimensionMismatchException();
     }
     if (A.cols != B.cols)
     {
         throw new DimensionMismatchException();
     }
     double[] abStore = MatrixAlgorithms.Subtract(
         A.store, A.offset, A.rowStride, A.colStride,
         B.store, B.offset, B.rowStride, B.colStride,
         A.rows, A.cols
         );
     return(new RectangularMatrix(abStore, A.rows, A.cols));
 }
Example #2
0
 /// <summary>
 /// Computes the difference of two square matrices.
 /// </summary>
 /// <param name="A">The first matrix.</param>
 /// <param name="B">The second matrix.</param>
 /// <returns>The difference <paramref name="A"/> - <paramref name="B"/>.</returns>
 /// <remarks>
 /// <para>Matrix subtraction is an O(N<sup>2</sup>) process.</para>
 /// </remarks>
 /// <exception cref="ArgumentNullException"><paramref name="A"/> or <paramref name="B"/> is null.</exception>
 /// <exception cref="DimensionMismatchException">The dimension of <paramref name="A"/> is not the same as the dimension of <paramref name="B"/>.</exception>
 public static SquareMatrix operator -(SquareMatrix A, SquareMatrix B)
 {
     if (A == null)
     {
         throw new ArgumentNullException("A");
     }
     if (B == null)
     {
         throw new ArgumentNullException("B");
     }
     if (A.dimension != B.dimension)
     {
         throw new DimensionMismatchException();
     }
     double[] abStore = MatrixAlgorithms.Subtract(A.store, B.store, A.dimension, A.dimension);
     return(new SquareMatrix(abStore, A.dimension));
 }