# General Purpose Matrix Operations

 Home Matrix Home General Purpose Matrix Routines Home Copy Matrices / Vectors Get Row / Column of a Matrix Set Row / Column of a Matrix Get / Set the Diagonal of a Matrix Set Matrix Diagonal Elements to a Scalar Get / Set a Submatrix Fill Matrix with Scalar Join Matrices Interchange Rows / Columns Transpose Matrix

## Transpose a matrix.

Given an m×n matrix A = (aij) the transpose of A is the n×m matrix B = (bij) where bij = aji for all i,j.

The routine for transposing an arbitrary m×n real matrix of type double is called Transpose_Matrix(), the routine for transposing a square n×n real matrix of type double is called Transpose_Square_Matrix(), the routine for transposing an arbitrary m×n complex matrix of type double complex is called Transpose_CMatrix(), and the routine for transposing a square n×n complex matrix of type double complex is called Transpose_Square_CMatrix().

There are 2 versions of the Transpose_Matrix() routine and 2 versions of the Transpose_Square_Matrix() routine. For both routines, the Transpose_Matrix() routine and the Transpose_Square_Matrix() routine, 1 version is written in C, and 1 version is written in NASM assembly language.

There is 1 version of the Transpose_CMatrix() routine and 1 version of the Transpose_Square_Matrix() routine, both versions are written in C.

### Function List

• void Transpose_Matrix( double *At, double *A, int nrows, int ncols)

Take the transpose of the nrows × ncols matrix A and store in the ncols × nrows matrix At, i.e. At = AT. The matrix At should be declared as double At[ncols][nrows] in the calling routine, and the matrix A declared as double A[nrows][ncols]. In general, At and A should be disjoint i.e. their memory locations should be distinct.

• void Transpose_Square_Matrix( double *A, int n )

Take the transpose of the n × n matrix A and store in place.

• void Transpose_CMatrix( double complex *At, double complex *A, int nrows, int ncols)

Take the transpose of the nrows × ncols complex matrix A and store in the ncols × nrows complex matrix At, i.e. At = AT. The matrix At should be declared as double complex At[ncols][nrows] in the calling routine, and the matrix A declared as double complex A[nrows][ncols]. In general, At and A should be disjoint i.e. their memory locations should be distinct.

• void Transpose_Square_CMatrix( double complex *A, int n )

Take the transpose of the n × n complex matrix A and store in place.

#### C Test Code, Test Results, and Build Shell Script

• The file, testtransposematrix.c, contains a test program of Transpose_Matrix( ) in the file transpose_matrix.c. This test program requires the file transpose_matrix.c listed above.

• The file, TransposeMatrixTest.txt, contains the results of the test program testtransposematrix.c.

• The file, testtransposematrix.sh, contains the shell script used to compile, link, and execute the test program ttesttransposematrix.c.

• The file, testtransposesqmatrix.c, contains a test program of Transpose_Square_Matrix( ) in the file transpose_square_matrix.c. This test program requires the file transpose_square_matrix.c listed above.

• The file, TransposeSquareMatrixTest.txt, contains the results of the test program ttesttransposesqmatrix.c.

• The file, testtransposesqmatrix.sh, contains the shell script used to compile, link, and execute the test program testtransposesqmatrix.c.

• The file, testtransposecmatrix.c, contains a test program of Transpose_CMatrix( ) in the file transpose_cmatrix.c. This test program requires the file transpose_cmatrix.c listed above.

• The file, TransposeCMatrixTest.txt, contains the results of the test program testtransposecmatrix.c.

• The file, testtransposecmatrix.sh, contains the shell script used to compile, link, and execute the test program testtransposecmatrix.c.

• The file, testtransposesqcmatrix.c, contains a test program of Transpose_Square_CMatrix( ) in the file transpose_square_cmatrix.c. This test program requires the file transpose_square_cmatrix.c listed above.

• The file, TransposeSquareCMatrixTest.txt, contains the results of the test program testtransposesqcmatrix.c.

• The file, testtransposesqcmatrix.sh, contains the shell script used to compile, link, and execute the test program testtransposesqcmatrix.c.