# 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

## Getting / Replacing a Submatrix.

Given an m×n matrix A = (aij), a submatrix B = (bij) is a matrix such that bij = ai+k,j+l for some fixed k,l.

The routines for getting a real submatrix of type double and setting a real submatrix of type double within a real matrix of type double are called Get_Submatrix() and Set_Submatrix() respectively and the routines for getting a complex submatrix of type double complex and setting a complex submatrix of type double complex within a complex matrix of type double complex are called Get_CSubmatrix() and Set_CSubmatrix() respectively.

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

There is 1 version of the Get_CSubmatrix() routine and 1 version of the Set_CSubmatrix() routine both written in C.

### Function List

• void Get_Submatrix( double *S, int mrows, int mcols, double *A, int ncols, int row, int col )

Copy mrows and mcols of the matrix A with ncols columns starting with A[row] [col] to the submatrix S. Note that S should be declared double S[mrows] [mcols] in the calling routine.

• void Set_Submatrix( double *A, int ncols, double *S, int mrows, int mcols, int row, int col )

Copy the mrows x mcols matrix S into the matrix A with ncols columns starting at the location A[row][col].

• void Get_CSubmatrix( double complex *S, int mrows, int mcols, double complex *A, int ncols, int row, int col )

Copy mrows and mcols of the complex matrix A with ncols columns starting with A[row] [col] to the complex submatrix S. Note that S should be declared double complex S[mrows] [mcols] in the calling routine.

• void Set_CSubmatrix( double complex *A, int ncols, double complex *S, int mrows, int mcols, int row, int col )

Copy the mrows x mcols complex matrix S into the complex matrix A with ncols columns starting at the location A[row][col].

#### C Source Code

• The file, get_submatrix.c, contains the version of Get_Submatrix() written in C.

• The file, set_submatrix.c, contains the version of Set_Submatrix() written in C.

• The file, get_csubmatrix.c, contains the version of Get_CSubmatrix() written in C.

• The file, set_csubmatrix.c, contains the version of Set_CSubmatrix() written in C.

#### NASM Source CodeFor Linux gcc Users

• The file, get_submatrix.asm, contains the version of Get_Submatrix() written in NASM.

• The file, set_submatrix.asm, contains the version of Set_Submatrix() written in NASM.

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

• The file, testgetsubmatrix.c, contains a test program of Get_Submatrix( ) in the file get_submatrix.c. This test program requires the file get_submatrix.c listed above.

• The file, GetSubmatrixTest.txt, contains the results of the test program testgetsubmatrix.c.

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

• The file, testsetsubmatrix.c, contains a test program of Set_Submatrix( ) in the file set_submatrix.c. This test program requires the file set_submatrix.c listed above.

• The file, SetSubmatrixTest.txt, contains the results of the test program testsetsubmatrix.c.

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

• The file, testgetcsubmatrix.c, contains a test program of Get_CSubmatrix( ) in the file get_csubmatrix.c. This test program requires the file get_csubmatrix.c listed above.

• The file, GetCSubmatrixTest.txt, contains the results of the test program testgetcsubmatrix.c.

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

• The file, testsetcsubmatrix.c, contains a test program of Set_CSubmatrix( ) in the file set_csubmatrix.c. This test program requires the file set_csubmatrix.c listed above.

• The file, SetCSubmatrixTest.txt, contains the results of the test program testsetcsubmatrix.c.

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