Exemple #1
0
 /// <summary>
 /// Vector subtraction
 /// </summary>
 /// <param name="L">Left vector</param>
 /// <param name="R">Right vector</param>
 /// <returns>new Vector(L-R)</returns>
 public static Vector <T> operator -(Vector <T> L, Vector <T> R)
 {
     T[] result = new T[L.numEntries];
     if (R.numEntries != L.numEntries)
     {
         throw new InvalidOperationException("Invalid dimensions for vector subtraction");
     }
     else
     {
         for (int i = 0; i < result.Length; i++)
         {
             result[i] = operators.subtract(L.values[i], R.values[i]);
         }
         return(new Vector <T>(result));
     }
 }
Exemple #2
0
        /// <summary>
        /// Matrix negation
        /// </summary>
        /// <param name="R">Right matrix</param>
        /// <returns>new Matrix(-R)</returns>
        public static Matrix <U> operator -(Matrix <U> R)
        {
            int m = R.numRows;
            int n = R.numColumns;

            U[][] result = new U[m][];
            //create new 2d array
            for (int i = 0; i < m; i++)
            {
                result[i] = new U[n];
            }
            for (int i = 0; i < m; i++)
            {
                for (int j = 0; j < n; j++)
                {
                    result[i][j] = operators.subtract(operators.GetZeroValue(), R.values[i][j]);
                }
            }
            return(new Matrix <U>(result));
        }