private static SymmetricMatrix <T> Add <T>(DiagonalMatrix <T> lhs, SymmetricMatrix <T> rhs) { var result = new SymmetricMatrix <T>(rhs); for (int i = 0; i < lhs.Order; i++) { result[i, i] = (dynamic)lhs[i, i] + (dynamic)result[i, i]; } return(result); }
private static DiagonalMatrix <T> Add <T>(DiagonalMatrix <T> lhs, DiagonalMatrix <T> rhs) { var resultArray = new T[lhs.Order]; for (int i = 0; i < lhs.Order; i++) { resultArray[i] = (dynamic)lhs[i, i] + (dynamic)rhs[i, i]; } return(new DiagonalMatrix <T>(resultArray)); }
private static SquareMatrix <T> Add <T>(SquareMatrix <T> lhs, DiagonalMatrix <T> rhs) { var result = new SquareMatrix <T>(lhs); for (int i = 0; i < result.Order; i++) { result[i, i] = (dynamic)result[i, i] + (dynamic)rhs[i, i]; } return(result); }
/// <summary> /// Create clone of diagonal matrix. /// </summary> /// <returns>Clone of diagonal matrix.</returns> public new DiagonalMatrix <T> Clone() { DiagonalMatrix <T> diagonalMatrix = new DiagonalMatrix <T>(this.Height); for (int i = 0; i < this.Height; i++) { diagonalMatrix[i, i] = this[i, i]; } return(diagonalMatrix); }
public static DiagonalMatrix <T> Add <T>(this DiagonalMatrix <T> leftMatrix, DiagonalMatrix <T> rightMatrix) { DiagonalMatrix <T> result = leftMatrix.Clone(); for (int i = 0; i < result.Width; i++) { dynamic value = rightMatrix[i, i]; result[i, i] += value; } return(result); }
private static Matrix <T> InitializeResultMatrix <T>(Matrix <T> lhs, Matrix <T> rhs) { Matrix <T> result; if (lhs.GetType() == typeof(SquareMatrix <T>) || rhs.GetType() == typeof(SquareMatrix <T>)) { result = new SquareMatrix <T>(lhs.Order); } else if (lhs.GetType() == typeof(SymmetricalMatrix <T>) || rhs.GetType() == typeof(SymmetricalMatrix <T>)) { result = new SymmetricalMatrix <T>(lhs.Order); } else { result = new DiagonalMatrix <T>(lhs.Order); } return(result); }
/// <summary> /// finds sum with diagonal matrix /// </summary> /// <param name="matrix">diagonal matrix which is added to existing matrix</param> /// <returns>new square matrix as result of sum two matrixes</returns> public SquareMatrix <T> Visit(DiagonalMatrix <T> matrix) => Sum(matrix);
private static void Sum <T>(DiagonalMatrix <T> matrix, DiagonalMatrix <T> addedMatrix) { SumDiagonalElements <T>(matrix, addedMatrix); }
private static SquareMatrix <T> Add <T>(DiagonalMatrix <T> lhs, SquareMatrix <T> rhs) => Add(rhs, lhs);
private static SymmetricMatrix <T> Add <T>(SymmetricMatrix <T> lhs, DiagonalMatrix <T> rhs) => Add(rhs, lhs);