genVectorLength
in genMath.lib

Vector Functions            Function List by Category            Alphabetical Function List

Sample Code

int genVectorLength(
                                        float *Vector,          // pointer to array holding vector A
                                        int dimen,                // dimension of vector
                                        float *Length)        // pointer to store result

This function computes the length of a vector of dimension n.  The function 'assumes'
that one end of the vector is at the origin.  If you need to compute the length of a 
more general vector, pass the coordinate differences to the function (such as x1 - x2,
y1-y2):

Length = sqrt{ sum{ a[i]^2 } }

The explicit routines VectorLength2d and VectorLength3d 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:
/////////// splgnLen.c for genVectorLength Library Function //////////
//								    //																//
//	For this sample, a 3-d vector is used.  The vector is       //
//	stored in array a, and the length is returned into	    //
//	c.							    //
//								    //
//////////////////////////////////////////////////////////////////////

//////////////////////////// INCLUDES ////////////////////////////////

#include "stdio.h"
#include "genMath.h"

////////////////////////////// MAIN //////////////////////////////////
void main()
{

	//local declarations
	//integers
	int retcode;		// return code for call to genVectorLength

	//floats
	float a[3];		// vector
	float c;		// Length of vector

	//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;

	//compute the length
	retcode = genVectorLength(a,3,&c);
	
	//display the result
	printf("%s%f%s", "Vector Length = ", c,"\n\n");
	
	//display closing message and wait for <enter> before exiting
	printf("Press <Enter> to end");
	scanf("%c", &ch);

} // End Main

/////////////////////////////// End splgnLen.c ///////////////////////
The reader may compute the length of A and compare
to the output of the sample program.
Output from the test program splgnLen.c: 
Vector Length = 10.395789