/// <summary> /// Finds the sum of two symmetric matrices. /// </summary> /// <exception cref="ArgumentNullException"> /// Thrown if the second matrix is null. /// </exception> /// <exception cref="ArgumentException"> /// Thrown if matrices have different sizes. /// </exception> /// <typeparam name="T">The type of matrices.</typeparam> /// <param name="matrix1">The first matrix.</param> /// <param name="matrix2">The second matrix.</param> /// <param name="iSum">The summing logic.</param> /// <returns>Returns the resulting matrix.</returns> public static SymmetricMatrix <T> Add <T>(this SymmetricMatrix <T> matrix1, SymmetricMatrix <T> matrix2, ISum <T> iSum) { if (matrix2 == null) { throw new ArgumentNullException("The second matrix is null!"); } if (matrix1.Size != matrix2.Size) { throw new ArgumentException("Sizes of matrices are different!"); } int size = matrix1.Size; var result = new SymmetricMatrix <T>(size); for (int i = 0; i < size; i++) { for (int j = 0; j < i + 1; j++) { result[i, j] = iSum.Sum(matrix1[i, j], matrix2[i, j]); result[j, i] = result[i, j]; } } return(result); }
/// <summary> /// Writes a record. /// </summary> /// <param name="record">the record to write</param> public void Write(T record) { if (_sum == null) { WriteRecord(record); } else { if (_buffer.Count == 0 || _comparer.Compare(record, _buffer[0]) == 0) { _logger.Trace("Record added to sum buffer"); _buffer.Add(record); } else { _logger.Trace("Writing sum buffer"); WriteRecord(_sum.Sum(_buffer)); _buffer.Clear(); _buffer.Add(record); } } }
/// <summary> /// Finds sum with any matrix /// </summary> /// <param name="matrix">any matrix which is added to existing matrix</param> /// <returns>new square matrix as result of sum two matrixes</returns> private SquareMatrix <T> Sum(BaseMatrix <T> matrix) { int size = (int)Math.Sqrt(matrix.Length); Result = new SquareMatrix <T>(size); for (int i = 0; i < size; i++) { for (int j = 0; j < size; j++) { Result[i, j] = criterion.Sum(other[i, j], matrix[i, j]); } } return(Result as SquareMatrix <T>); }
/// <summary> /// Finds the sum of two diagonal matrices. /// </summary> /// <exception cref="ArgumentNullException"> /// Thrown if the second matrix is null. /// </exception> /// <exception cref="ArgumentException"> /// Thrown if matrices have different sizes. /// </exception> /// <typeparam name="T">The type of matrices.</typeparam> /// <param name="matrix1">The first matrix.</param> /// <param name="matrix2">The second matrix.</param> /// <param name="iSum">The summing logic.</param> /// <returns>Returns the resulting matrix.</returns> public static DiagonalMatrix <T> Add <T>(this DiagonalMatrix <T> matrix1, DiagonalMatrix <T> matrix2, ISum <T> iSum) { if (matrix2 == null) { throw new ArgumentNullException("The second matrix is null!"); } if (matrix1.Size != matrix2.Size) { throw new ArgumentException("Sizes of matrices are different!"); } int size = matrix1.Size; var result = new DiagonalMatrix <T>(size); for (int i = 0; i < size; i++) { result[i, i] = iSum.Sum(matrix1[i, i], matrix2[i, i]); } return(result); }
int Multiplication(int x, int a, int b) { return(x * _sum.Sum(a, b)); }
public String Execute() { return(cmd.Sum()); }
/// <summary> /// Overload of plus operation /// </summary> /// <param name="arg1">First matrix</param> /// <param name="arg2">Second matrix</param> /// <returns>New class object with summed coefficients</returns> public static SquareMatrix <T> operator +(SquareMatrix <T> arg1, SquareMatrix <T> arg2) { return(new SquareMatrix <T>(sum.Sum(arg1.Array, arg2.Array), sum)); }