Transpose
The transpose of matrix M, written as is a matrix in which every element i, j equals the element j, i of the original matrix. The transpose of a matrix can be acquired by reflecting the matrix over its main diagonal, writing the rows of M as the columns of , or by writing the columns of M as the rows of . We can express the transpose for each component of a matrix with the following equation:
The transpose operation replaces the rows of a matrix with its columns:
Getting ready
We're going to create a non-nested loop that serves as a generic Transpose
function. This function will be able to transpose matrices of any dimension. We're then going to create Transpose
functions specific to 2 X 2, 3 X 3, and 4 X 4 matrices. These more specific functions are going to call the generic Transpose
with the appropriate arguments.
How to do it…
Follow these steps to implement a generic transpose function and transpose functions for two, three and four dimensional square...