genVectorScale
in genMath.lib
Vector Functions Function List by Category Alphabetical Functions
int genVectorScale(
float *Vector, // pointer to vector
to scale
int dimen,
// vector dimension
float scalar, //
scale factor
float *ScaledVector) // pointer to store scaled vector
This function multiplies each component of a vector by a scalar:
ScaledVector(i) = c * a(i)
where c is a scalar. This simply makes the vector longer(or shorter), but does not change the direction.
The explicit routines VectorScale2d and VectorScale3d
are faster due to code
optimizations in explicit algorithms..
The return code is errno, defined in the C standard library (math.h). This is an integer value for math errors.
Sample Application:
/////////// splgsca.c for genVectorScale Library Function //////////// // // // // For this sample, a 3-d vector is used. Vector is stored // // in array a, and the result is returned into array b // // // ////////////////////////////////////////////////////////////////////// //////////////////////////// INCLUDES //////////////////////////////// #include "stdio.h" #include "genMath.h" ////////////////////////////// MAIN ////////////////////////////////// void main() { //local declarations //integers int retcode; // return code for call to genVectorScale int i; // counter to display result //floats float a[3]; // vector float b[3]; // result float c; // scalar factor //character strings char ch; // input string to exit //intialize the A and B vectors a[0] = (float)1.234; a[1] = (float)-.678; a[2] = (float)10.3; //scale the vector by 6.2 retcode = genVectorScale(a,3,6.2,b); //display the result printf("%s", "Scaled Vector Components: \n\n");
for(i = 0; i < 3; ++i){
printf("%s%d%s%f%s","b[",i,"] = ",b[i],"\n");
} //display closing message and wait for <enter> before exiting printf("\n\nPress <Enter> to end"); scanf("%c", &ch); } // End Main /////////////////////////////// End splgSca.c ///////////////////////