## Linear Combinations.

A linear combination of the vectors**, ...,**

*v*_{1}**is the vector**

*v*_{m}**=**

*v**a*+ ··· +

_{1}**v**_{1}*a*where

_{m}**v**_{m}*a*, ...,

_{1}*a*are scalars. The routine which calculates the linear combination of a finite number of real vectors is called

_{m}*Linear_Combination( )*and the routine which calculates the linear combination of a finite number of complex vectors is called

*cLinear_Combination( )*. Another routine which adds a linear combination of a finite number of real vectors to a fixed real vector is called

*Add_Linear_Combination_to( )*and the routine which adds a linear combination of a finite number of complex vectors to a fixed complex vector is called

*Add_cLinear_Combination_to( )*. Special versions of routines of linear combinations of the form

**v**=

**w**+

*s*

**d**, where

**v**,

**w**,

**d**are vectors with the same dimension and

*s*is a scalar are also presented are called

*Ray_in_n_Space()*for the real case and

*Ray_in_n_CSpace()*for the complex case. There are special versions of these two routines for the

*2*and

*3*dimensional cases. Note that if

**d**has unit norm, and

*s*> 0, then

**v**lies on the ray originating from

**w**in the direction

**d**at a distance

*s*from

**w**and if

*s*< 0, then

**v**lies on the ray originating from

**w**in the direction opposite to

**d**at a distance

*-s*from

**w**.

### Function List

- void Linear_Combination( double v[ ], int n, int number_of_summands, ... )

This routine calculates the*n*-dimensional vector*v = s1*v1 + ··· + sm*vm*, where*m*is the*number_of_summands*. The arguments in the ellipsis (...) are the pairs*si*and*vi*where*si*is a scalar, of type double, and*vi*is an array, of type double[n].

Note that the vector*v*is initially initialized to 0.0, and therefore there is no reason to include it in one of the summands as it will be annihilated before used. If you wish to add a linear combination of vectors to*v*, then see Add_Linear_Combination_to below.

NOTE: Make sure that the arguments in the ellipsis are of the correct type, i.e. that all of the scalars are of type*double*and all of the vectors are of type*double [n]*.*C*cannot promote these arguments to the type expected, i.e. do not use*2*for a scalar but rather*2.0*.

- void Add_Linear_Combination_to( double v[ ], int n, int number_of_summands, ... )

This routine calculates the*n*-dimensional vector*v ← v + s1*v1 + ··· + sm*vm*, where*m*is the*number_of_summands*. The arguments in the ellipsis (...) are the pairs*si*and*vi*where*si*is a scalar, of type double, and*vi*is an array, of type double[n].

NOTE: Make sure that the arguments in the ellipsis are of the correct type, i.e. that all of the scalars are of type*double*and all of the vectors are of type*double [n]*.*C*cannot promote these arguments to the type expected, i.e. do not use*2*for a scalar but rather*2.0*.

- void Ray_in_n_Space( double v[ ], double initial_pt[ ], double direction[ ], double distance, int n )

This routine calculates the*n*-dimensional vector*v = initial_pt + distance * direction*. All vectors,*v*,*initial_pt*, and*direction*, should be declared in the calling routine as*double [n]*.

- void Ray_in_2_Space( double v[ ], double initial_pt[ ], double direction[ ], double distance )

This routine calculates the*2*-dimensional vector*v = initial_pt + distance * direction*. All vectors,*v*,*initial_pt*, and*direction*, should be declared in the calling routine as*double [2]*.

- void Ray_in_3_Space( double v[ ], double initial_pt[ ], double direction[ ], double distance)

This routine calculates the*3*-dimensional vector*v = initial_pt + distance * direction*. All vectors,*v*,*initial_pt*, and*direction*, should be declared in the calling routine as*double [3]*.

- void cLinear_Combination( double complex v[ ], int n, int number_of_summands, ... )

This routine calculates the*n*-dimensional vector*v = s1*v1 + ··· + sm*vm*, where*m*is the*number_of_summands*. The arguments in the ellipsis (...) are the pairs*si*and*vi*where*si*is a scalar, of type double complex, and*vi*is an array, of type double complex [n].

Note that the vector*v*is initially initialized to 0.0, and therefore there is no reason to include it in one of the summands as it will be annihilated before used. If you wish to add a linear combination of vectors to*v*, then see Add_cLinear_Combination_to below.

NOTE: Make sure that the arguments in the ellipsis are of the correct type, i.e. that all of the scalars are of type*double complex*and all of the vectors are of type*double complex [n]*.*C*cannot promote these arguments to the type expected, i.e. do not use*2*or*2.0*for a scalar but rather*2.0 + 0.0*I*.

- void Add_cLinear_Combination_to( double complex v[ ], int n, int number_of_summands, ... )

This routine calculates the*n*-dimensional vector*v ← v + s1*v1 + ··· + sm*vm*, where*m*is the*number_of_summands*. The arguments in the ellipsis (...) are the pairs*si*and*vi*where*si*is a scalar, of type double complex, and*vi*is an array, of type double complex[n].

NOTE: Make sure that the arguments in the ellipsis are of the correct type, i.e. that all of the scalars are of type*double*and all of the vectors are of type*double [n]*.*C*cannot promote these arguments to the type expected, i.e. do not use*2*or*2.0*for a scalar but rather*2.0 + 0.0*I*.

- void Ray_in_n_CSpace( double complex v[ ], double complex initial_pt[ ], double complex direction[ ], double distance, int n )

This routine calculates the*n*-dimensional complex vector*v = initial_pt + distance * direction*. All vectors,*v*,*initial_pt*, and*direction*, should be declared in the calling routine as*double complex [n]*.

- void Ray_in_2_CSpace( double complex v[ ], double complex initial_pt[ ], double complex direction[ ], double distance )

This routine calculates the*2*-dimensional complex vector*v = initial_pt + distance * direction*. All vectors,*v*,*initial_pt*, and*direction*, should be declared in the calling routine as*double complex [2]*.

- void Ray_in_3_CSpace( double complex v[ ], double complex initial_pt[ ], double complex direction[ ], double distance)

This routine calculates the*3*-dimensional complex vector*v = initial_pt + distance * direction*. All vectors,*v*,*initial_pt*, and*direction*, should be declared in the calling routine as*double complex [3]*.

*C* Source Code

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

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

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

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

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

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

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

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

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

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

*NASM* Source Code

For Linux gcc Users

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

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

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

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

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

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

- The file, testlinearcomb.c, contains a test program of Linear_Combination( ). This test program requires the file
*linear_combination.c*listed above.

- The file, LinearCombinationTest.txt, contains the results of the test program testlinearcomb.c.

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

- The file, testaddlinearcombto.c, contains a test program of Add_Linear_Combination_to( ). This test program requires the file
*add_linear_combination_to.c*listed above.

- The file, AddLinearCombinationToTest.txt, contains the results of the test program testaddlinearcombto.c.

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

- The file, testraynspace.c, contains a test program of Ray_in_n_Space( ). This test program requires the file
*ray_in_n_space.c*listed above.

- The file, RayInnSpaceTest.txt, contains the results of the test program testraynspace.c.

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

- The file, testray2space.c, contains a test program of Ray_in_2_Space( ). This test program requires the file
*ray_in_2_space.c*listed above.

- The file, RayIn2SpaceTest.txt, contains the results of the test program testray2space.c.

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

- The file, testray3space.c, contains a test program of Ray_in_3_Space( ). This test program requires the file
*ray_in_3_space.c*listed above.

- The file, RayIn3SpaceTest.txt, contains the results of the test program testray3space.c.

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

- The file, testclinearcomb.c, contains a test program of cLinear_Combination( ). This test program requires the file
*clinear_combination.c*listed above.

- The file, CLinearCombinationTest.txt, contains the results of the test program testclinearcomb.c.

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

- The file, testaddclinearcombto.c, contains a test program of Add_cLinear_Combination_to( ). This test program requires the file
*add_clinear_combination_to.c*listed above.

- The file, AddCLinearCombinationToTest.txt, contains the results of the test program testaddclinearcombto.c.

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

- The file, testrayncspace.c, contains a test program of Ray_in_n_CSpace( ). This test program requires the file
*ray_in_n_space.c*listed above.

- The file, RayInnCSpaceTest.txt, contains the results of the test program testrayncspace.c.

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

- The file, testray2cspace.c, contains a test program of Ray_in_2_CSpace( ). This test program requires the file
*ray_in_2_cspace.c*listed above.

- The file, RayIn2CSpaceTest.txt, contains the results of the test program testray2cspace.c.

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

- The file, testray3cspace.c, contains a test program of Ray_in_3_CSpace( ). This test program requires the file
*ray_in_3_cspace.c*listed above.

- The file, RayIn3CSpaceTest.txt, contains the results of the test program testray3cspace.c.

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