# 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

## Interchanging two rows / columns of a matrix.

Given an m×n matrix A = (aij) because each row has the same length, a new matrix can be formed by interchanging two rows. Similarly because each column of the matrix has the same length, a new matrix can be formed by interchanging two columns.

The routines for interchanging two rows or interchanging two columns of a real matrix of type double are called Interchange_Rows() and Interchange_Columns() respectively and the routines for interchanging two rows or interchanging two columns of a complex matrix of type double complex are called Interchange_CRows() and Interchange_CColumns() respectively.

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

There is 1 version of the Interchange_CRows() routine and 1 version of the Interchange_CColumns() routine, both written in C.

### Function List

• void Interchange_Rows( double *A, int row1, int row2, int ncols )

Interchange the rows row1 and row2 of the nrows × ncols matrix A, where nrows need not be specified other than nrowsmax(row1, row2).

• void Interchange_Columns( double *A, int col1, int col2, int nrows, int ncols )

Interchange the columns col1 and col2 of the nrows × ncols matrix A.

• void Interchange_CRows( double complex *A, int row1, int row2, int ncols )

Interchange the rows row1 and row2 of the nrows × ncols complex matrix A, where nrows need not be specified other than nrowsmax(row1, row2).

• void Interchange_CColumns( double complex *A, int col1, int col2, int nrows, int ncols )

Interchange the columns col1 and col2 of the nrows × ncols complex matrix A.

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

• The file, testinterchangerows.c, contains a test program of Interchange_Rows( ) in the file interchange_rows.c. This test program requires the file interchange_rows.c listed above.

• The file, InterchangeRowsTest.txt, contains the results of the test program testinterchangerows.c.

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

• The file, testinterchangecols.c, contains a test program of Interchange_Columns( ) in the file interchange_cols.c. This test program requires the file interchange_cols.c listed above.

• The file, InterchangeColsTest.txt, contains the results of the test program testinterchangecols.c.

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

• The file, testinterchangecrows.c, contains a test program of Interchange_CRows( ) in the file interchange_crows.c. This test program requires the file interchange_crows.c listed above.

• The file, InterchangeCRowsTest.txt, contains the results of the test program testinterchangecrows.c.

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

• The file, testinterchangeccols.c, contains a test program of Interchange_CColumns( ) in the file interchange_ccols.c. This test program requires the file interchange_ccols.c listed above.

• The file, InterchangeCColsTest.txt, contains the results of the test program testinterchangeccols.c.

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