Arithmetic Matrix Operations



Matrix Multiply / Divide by Scalar

Multiply / Divide a Matrix by a Scalar.

The functionality of matrix routines in this collection are routines which could be implemented for matrices defined over an arbitrary field but the implementation presented here is for real matrices declared as double A[M][N] or for dynamically defined matrices declared as double* A and for complex matrices declared as double complex A[M][N] or for dynamically defined complex matrices declared as double complex *A.

The function for multiplying a matrix by a scalar is Multiply_Matrix_by_Scalar( ) and the function for multiplying a complex matrices by a scalar is Multiply_CMatrix_by_Scalar( ). There are special versions of these routines for the cases of the ubiquitous 2×2 and 3×3 matrices. The function for dividing a matrix by a non-zero scalar is Divide_Matrix_by_Scalar( ) and the function for dividing a complex matrix by a non-zero scalar is Divide_CMatrix_by_Scalar( ). There are also special versions of these routines for the cases of the ubiquitous 2×2 and 3×3 matrices.

There are 2 versions for both Multiply_Matrix_by_Scalar( ) and
Divide_Matrix_by_Scalar( ), 1 version is written in C and 1 version written in NASM. There is 1 version for both for both Multiply_CMatrix_by_Scalar( ) and
Divide_CMatrix_by_Scalar( ) both written in C. For the special 2×2 and 3×3 cases there is an additional version which is written as a macro.

Function List

  • void Multiply_Matrix_by_Scalar( double *A, double x, int nrows, int ncols)

    Multiply the nrows × ncols matrix A by the scalar x, i.e. A ← xA.

  • void Multiply_2x2_Matrix_by_Scalar( double *A, double x )

    Multiply the 2×2 matrix A by the scalar x, i.e. A ← xA.

  • void Multiply_3x3_Matrix_by_Scalar( double *A, double x )

    Multiply the 3 × 3 matrix A by the scalar x, i.e. A ← xA.

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

    Multiply the nrows × ncols complex matrix A by the scalar x, i.e. A ← xA.

  • void Multiply_2x2_CMatrix_by_Scalar( double complex *A, double complex x )

    Multiply the 2×2 complex matrix A by the scalar x, i.e. A ← xA.

  • void Multiply_3x3_CMatrix_by_Scalar( double complex *A, double complex x )

    Multiply the 3 × 3 complex matrix A by the scalar x, i.e. A ← xA.

  • void Divide_Matrix_by_Scalar( double *A, double x, int nrows, int ncols)

    Divide the nrows × ncols matrix A by the non-zero scalar x, i.e. A ← (1/x)A.

  • void Divide_2x2_Matrix_by_Scalar( double *A, double x )

    Multiply the 2×2 matrix A by the non-zero scalar x, i.e. A ← (1/x)A.

  • void Divide_3x3_Matrix_by_Scalar( double *A, double x )

    Multiply the 3×3 matrix A by the non-zero scalar x, i.e. A ← (1/x)A.

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

    Divide the nrows × ncols complex matrix A by the non-zero scalar x, i.e. A ← (1/x)A.

  • void Divide_2x2_CMatrix_by_Scalar( double complex *A, double complex x )

    Multiply the 2×2 complex matrix A by the non-zero scalar x, i.e. A ← (1/x)A.

  • void Divide_3x3_CMatrix_by_Scalar( double complex *A, double complex x )

    Multiply the 3×3 complex matrix A by the non-zero scalar x, i.e. A ← (1/x)A.

C Source Code

NASM Source Code
For Linux gcc Users


C Test Code, Test Results, and Build Shell Script

  • The file, testmulmatrixbyscalar.c, contains a test program of Multiply_Matrix_by_Scalar( ) in the file mul_matrix_by_scalar.c. This test program requires the file mul_matrix_by_scalar.c listed above.

  • The file, MulMatrixByScalarTest.txt, contains the results of the test program testmulmatrixbyscalar.c.

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


  • The file, testmul2x2matrixbyscalar.c, contains a test program of Multiply_2x2_Matrix_by_Scalar( ) in the file mul_2x2_matrix_by_scalar.c. This test program requires the file mul_2x2_matrix_by_scalar.c listed above.

  • The file, Mul2x2MatrixByScalarTest.txt, contains the results of the test program testmul2x2matrixbyscalar.c.

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


  • The file, testmul2x2matrixbyscalar_h.c, contains a test program of Multiply_2x2_Matrix_by_Scalar( ) in the file mul_2x2_matrix_by_scalar.h. This test program requires the file mul_2x2_matrix_by_scalar.h listed above.

  • The file, Mul2x2MatrixByScalar_hTest.txt, contains the results of the test program testmul2x2matrixbyscalar_h.c.

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


  • The file, testmul3x3matrixbyscalar.c, contains a test program of Multiply_3x3_Matrix_by_Scalar( ) in the file mul_3x3_matrix_by_scalar.c. This test program requires the file mul_3x3_matrix_by_scalar.c listed above.

  • The file, Mul3x3MatrixByScalarTest.txt, contains the results of the test program testmul3x3matrixbyscalar.c.

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


  • The file, testmul3x3matrixbyscalar_h.c, contains a test program of Multiply_3x3_Matrix_by_Scalar( ) in the file mul_3x3_matrix_by_scalar.h. This test program requires the file mul_3x3_matrix_by_scalar.h listed above.

  • The file, Mul3x3MatrixByScalar_hTest.txt, contains the results of the test program testmul3x3matrixbyscalar_h.c.

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


  • The file, testmulcmatrixbyscalar.c, contains a test program of Multiply_CMatrix_by_Scalar( ) in the file mul_cmatrix_by_scalar.c. This test program requires the file mul_cmatrix_by_scalar.c listed above.

  • The file, MulCMatrixByScalarTest.txt, contains the results of the test program testmulcmatrixbyscalar.c.

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


  • The file, testmul2x2cmatrixbyscalar.c, contains a test program of Multiply_2x2_CMatrix_by_Scalar( ) in the file mul_2x2_cmatrix_by_scalar.c. This test program requires the file mul_2x2_cmatrix_by_scalar.c listed above.

  • The file, Mul2x2CMatrixByScalarTest.txt, contains the results of the test program testmul2x2cmatrixbyscalar.c.

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


  • The file, testmul2x2cmatrixbyscalarh.c, contains a test program of Multiply_2x2_CMatrix_by_Scalar( ) in the file mul_2x2_cmatrix_by_scalar.h. This test program requires the file mul_2x2_cmatrix_by_scalar.h listed above.

  • The file, Mul2x2CMatrixByScalar_hTest.txt, contains the results of the test program testmul2x2cmatrixbyscalarh.c.

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


  • The file, testmul3x3cmatrixbyscalar.c, contains a test program of Multiply_3x3_CMatrix_by_Scalar( ) in the file mul_3x3_cmatrix_by_scalar.c. This test program requires the file mul_3x3_cmatrix_by_scalar.c listed above.

  • The file, Mul3x3CMatrixByScalarTest.txt, contains the results of the test program testmul3x3cmatrixbyscalar.c.

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


  • The file, testmul3x3cmatrixbyscalarh.c, contains a test program of Multiply_3x3_CMatrix_by_Scalar( ) in the file mul_3x3_cmatrix_by_scalar.h. This test program requires the file mul_3x3_cmatrix_by_scalar.h listed above.

  • The file, Mul3x3CMatrixByScalar_hTest.txt, contains the results of the test program testmul3x3cmatrixbyscalarh.c.

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


  • The file, testdivmatrixbyscalar.c, contains a test program of
    Divide_Matrix_by_Scalar( ) in the file div_matrix_by_scalar.c. This test program requires the file div_matrix_by_scalar.c listed above.

  • The file, DivMatrixByScalarTest.txt, contains the results of the test program testdivmatrixbyscalar.c.

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


  • The file, testdiv2x2matrixbyscalar.c, contains a test program of Divide_2x2_Matrix_by_Scalar( ) in the file div_2x2_matrix_by_scalar.c. This test program requires the file div_2x2_matrix_by_scalar.c listed above.

  • The file, Div2x2MatrixByScalarTest.txt, contains the results of the test program testdiv2x2matrixbyscalar.c.

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


  • The file, testdiv2x2matrixbyscalar_h.c, contains a test program of Divide_2x2_Matrix_by_Scalar( ) in the file div_2x2_matrix_by_scalar.h. This test program requires the file div_2x2_matrix_by_scalar.h listed above.

  • The file, Div2x2MatrixByScalar_hTest.txt, contains the results of the test program testdiv2x2matrixbyscalar_h.c.

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


  • The file, testdiv3x3matrixbyscalar.c, contains a test program of Divide_3x3_Matrix_by_Scalar( ) in the file div_3x3_matrix_by_scalar.c. This test program requires the file div_3x3_matrix_by_scalar.c listed above.

  • The file, Div3x3MatrixByScalarTest.txt, contains the results of the test program testdiv3x3matrixbyscalar.c.

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


  • The file, testdiv3x3matrixbyscalar_h.c, contains a test program of Divide_3x3_Matrix_by_Scalar( ) in the file div_3x3_matrix_by_scalar.h. This test program requires the file div_3x3_matrix_by_scalar.h listed above.

  • The file, Div3x3MatrixByScalar_hTest.txt, contains the results of the test program testdiv3x3matrixbyscalar_h.c.

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


  • The file, testdivcmatrixbyscalar.c, contains a test program of
    Divide_CMatrix_by_Scalar( ) in the file div_cmatrix_by_scalar.c. This test program requires the file div_cmatrix_by_scalar.c listed above.

  • The file, DivCMatrixByScalarTest.txt, contains the results of the test program testdivcmatrixbyscalar.c.

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


  • The file, testdiv2x2cmatrixbyscalar.c, contains a test program of Divide_2x2_CMatrix_by_Scalar( ) in the file div_2x2_cmatrix_by_scalar.c. This test program requires the file div_2x2_cmatrix_by_scalar.c listed above.

  • The file, Div2x2CMatrixByScalarTest.txt, contains the results of the test program testdiv2x2cmatrixbyscalar.c.

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


  • The file, testdiv2x2cmatrixbyscalarh.c, contains a test program of Divide_2x2_CMatrix_by_Scalar( ) in the file div_2x2_cmatrix_by_scalar.h. This test program requires the file div_2x2_cmatrix_by_scalar.h listed above.

  • The file, Div2x2CMatrixByScalar_hTest.txt, contains the results of the test program testdiv2x2cmatrixbyscalarh.c.

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


  • The file, testdiv3x3cmatrixbyscalar.c, contains a test program of Divide_3x3_CMatrix_by_Scalar( ) in the file div_3x3_cmatrix_by_scalar.c. This test program requires the file div_3x3_cmatrix_by_scalar.c listed above.

  • The file, Div3x3CMatrixByScalarTest.txt, contains the results of the test program testdiv3x3cmatrixbyscalar.c.

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


  • The file, testdiv3x3cmatrixbyscalarh.c, contains a test program of Divide_3x3_CMatrix_by_Scalar( ) in the file div_3x3_cmatrix_by_scalar.h. This test program requires the file div_3x3_cmatrix_by_scalar.h listed above.

  • The file, Div3x3CMatrixByScalar_hTest.txt, contains the results of the test program testdiv3x3cmatrixbyscalarh.c.

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