# Arithmetic Matrix Operations

 Home Matrix Home Arithmetic Matrix Routines Home Matrix Addition / Subtraction Matrix Diagonal Add / Subract Scalar Matrix Multiply / Divide by Scalar Matrix Multiplication ATB, ABT, ATA, AAT [A,B] and {A, B} Row / Column Transform Row Sum / Column Sum / Trace Zero Matrix / Identity Matrix Direct Sum Bilinear Function / Kronecker

## Zero Matrix and Identity Matrix.

It is convenient to have routines to initialize a matrix either to a zero matrix or the identity matrix.

The function for setting a real matrix to the zero matrix is Zero_Matrix( ) and the function for setting a complex matrix to the zero matrix is Zero_CMatrix( ). The function for setting a square n×n real matrix to the identity matrix is Identity_Matrix( ) and the function or setting a square n×n complex matrix to the identity matrix is Identity_CMatrix( ). There are also special routines for setting a matrix to a identity matrix stored in upper triangular form or lower triangular form.

### Function List

• void Zero_Matrix( double *A, int nrows, int ncols )

Set the nrows×ncols matrix A to the zero matrix, i.e. A[i] [j] = 0 for all i, j.

• void Identity_Matrix( double *A, int n )

Set the square n×n matrix A to the identity matrix, i.e. A[i][j] = 0 if i ≠ j and A[i][i] = 1 otherwise.

• void Identity_Matrix_ut( double *A, int n )

Set the square n×n matrix A stored in upper triangular form to the identity matrix. The array A must be declared at least n (n+1) / 2 in the calling routine.

• void Identity_Matrix_lt( double *A, int n )

Set the square n×n matrix A stored in lower triangular form to the identity matrix. The array A must be declared at least n (n+1) / 2 in the calling routine.

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

Set the nrows×ncols complex matrix A to the zero matrix, i.e. A[i] [j] = 0+0i for all i, j.

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

Set the square n×n complex matrix A to the identity matrix, i.e. A[i][j] = 0+0i if i ≠ j and A[i][i] = 1+0i otherwise.

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

Set the square n×n complex matrix A stored in upper triangular form to the identity matrix. The array A must be declared at least n (n+1) / 2 in the calling routine.

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

Set the square n×n complex matrix A stored in lower triangular form to the identity matrix. The array A must be declared at least n (n+1) / 2 in the calling routine.

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

• The file, testzeromatrix_C.c, contains a test program of Zero_Matrix( ). This test program requires the file zero_matrix.c listed above.

• The file, ZeroMatrix_CTest.txt, contains the results of the test program testzeromatrix_C.c.

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

• The file, testidentity_C.c, contains a test program of Identity_Matrix( ). This test program requires the file identity_matrix.c listed above.

• The file, IdentityMatrixTests_C.txt, contains the results of the test program testidentity_C.c.

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

• The file, testidentity_ut_C.c, contains a test program of Identity_Matrix_ut( ). This test program requires the file identity_matrix_ut.c listed above.

• The file, IdentityMatrixUTTests_C.txt, contains the results of the test program testidentity_ut_C.c.

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

• The file, testidentity_lt_C.c, contains a test program of Identity_Matrix_lt( ). This test program requires the file identity_matrix_lt.c listed above.

• The file, IdentityMatrixLTTests_C.txt, contains the results of the test program testidentity_lt_C.c.

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

• The file, testzerocmatrix.c, contains a test program of Zero_CMatrix( ). This test program requires the file zero_cmatrix.c listed above.

• The file, ZeroCMatrixTest.txt, contains the results of the test program ttestzerocmatrix.c.

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

• The file, testidentitycmatrix.c, contains a test program of Identity_CMatrix( ). This test program requires the file identity_cmatrix.c listed above.

• The file, IdentityCMatrixTests.txt, contains the results of the test program testidentitycmatrix.c.

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

• The file, testidentitycmatrixut.c, contains a test program of Identity_CMatrix_ut( ). This test program requires the file identity_cmatrix_ut.c listed above.

• The file, IdentityCMatrixUTTests.txt, contains the results of the test program testidentitycmatrixut.c.

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

• The file, testidentitycmatrixlt.c, contains a test program of Identity_CMatrix_lt( ). This test program requires the file identity_cmatrix_lt.c listed above.

• The file, IdentityCMatrixLTTests.txt, contains the results of the test program testidentitycmatrixlt.c.

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

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

• The file, testzeromatrix_A.c, contains a test program of Zero_Matrix( ). This test program requires the file zero_matrix.asm listed above.

• The file, ZeroMatrix_ATest.txt, contains the results of the test program testzeromatrix_A.c.

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

• The file, testidentity_A.c, contains a test program of Identity_Matrix( ). This test program requires the file identity_matrix.asm listed above.

• The file, IdentityMatrixTests_A.txt, contains the results of the test program testidentity_A.c.

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

• The file, testidentity_ut_A.c, contains a test program of Identity_Matrix_ut( ). This test program requires the file identity_matrix_ut.asm listed above.

• The file, IdentityMatrixUTTests_A.txt, contains the results of the test program testidentity_ut_A.c.

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

• The file, testidentity_lt_A.c, contains a test program of Identity_Matrix_lt( ). This test program requires the file identity_matrix_lt.asm listed above.

• The file, IdentityMatrixLTTests_A.txt, contains the results of the test program testidentity_lt_A.c.

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

#### Timing For Zero_MatrixNumber of Clock Cycles

 Routine 3 × 4Matrix zero_matrix.c 105 zero_matrix.asm 38

#### Timing For Identity_MatrixNumber of Clock Cycles

 Routine 3 × 3Matrix identity_matrix.c 66 identity_matrix.asm 28

#### Timing For Identity_Matrix_utNumber of Clock Cycles

 Routine 2 × 2Matrix 3 × 3Matrix 4 × 4Matrix identity_matrix_ut.c 19 47 85 identity_matrix_ut.asm 0* 19 38
*Time within time variation of calling time stamp.

#### Timing For Identity_Matrix_ltNumber of Clock Cycles

 Routine 2 × 2Matrix 3 × 3Matrix 4 × 4Matrix identity_matrix_lt.c 19 47 85 identity_matrix_lt.asm 0* 19 38
*Time within time variation of calling time stamp.