## Set Matrix Diagonal Elements to a Scalar.

Given an*m*×

*n*matrix

**A**= (

*a*) the diagonal of

_{ij}**A**is the collection of matrix elements

(

*a*),

_{ii}*i = 0, … , min(m,n)*.

The function which sets each diagonal element of a real matrix of type

*double*to a user-specified scalar is called

*Set_Diagonal_to_Scalar()*and the function which sets each diagonal element of a complex matrix of type

*double complex*to a user-specified complex scalar is called

*Set_CDiagonal_to_Scalar()*.

There are 2 versions of the

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

*C*and 1 version is written in

*NASM*assembly language.

There is 1 version of the

*Set_CDiagonal_to_Scalar()*routine.

### Function List

- void Set_Diagonal_to_Scalar( double *A, double x, int nrows, int ncols )

Given the scalar*x*, this routine sets each diagonal element of the*nrows x ncols*matrix*A*to*x*, i.e.*A[i][i]=x*. The destination matrix*A*should be dimensioned in the calling routine as*nrows x ncols*.

- void Set_CDiagonal_to_Scalar( double complex *A, double complex x, int nrows, int ncols )

Given the complex scalar*x*, this routine sets each diagonal element of the*nrows x ncols*complex matrix*A*to*x*, i.e.*A[i][i]=x*. The destination matrix*A*should be dimensioned in the calling routine as*nrows x ncols*.

*C* Source Code

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

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

*NASM* Source Code

For Linux gcc Users

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

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

- The file, testsetdiagonaltoscalar.c, contains a test program of Set_Diagonal_to_Scalar( ) in the file
*set_diagonal_to_scalar.c*. This test program requires the file*set_diagonal_to_scalar.c*listed above.

- The file, SetDiagonalToScalarTest.txt, contains the results of the test program testsetdiagonaltoscalar.c.

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

- The file, testsetcdiagonaltoscalar.c, contains a test program of Set_CDiagonal_to_Scalar( ) in the file
*set_cdiagonal_to_scalar.c*. This test program requires the file*set_cdiagonal_to_scalar.c*listed above.

- The file, SetCDiagonalToScalarTest.txt, contains the results of the test program testsetcdiagonaltoscalar.c.

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