On 2009-10-13, Sumesh P.T. <[email protected]> wrote: > I am using gsl_ran_gaussian to generate a random number distribution > with a specified standard deviation. Surprisingly the mean of the > distribution is not zero !!! Can it be possible? The mean does not > fluctuate around zero, but rather tends to be with a positive > value....Is this expected? or my interpretation is wrong? Has anyone > tried this? > I am giving my program and result here: > > ###########Program##########################3 > #include <stdlib.h> > #include <math.h> > #include "concen.h" > #include <gsl/gsl_errno.h> > #include <gsl/gsl_matrix.h> > #include <gsl/gsl_odeiv.h> > #include <gsl/gsl_rng.h> > #include <gsl/gsl_randist.h> > > int main() { > double y,sum=0.; > const gsl_rng_type * R; > gsl_rng * r; > gsl_rng_env_setup(); > R = gsl_rng_default; > r = gsl_rng_alloc (R); > for(int i=1;i<=10000;i++) { > y = gsl_ran_gaussian(r,1.); > sum=sum+y; > printf("%f, %f, %f ,\n",y,sum,sum/i); > } > } > ############################################## > ############################################## > Last 10 values after calling it 10000 times > ------------------------------------------------------ > random sum mean > 0.806397, 130.966701, 0.013108 , > -0.096531, 130.870170, 0.013097 , > -0.440024, 130.430146, 0.013052 , > 0.482622, 130.912768, 0.013099 , > 0.798685, 131.711453, 0.013178 , > 1.904331, 133.615784, 0.013367 , > 0.124113, 133.739897, 0.013378 , > -0.728447, 133.011450, 0.013304 , > -1.790865, 131.220585, 0.013123 , > -2.349805, 128.870779, 0.012887 , > > Both sum and mean are positive values with no fluctuations around > zero! Is not that surprising? > > Thanks, > sumesh >
I do not see any problem. Your mean of 0.01 is consistent with your sample size. Mean converges to zero rougly as 1/sqrt(N). Could you repeat you test with N=1000000 and N=10^8 To see fluctuations, please, change rng seed on each run. --Leo-- _______________________________________________ Help-gsl mailing list [email protected] http://lists.gnu.org/mailman/listinfo/help-gsl
