# Arithmetic Vector Operations

 Home Matrix Home Arithmetic Matrix Routines Home Vector Addition / Subtraction Vector Multiply / Divide by a Scalar Linear Combination of Vectors Multiply Vectors Zero Vector / Basis Vectors

## Multiply / Divide a Vector by a Scalar.

The functionality of vector routines in this collection are routines which could be implemented for vectors (n×1 or 1×n matrices) defined over an arbitrary Abelian group but the implementation presented here is for real vectors declared as double v[N] or for dynamically defined vectors declared as double* v and for complex vectors declared as double complex V[N] or for dynamically defined complex vectors declared as double complex* v.

The function for multiplying a real vector by a real scalar is Multiply_Vector_by_Scalar( ) and the function for multiplying a complex vector by a complex scalar is Multiply_CVector_by_Scalar( ). There are special versions of this routine for the cases of the ubiquitous 2-d and 3-d vectors. There is also a special version of these routines when the scalar is -1 called Reflect_through_the_Origin( ) for a real vector and Reflect_through_the_cOrigin( ) for a complex vector. The function for dividing a real vector by a non-zero scalar is Divide_Vector_by_Scalar( ) and The function for dividing a complex vector by a non-zero complex scalar is Divide_CVector_by_Scalar( ). There are also special versions of this routines for the cases of the ubiquitous 2-d and 3-d vectors.

### Function List

• void Multiply_Vector_by_Scalar( double v[ ], double x, int n )

Multiply the n-dim vector v by the scalar x, i.e. v ← xv.

• void Multiply_2d_Vector_by_Scalar( double v[ ], double x )

Multiply the 2d vector v by the scalar x, v ← xv.

• void Multiply_3d_Vector_by_Scalar( double v[ ], double x )

Multiply the 3d vector v by the scalar x, i.e. v ← xv.

• void Reflect_through_the_Origin( double v[ ], int n)

Multiply the n-dim vector v by the -1, i.e. v ← -v.

• void Reflect_through_the_Origin_2d( double v[ ] )

Multiply the 2d vector v by the -1, i.e. v ← -v.

• void Reflect_through_the_Origin_3d( double v[ ] )

Multiply the 3d vector v by the -1, i.e. v ← -v.

• void Divide_Vector_by_Scalar( double v[ ], double x, int n )

Divide the n-dim vector v by the scalar x, i.e. v ← (1/x)v.

• void Divide_2d_Vector_by_Scalar( double v[ ], double x )

Multiply the 2d vector v by the scalar x, i.e. v ← (1/x)v.

• void Divide_3d_Vector_by_Scalar( double v[ ], double x )

Multiply the 3d vector v by the scalar x, i.e. v ← (1/x)v.

• void Multiply_CVector_by_Scalar( double complex v[ ], double complex x, int n )

Multiply the n-dim complex vector v by the complex scalar x, i.e. v ← xv.

• void Multiply_2d_CVector_by_Scalar( double complex v[ ], double complex x )

Multiply the 2d complex vector v by the complex scalar x, v ← xv.

• void Multiply_3d_CVector_by_Scalar( double complex v[ ], double complex x )

Multiply the 3d complex vector v by the complex scalar x, i.e. v ← xv.

• void Reflect_through_the_cOrigin( double complex v[ ], int n)

Multiply the n-dim complex vector v by the -1, i.e. v ← -v.

• void Reflect_through_the_cOrigin_2d( double complex v[ ] )

Multiply the 2d complex vector v by the -1, i.e. v ← -v.

• void Reflect_through_the_cOrigin_3d( double complex v[ ] )

Multiply the 3d complex vector v by the -1, i.e. v ← -v.

• void Divide_CVector_by_Scalar( double complex v[ ], double complex x, int n )

Divide the n-dim complex vector v by the non-zero complex scalar x, i.e. v ← (1/x)v.

• void Divide_2d_CVector_by_Scalar( double complex v[ ], double complex x )

Multiply the 2d complex vector v by the non-zero complex scalar x, i.e. v ← (1/x)v.

• void Divide_3d_CVector_by_Scalar( double complex v[ ], double complex x )

Multiply the 3d complex vector v by the non-zero complex scalar x, i.e. v ← (1/x)v.

#### C Source Code - Macros

As a rule, the macros presented here are faster and require less memory than either the C version or the NASM version of the corresponding routines. The major draw back is that when calling these macros DO NOT use expressions for the arguments. I.e. do not call MyMacro(&A, n+m) but rather set variables double * pA, int k then set pA = A + 2; k = n+m; and then call the macro MyMacro(pA,k). It would be easy to change the macro to allow such expressions but in general not all versions of C have a typeof "keyword" which would facilitate the changes and moreover make the macro run slower. For C compilers which have the inline keyword, a better alternative would be to make the corresponding C functions inline.
• The file, mul_2d_vector_by_scalar.h, contains the version of Multiply_2d_Vector_by_Scalar( ) written as a macro. This macro is also suitable for multiplying 2-d complex vectors by a real or complex scalar.

• The file, mul_3d_vector_by_scalar.h, contains the version of Multiply_3d_Vector_by_Scalar( ) written as a macro. This macro is also suitable for multiplying 3-d complex vectors by a real or complex scalar.

• The file, reflect_thru_origin_2d.h, contains the version of Reflect_through_the_Origin_2d( ) written as a macro. This macro is also suitable for reflecting 2-d complex vectors through the origin.

• The file, reflect_thru_origin_3d.h, contains the version of Reflect_through_the_Origin_2d( ) written as a macro. This macro is also suitable for reflecting 3-d complex vectors through the origin.

• The file, div_2d_vector_by_scalar.h, contains the version of Divide_2d_Vector_by_Scalar( ) written as a macro.

• The file, div_3d_vector_by_scalar.h, contains the version of Divide_3d_Vector_by_Scalar( ) written as a macro.

• The file, div_2d_cvector_by_scalar.h, contains the version of Divide_2d_CVector_by_Scalar( ) written as a macro.

• The file, div_3d_cvector_by_scalar.h, contains the version of Divide_3d_CVector_by_Scalar( ) written as a macro.

#### C Source Code Tests, Test Results, and Build Shell Scripts

• The file, testmulvectorbyscalar.c, contains a test program of Multiply_Vector_by_Scalar( ) in the file mul_vector_by_scalar.c. This test program requires the file mul_vector_by_scalar.c listed above.

• The file, MultiplyVectorbyScalarTest.txt, contains the results of the test program testmulvectorbyscalar.c.

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

• The file, testmul2dvectorbyscalar.c, contains a test program of Multiply_2d_Vector_by_Scalar( ) in the file mul_2d_vector_by_scalar.c. This test program requires the file mul_2d_vector_by_scalar.c listed above.

• The file, Multiply2dVectorbyScalarTest.txt, contains the results of the test program testmul2dvectorbyscalar.c.

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

• The file, testmul3dvectorbyscalar.c, contains a test program of Multiply_3d_Vector_by_Scalar( ) in the file mul_3d_vector_by_scalar.c. This test program requires the file mul_3d_vector_by_scalar.c listed above.

• The file, Multiply3dVectorbyScalarTest.txt, contains the results of the test program testmul3dvectorbyscalar.c.

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

• The file, testreflectthruorigin.c, contains a test program of Reflect_through_the_Origin( ) in the file reflect_thru_origin.c. This test program requires the file reflect_thru_origin.c listed above.

• The file, ReflectthrutheOriginTest.txt, contains the results of the test program testreflectthruorigin.c.

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

• The file, testreflectthruorigin2d.c, contains a test program of Reflect_through_the_Origin_2d( ) in the file reflect_thru_origin_2d.c. This test program requires the file reflect_thru_origin_2d.c listed above.

• The file, ReflectthrutheOrigin2dTest.txt, contains the results of the test program testreflectthruorigin2d.c.

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

• The file, testreflectthruorigin3d.c, contains a test program of Reflect_through_the_Origin_3d( ) in the file reflect_thru_origin_3d.c. This test program requires the file reflect_thru_origin_3d.c listed above.

• The file, ReflectthrutheOrigin3dTest.txt, contains the results of the test program testreflectthruorigin3d.c.

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

• The file, testdivvectorbyscalar.c, contains a test program of Divide_Vector_by_Scalar( ) in the file div_vector_by_scalar.c. This test program requires the file div_vector_by_scalar.c listed above.

• The file, DivideVectorbyScalarTest.txt, contains the results of the test program testdivvectorbyscalar.c.

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

• The file, testdiv2dvectorbyscalar.c, contains a test program of Divide_2d_Vector_by_Scalar( ) in the file div_2d_vector_by_scalar.c. This test program requires the file div_2d_vector_by_scalar.c listed above.

• The file, Divide2dVectorbyScalarTest.txt, contains the results of the test program testdiv2dvectorbyscalar.c.

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

• The file, testdiv3dvectorbyscalar.c, contains a test program of Divide_3d_Vector_by_Scalar( ) in the file div_3d_vector_by_scalar.c. This test program requires the file div_3d_vector_by_scalar.c listed above.

• The file, Divide3dVectorbyScalarTest.txt, contains the results of the test program testdiv3dvectorbyscalar.c.

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

• The file, testmulcvectorbyscalar.c, contains a test program of Multiply_CVector_by_Scalar( ) in the file mul_cvector_by_scalar.c. This test program requires the file mul_cvector_by_scalar.c listed above.

• The file, MultiplyCVectorbyScalarTest.txt, contains the results of the test program testmulcvectorbyscalar.c.

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

• The file, testmul2dcvectorbyscalar.c, contains a test program of Multiply_2d_CVector_by_Scalar( ) in the file mul_2d_cvector_by_scalar.c. This test program requires the file mul_2d_cvector_by_scalar.c listed above.

• The file, Multiply2dCVectorbyScalarTest.txt, contains the results of the test program testmul2dcvectorbyscalar.c.

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

• The file, testmul3dcvectorbyscalar.c, contains a test program of Multiply_3d_CVector_by_Scalar( ) in the file mul_3d_cvector_by_scalar.c. This test program requires the file mul_3d_cvector_by_scalar.c listed above.

• The file, Multiply3dCVectorbyScalarTest.txt, contains the results of the test program testmul3dcvectorbyscalar.c.

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

• The file, testreflectthrucorigin.c, contains a test program of Reflect_through_the_cOrigin( ) in the file reflect_thru_corigin.c. This test program requires the file reflect_thru_corigin.c listed above.

• The file, ReflectthrutheCOriginTest.txt, contains the results of the test program testreflectthrucorigin.c.

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

• The file, testreflectthrucorigin2d.c, contains a test program of Reflect_through_the_cOrigin_2d( ) in the file reflect_thru_corigin_2d.c. This test program requires the file reflect_thru_corigin_2d.c listed above.

• The file, ReflectthrutheCOrigin2dTest.txt, contains the results of the test program testreflectthrucorigin2d.c.

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

• The file, testreflectthrucorigin3d.c, contains a test program of Reflect_through_the_cOrigin_3d( ) in the file reflect_thru_corigin_3d.c. This test program requires the file reflect_thru_corigin_3d.c listed above.

• The file, ReflectthrutheCOrigin3dTest.txt, contains the results of the test program testreflectthrucorigin3d.c.

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

• The file, testdivcvectorbyscalar.c, contains a test program of Divide_CVector_by_Scalar( ) in the file div_cvector_by_scalar.c. This test program requires the file div_cvector_by_scalar.c listed above.

• The file, DivideCVectorbyScalarTest.txt, contains the results of the test program testdivcvectorbyscalar.c.

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

• The file, testdiv2dcvectorbyscalar.c, contains a test program of Divide_2d_CVector_by_Scalar( ) in the file div_2d_cvector_by_scalar.c. This test program requires the file div_2d_cvector_by_scalar.c listed above.

• The file, Divide2dCVectorbyScalarTest.txt, contains the results of the test program testdiv2dcvectorbyscalar.c.

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

• The file, testdiv3dcvectorbyscalar.c, contains a test program of Divide_3d_CVector_by_Scalar( ) in the file div_3d_cvector_by_scalar.c. This test program requires the file div_3d_cvector_by_scalar.c listed above.

• The file, Divide3dCVectorbyScalarTest.txt, contains the results of the test program testdiv3dcvectorbyscalar.c.

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

#### C Macros Tests, Test Results, and Build Shell Scripts

• The file, testmul2dvectorbyscalar_h.c, contains a test program of the macro Multiply_2d_Vector_by_Scalar( ) in the file mul_2d_vector_by_scalar.h. This test program requires the file mul_2d_vector_by_scalar.h listed above.

• The file, Multiply2dVectorbyScalar_hTest.txt, contains the results of the test program testmul2dvectorbyscalar_h.c.

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

• The file, testmul3dvectorbyscalar_h.c, contains a test program of the macro Multiply_3d_Vector_by_Scalar( ) in the file mul_3d_vector_by_scalar.h. This test program requires the file mul_3d_vector_by_scalar.h listed above.

• The file, Multiply3dVectorbyScalar_hTest.txt, contains the results of the test program testmul3dvectorbyscalar_h.c.

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

• The file, testreflectthruorigin2d_h.c, contains a test program of the macro Reflect_through_the_Origin_2d( ) in the file reflect_thru_origin_2d.h. This test program requires the file reflect_thru_origin_2d.h listed above.

• The file, ReflectthrutheOrigin2d_hTest.txt, contains the results of the test program testreflectthruorigin2d_h.c.

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

• The file, testreflectthruorigin3d_h.c, contains a test program of the macro Reflect_through_the_Origin_3d( ) in the file reflect_thru_origin_3d.h. This test program requires the file reflect_thru_origin_3d.h listed above.

• The file, ReflectthrutheOrigin3d_hTest.txt, contains the results of the test program testreflectthruorigin3d_h.c.

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

• The file, testdiv2dvectorbyscalar_h.c, contains a test program of the macro Divide_2d_Vector_by_Scalar( ) in the file div_2d_vector_by_scalar.h. This test program requires the file div_2d_vector_by_scalar.h listed above.

• The file, Divide2dVectorbyScalar_hTest.txt, contains the results of the test program testdiv2dvectorbyscalar_h.c.

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

• The file, testdiv3dvectorbyscalar_h.c, contains a test program of the macro Divide_3d_Vector_by_Scalar( ) in the file div_3d_vector_by_scalar.h. This test program requires the file div_3d_vector_by_scalar.h listed above.

• The file, Divide3dVectorbyScalar_hTest.txt, contains the results of the test program testdiv3dvectorbyscalar_h.c.

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

• The file, testmul2dcvectorbyscalar_h.c, contains a test program of the macro Multiply_2d_Vector_by_Scalar( ) in the file mul_2d_vector_by_scalar.h for the case in which the arguments are the same as in mul_2d_cvector_by_scalar.c. This test program requires the file mul_2d_vector_by_scalar.h listed above.

• The file, Multiply2dCVectorbyScalar_hTest.txt, contains the results of the test program testmul2dcvectorbyscalar_h.c.

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

• The file, testmul3dcvectorbyscalar_h.c, contains a test program of the macro Multiply_3d_Vector_by_Scalar( ) in the file mul_3d_vector_by_scalar.h for the case in which the arguments are the same as in mul_3d_cvector_by_scalar.c. This test program requires the file mul_3d_vector_by_scalar.h listed above.

• The file, Multiply3dCVectorbyScalar_hTest.txt, contains the results of the test program testmul3dcvectorbyscalar_h.c.

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

• The file, testreflectthrucorigin2d_h.c, contains a test program of the macro Reflect_through_the_Origin_2d( ) in the file reflect_thru_origin_2d.h for the case in which the arguments are the same as in reflect_thru_corigin_2d.c. This test program requires the file reflect_thru_origin_2d.h listed above.

• The file, ReflectthrutheCOrigin2d_hTest.txt, contains the results of the test program testreflectthrucorigin2d_h.c.

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

• The file, testreflectthruorigin3d_h.c, contains a test program of the macro Reflect_through_the_Origin_3d( ) in the file reflect_thru_origin_3d.h for the case in which the arguments are the same as in reflect_thru_corigin_3d.c. This test program requires the file reflect_thru_origin_3d.h listed above.

• The file, ReflectthrutheOrigin3d_hTest.txt, contains the results of the test program testreflectthruorigin3d_h.c.

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

• The file, testdiv2dcvectorbyscalar_h.c, contains a test program of the macro Divide_2d_CVector_by_Scalar( ) in the file div_2d_cvector_by_scalar.h. This test program requires the file div_2d_cvector_by_scalar.h listed above.

• The file, Divide2dCVectorbyScalar_hTest.txt, contains the results of the test program testdiv2dcvectorbyscalar_h.c.

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

• The file, testdiv3dcvectorbyscalar_h.c, contains a test program of the macro Divide_3d_CVector_by_Scalar( ) in the file div_3d_cvector_by_scalar.h. This test program requires the file div_3d_cvector_by_scalar.h listed above.

• The file, Divide3dCVectorbyScalar_hTest.txt, contains the results of the test program testdiv3dcvectorbyscalar_h.c.

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