namespace XmlDocumentation; /// /// Abstract base class representing a mathematical matrix. /// public abstract class Matrix { /// /// Gets the number of rows in the matrix. /// public abstract int Rows { get; } /// /// Gets the number of columns in the matrix. /// public abstract int Columns { get; } /// /// Gets or sets the value at the specified row and column in the matrix. /// /// The row index. /// The column index. /// The value at the specified position. /// Thrown if the row or column index is out of bounds. public abstract double this[int row, int column] { get; set; } /// /// Transposes the matrix, swapping rows and columns. /// /// A new matrix that is the transpose of the current matrix. /// /// /// Matrix m = new ArrayMatrix(2, 3); /// m[0, 0] = 1; m[0, 1] = 2; m[0, 2] = 3; /// m[1, 0] = 4; m[1, 1] = 5; m[1, 2] = 6; /// Matrix transposed = m.Transpose(); /// Console.WriteLine(transposed[0, 0]); // Outputs 1 /// /// public abstract Matrix Transpose(); /// /// Adds two matrices together. /// /// The matrix to add to the current matrix. /// A new matrix containing the sum of the two matrices. /// Thrown if the matrices do not have the same dimensions. /// /// /// Matrix m1 = new ArrayMatrix(2, 2); /// m1[0, 0] = 1; m1[0, 1] = 2; /// m1[1, 0] = 3; m1[1, 1] = 4; /// /// Matrix m2 = new ArrayMatrix(2, 2); /// m2[0, 0] = 5; m2[0, 1] = 6; /// m2[1, 0] = 7; m2[1, 1] = 8; /// /// Matrix sum = m1.Add(m2); /// Console.WriteLine(sum[0, 0]); // Outputs 6 /// /// public abstract Matrix Add(Matrix other); /// /// Multiplies the current matrix with another matrix. /// /// The matrix to multiply by. /// A new matrix containing the result of the multiplication. /// Thrown if the number of columns in the current matrix is not equal to the number of rows in the other matrix. /// /// /// Matrix m1 = new ArrayMatrix(2, 3); /// m1[0, 0] = 1; m1[0, 1] = 2; m1[0, 2] = 3; /// m1[1, 0] = 4; m1[1, 1] = 5; m1[1, 2] = 6; /// /// Matrix m2 = new ArrayMatrix(3, 2); /// m2[0, 0] = 7; m2[0, 1] = 8; /// m2[1, 0] = 9; m2[1, 1] = 10; /// m2[2, 0] = 11; m2[2, 1] = 12; /// /// Matrix product = m1.Multiply(m2); /// Console.WriteLine(product[0, 0]); // Outputs 58 /// /// public abstract Matrix Multiply(Matrix other); }