/***************************************************** * Computing the statistical functions * * for one or two variables * * * * -------------------------------------------------- * * 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 * * * * 1. Define type of calculus:" * * 1: Statistical functions for a set X(i) * * 2: Statistical functions for a set X(i), Y(i) * * * * 2. Input number n of data * * * * 3. Input successively the n values X(i) [and Y(i)] * * * * Type of calculus (1 or 2): 2 * * * * Number of data: 5 * * * * 1 1 12 * * 2 2 9 * * 3 3 7 * * 4 4 15 * * 5 5 6 * * * * * * Mean of X(i)....................: 3.00000000 * * * * (n-1) standard deviation of X(i): 1.58113883 * * (n) standard deviation of X(i): 1.41421356 * * * * (n-1) standard dev. of X mean...: 0.70710678 * * (n) standard dev. of X mean...: 0.63245553 * * * * Mean of Y(i)....................: 9.80000000 * * * * (n-1) standard deviation of Y(i): 3.70135111 * * (n) standard deviation of Y(i): 3.31058908 * * * * (n-1) standard dev. of Y mean...: 1.65529454 * * (n) standard dev. of Y mean...: 1.48054045 * * * * * * (n-1) covariance of X,Y.........: -1.50000000 * * (n) covariance of X,Y.........: -1.20000000 * * * * Correlation coefficient.........: -0.25630730 * * * ****************************************************** Description: This program computes the usual statistical functions for a set of n variables X(i) or for a set of n pairs X(i), Y(i). */ #include #include #define SIZE 100 double X[SIZE], Y[SIZE]; double a3,a4,a5,a6,a7,tmp,tmp1; double v1,v2,v3,v4,v5,v6,v7,v8; int i, n, nt; /**************************************************** * Subroutine of statistical functions * * for 1 or 2 variables * * ------------------------------------------------- * * INPUTS: * * nt: type of calculus =1 for one variable * * =2 for two variables * * n: number of data X(i) [and Y(i) ] * * OUTPUTS: * * v1: mean of X(i) * * v2: mean of Y(i) * * v3: (n-1) standard deviation of v1 * * v4: (n-1) standard deviation of v2 * * v5: (n) standard deviation of v1 * * v6: (n) standard deviation of v2 * * v7: (n-1) covariance of X,Y * * v8: correlation coefficient * * a3: (n-1) standard deviation of X * * a4: (n-1) standard deviation of Y * * a5: (n) standard deviation of X * * a6: (n) standard deviation of Y * * a7: (n) covariance of X,Y * ****************************************************/ void Stat_functions() { //Label: e100 int i,n1; double xnr; v1=0.0; v2=0.0; v3=0.0; v4=0.0; v5=0.0; n1=n-1; xnr=sqrt(n); //choose type of calculus if (nt==2) goto e100; //case of one set X(i) for (i=1; i