Table of Contents

NAME

QccVectorAlloc, QccVectorFree, QccVectorZero, QccVectorResize, QccVectorMean, QccVectorVariance, QccVectorAdd, QccVectorSubtract, QccVectorScalarMult, QccVectorCopy, QccVectorNorm, QccVectorNormalize, QccVectorDotProduct, QccVectorAngle, QccVectorSquareDistance, QccVectorSumComponents, QccVectorMaxValue, QccVectorMinValue, QccVectorPrint - miscellaneous vector routines

SYNOPSIS

#include "libQccPack.h"

QccVector QccVectorAlloc(int vector_dimension);

void QccVectorFree(QccVector vector);

int QccVectorZero(QccVector vector, int vector_dimension);

QccVector QccVectorResize(QccVector vector, int vector_dimension, int new_vector_dimension);

double QccVectorMean(const QccVector vector, int vector_dimension);

double QccVectorVariance(const QccVector vector, int vector_dimension);

int QccVectorAdd(QccVector vector1, const QccVector vector2, int vector_dimension);

int QccVectorSubtract(QccVector vector1, const QccVector vector2, int vector_dimension);

int QccVectorScalarMult(QccVector vector, double s, int vector_dimension);

int QccVectorCopy(QccVector vector1, const QccVector vector2, int vector_dimension);

double QccVectorNorm(const QccVector vector, int vector_dimension);

double QccVectorNormalize(QccVector vector, int vector_dimension);

double QccVectorDotProduct(const QccVector vector1, const QccVector vector2, int vector_dimension);

double QccVectorAngle(const QccVector vector1, const QccVector vector2, int vector_dimension, int degrees);

double QccVectorSquareDistance(const QccVector vector1, const QccVector vector2, int vector_dimension);

double QccVectorSumComponents(const QccVector vector, int vector_dimension);

double QccVectorMaxValue(const QccVector vector, int vector_dimension, int *winner);

double QccVectorMinValue(const QccVector vector, int vector_dimension, int *winner);

int QccVectorPrint(const QccVector vector, int vector_dimension);

DESCRIPTION

The QccPack library routines use a one-dimensional vector type defined as follows:

typedef double *QccVector;

QccVectorAlloc() allocates space for a QccVector of dimension vector_dimension. QccVectorAlloc() returns a NULL pointer if the allocation fails.

QccVectorFree() frees the space previously allocated via QccVectorAlloc()

QccVectorZero() makes each component of vector zero. QccVectorZero() returns 0 on success, 1 on failure.

QccVectorResize() changes the dimension of vector from vector_dimension to new_vector_dimension by calling realloc(3) . Upon success, the new vector is returned; a NULL pointer is returned if realloc(3) fails. If vector is NULL, QccVectorAlloc() is called. In any case, all elements added to vector are zero.

QccVectorMean() returns the mean value of all the components of vector. In the case that vector is NULL, QccVectorMean() returns 0.0.

QccVectorVariance() returns the variance of the components of vector. In the case that vector is NULL, QccVectorVariance() returns 0.0.

QccVectorSum() returns the sum of all the components of vector. In the case that vector is NULL, QccVectorSum() returns 0.0.

QccVectorAdd() adds each component of vector1 to the corresponding component of vector2 (vector addition). The resulting vector is returned in vector1. Both vector1 and vector2 must have the same vector dimension, vector_dimension. QccVectorAdd() returns 0 on success, 1 on failure.

QccVectorSubtract() subtracts each component of vector2 from the corresponding component of vector1. The resulting vector is returned in vector1. Both vector1 and vector2 must have the same vector dimension, vector_dimension. QccVectorSubtract() returns 0 on success, 1 on failure.

QccVectorScalarMult() multiplies vector vector by the scalar s; that is, each component of vector is multiplied by the double s, and the resulting vector is returned in vector. QccVectorScalarMult() returns 0 on success, 1 on failure.

QccVectorCopy() copies vector2 to vector1. QccVectorCopy() returns 0 on success, 1 on failure.

QccVectorNorm() calculates the norm (square root of dot product) of vector. If vector is NULL, 0.0 is returned.

QccVectorNormalize() divides vector by its nonzero norm as calculated by QccVectorNorm(). The resulting vector, which has unit length, is returned in vector. If, on the other hand, the vector norm is originally zero, vector is not changed.

QccVectorDotProduct() calculates and returns the dot product of vectors vector1 and vector2. Both vector1 and vector2 must have the same vector dimension, vector_dimension. If either vector1 or vector2 is NULL, 0.0 is returned.

QccVectorAngle() calculates and returns the angle between vectors vector1 and vector2. Both vector1 and vector2 must have the same vector dimension, vector_dimension. If either vector1 or vector2 is NULL, 0.0 is returned. If degrees is nonzero, the angle is return is degrees; otherwise, it is returned in radians. QccVectorAngle() calls QccVectorDotProduct()and QccVectorNorm(); the angle is the acos(3) of the dot product divided by the two vector norms. If either vector has zero norm, 0.0 is returned.

QccVectorSquareDistance() calculates the squared Euclidean distance between vectors vector1 and vector2. That is, vector2 is subtracted from vector1 and the dot product of the difference vector is returned. Both vector1 and vector2 must have the same vector dimension, vector_dimension. If either vector1 or vector2 is NULL, 0.0 is returned.

QccVectorSumComponents() adds all the components of vector together and returns the sum.

QccVectorMaxValue() returns the value of the largest component of vector. If winner is not a NULL pointer, the index (0 through vector_dimension - 1) of the maximum component is returned in the int pointed to by winner.

QccVectorMinValue() returns the value of the smallest component of vector. If winner is not a NULL pointer, the index (0 through vector_dimension - 1) of the minimum component is returned in the int pointed to by winner.

QccVectorPrint() prints the components of vector to stdout.

SEE ALSO

QccPack(3)

NOTES

Except as noted above, these vector routines accept NULL vector pointers, in which case these routines return immediately without generating an error or performing any operations.

AUTHOR

Copyright (C) 1997-2021 James E. Fowler


Table of Contents



Get QccPack at SourceForge.net. Fast, secure and Free Open Source software downloads