## Joining two matrices along the rows / columns.

Given an*m*×

*n*matrix

_{1}**A**= (

*a*) and an

_{ij}*m*×

*n*matrix

_{2}**B**= (

*b*), then an

_{ij}*m*×(

*n*+

_{1}*n*) matrix

_{2}**C**= (

*c*) may be formed by concatenating the rows of

_{ij}**A**with the rows of

**B**, i.e. if 0 ≤ i <

*m*, 0 ≤ j <

*n*then

_{1}*c*=

_{ij}*a*and if 0 ≤ i <

_{ij}*m*,

*n*≤ j <

_{1}*n*+

_{1}*n*then

_{2}*c*=

_{ij}*b*.

_{i,j-n1}Similarly given an

*m*×

_{1}*n*matrix

**A**= (

*a*) and an

_{ij}*m*×

_{2}*n*matrix

**B**= (

*b*), then an (

_{ij}*m*+

_{1}*m*)×

_{2}*n*matrix

**C**= (

*c*) may be formed by concatenating the columns of

_{ij}**A**with the columns of

**B**, i.e. if 0 ≤ i <

*m*, 0 ≤ j <

_{1}*n*then

*c*=

_{ij}*a*and if

_{ij}*m*≤ i <

_{1}*m*+

_{1}*m*, 0 ≤ j <

_{2}*n*then

*c*=

_{ij}*b*.

_{i-m1,j}The routines for concatenating two real matrices of type

*double*by rows or columns are called

*Join_Matrices_by_Rows()*and

*Join_Matrices_by_Columns()*respectively and the routines for concatenating two complex matrices of type

*double complex*by rows or columns are called

*Join_CMatrices_by_Rows()*and

*Join_CMatrices_by_Columns()*respectively.

There are 2 versions of the

*Join_Matrices_by_Rows()*routine and 2 versions of the

*Join_Matrices_by_Columns()*routine. For both the

*Join_Matrices_by_Rows()*and the

*Join_Matrices_by_Columns()*routine, 1 version is written in

*C*and 1 version is written in

*NASM*assembly language.

There is 1 version of the

*Join_CMatrices_by_Rows()*routine and 1 version of the

*Join_CMatrices_by_Columns()*routine, both versions written in

*C*.

### Function List

- void Join_Matrices_by_Rows( double *C, double *A, int nrows, int ncols, double *B, int mcols )

Copy the*nrows × ncols*matrix*A*into the*nrows × (ncols + mcols)*matrix*C*and then copy the*nrows × mcols*matrix*B*starting at the location*C[0][ncols]*, i.e.*C = [A:B]*. The matrix*C*should be declared as*double C[nrows][ncols + mcols]*in the calling routine.

- void Join_Matrices_by_Columns( double *C, double *A, int nrows, int ncols, double *B, int mrows )

Copy the*nrows × ncols*matrix*A*into the*(nrows + mrows) × ncols*matrix*C*and then copy the*mrows × ncols*matrix*B*starting at the location*C[nrows][0]*, i.e.*C*, where^{T}= [A^{ T}:B^{ T}]^{ T}denotes the transpose. The matrix^{T}*C*should be declared as*double C[nrows + mrows][ncols]*in the calling routine.

- void Join_CMatrices_by_Rows( double complex *C, double complex *A, int nrows, int ncols, double complex *B, int mcols )

Copy the*nrows × ncols*complex matrix*A*into the*nrows × (ncols + mcols)*complex matrix*C*and then copy the*nrows × mcols*complex matrix*B*starting at the location*C[0][ncols]*, i.e.*C = [A:B]*. The matrix*C*should be declared as*double complex C[nrows][ncols + mcols]*in the calling routine.

- void Join_CMatrices_by_Columns( double complex *C, double complex *A, int nrows, int ncols, double complex *B, int mrows )

Copy the*nrows × ncols*complex matrix*A*into the*(nrows + mrows) × ncols*complex matrix*C*and then copy the*mrows × ncols*complex matrix*B*starting at the location*C[nrows][0]*, i.e.*C*, where^{T}= [A^{ T}:B^{ T}]^{ T}denotes the transpose. The complex matrix^{T}*C*should be declared as*double complex C[nrows + mrows][ncols]*in the calling routine.

*C* Source Code

- The file, join_by_rows.c, contains the version of Join_Matrices_by_Rows() written in
*C*.

- The file, join_by_cols.c, contains the version of Join_Matrices_by_Columns() written in
*C*.

- The file, join_by_crows.c, contains the version of Join_CMatrices_by_Rows() written in
*C*.

- The file, join_by_ccols.c, contains the version of Join_CMatrices_by_Columns() written in
*C*.

*NASM* Source Code

For Linux gcc Users

- The file, join_by_rows.asm, contains the version of Join_Matrices_by_Row() written in
*NASM*.

- The file, join_by_cols.asm, contains the version of Join_Matrices_by_Column() written in
*NASM*.

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

- The file, testjoinbyrows.c, contains a test program of Join_Matrices_by_Rows( ) in the file
*join_by_rows.c*. This test program requires the file*join_by_rows.c*listed above.

- The file, JoinByRowsTest.txt, contains the results of the test program testjoinbyrows.c.

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

- The file, testjoinbycols.c, contains a test program of Join_Matrices_by_Columns( ) in the file
*join_by_cols.c*. This test program requires the file*join_by_cols.c*listed above.

- The file, JoinByColsTest.txt, contains the results of the test program testjoinbycols.c.

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

- The file, testjoinbycrows.c, contains a test program of Join_CMatrices_by_Rows( ) in the file
*join_by_crows.c*. This test program requires the file*join_by_crows.c*listed above.

- The file, JoinByCRowsTest.txt, contains the results of the test program testjoinbycrows.c.

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

- The file, testjoinbyccols.c, contains a test program of Join_CMatrices_by_Columns( ) in the file
*join_by_ccols.c*. This test program requires the file*join_by_ccols.c*listed above.

- The file, JoinByCColsTest.txt, contains the results of the test program testjoinbyccols.c.

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