/***************************************************** * Computing the means and moments * * of a statistical variable * * * * -------------------------------------------------- * * REFERENCE: "Mathematiques et statistiques By H. * * Haut, PSI Editions, France, 1981" * * [BIBLI 13]. * * * * C++ version by J-P Moreau, Paris * * (www.jpmoreau.fr) * * -------------------------------------------------- * * SAMPLE RUN: * * * * TUTORIAL * * * * Means and moments of a statistical variable X(i) * * with frequency F(i) * * * * 1. Input number n of data * * * * 2. Input successively the n values X(i) and F(i) * * * * Number of data: 3 * * * * 1 1 6 * * 2 3 4 * * 3 5 8 * * * * Calculate generalized mean for t= 2 * * * * * * Arithmetic mean: 3.22222222 * * Geometric mean : 2.61023904 * * Harmonic mean : 2.01492537 * * * * Moments: * * * * M1= 3.22222222 * * M2= 3.06172840 * * M3= -1.16323733 * * M4= 12.56881570 * * * * Flatness coefficient....: 1.34079084 * * Coefficient of asymmetry: -0.21712925 * * * * Gen. mean M( 2): 3.66666667 * * * *****************************************************/ #include #include #define SIZE 101 int i,ite,n; double F[SIZE],X[SIZE]; double a,ap,asy,g,h,t,xm1,xm2,xm3,xm4,xmt; double tmpx,tmpf; /**************************************************** * Function to calculate the means and moments of a * * statistical variable X[i] * * ------------------------------------------------- * * INPUTS: * * n: number of data X[i] and F[i] * * X: n values X[i] * * F: n values F[i], frequency of X[i] * * t: coefficient of generalized mean M(t) * * to calculate * * OUTPUTS: * * a: arithmetic mean of X[i] * * g: geometric mean of X[i] * * h: harmonic mean of X[i] * * xm1: moment of first order * * xm2: moment of second order * * xm3: moment of third order * * xm4: moment of fourth order * * ap: flatness coefficient * * asy: coefficient of assymetry * * xmt: generalized mean M(t) * * ite: test flag (if te=1, harmonic mean h * * is not defined * ****************************************************/ void Calculate() { //Label: e100 double v1,v2,v3,v4,v5,v6,v7,vt,xm; int i; ite=0; v1=0.0; v2=0.0; v3=0.0; v4=0.0; v5=1.0; v6=0.0; v7=0.0; xm=0.0; // Calculate necessary sums for (i=1; i