FunctionCenter of Gravity of an array, assuming its indices as the abscissa
Syntax C/C++#include <VFstd.h>
float VF_centerOfGravityInd( fVector X, ui siz );
C++ VecObj#include <OptiVec.h>
T vector<T>::centerOfGravityInd();
Pascal/Delphiuses VFstd;
function VF_centerOfGravityInd( X:fVector; size:UIntSize ): Single;
CUDA function C/C++#include <cudaVFstd.h>
int cudaVF_centerOfGravityInd( float *h_RetVal, fVector d_X, ui siz );
int cusdVF_centerOfGravityInd( float *d_RetVal, fVector d_X, ui siz );
float VFcu_centerOfGravityInd( fVector h_X, ui siz );
CUDA function Pascal/Delphiuses VFstd;
function cudaVF_centerOfGravityInd( var h_RetVal:Single; d_X:fVector; size:UIntSize ): IntBool;
function cusdVF_centerOfGravityInd( d_RetVal:PSingle; d_X:fVector; size:UIntSize ): IntBool;
function VFcu_centerOfGravityInd( h_X:fVector; size:UIntSize ): Single;
DescriptionThe center of gravity of the vector X is calculated according to the formula:
COG = sum( Xi * i ) / sum( Xi ).
It is assumed that the values of X represent point masses, situated at the positions given by their indices. The center of gravity is returned as a real number, as it will normally fall in between of two adjacent indices. If all elements of X are 0, there is no mass and no gravity; nevertheless, the center of gravity is assumed as the mid-point of X, i.e. (size-1) / 2.
To calculate the center of gravity of a vector over an abscissa explicitly given (rather than over its indices), call VF_centerOfGravityV.
Error handlingnone
Return valueThe position of the center of gravity is returned.
See alsoVF_centerOfGravityV

VectorLib Table of Contents  OptiVec home