[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
## Re: [Help-gsl] gsl_ran_gaussian giving non-zero mean !

**From**: |
Frank Reininghaus |

**Subject**: |
Re: [Help-gsl] gsl_ran_gaussian giving non-zero mean ! |

**Date**: |
Tue, 13 Oct 2009 15:56:31 +0200 |

Hi,
2009/10/13 Sumesh P.T. <address@hidden>:
>* Both sum and mean are positive values with no fluctuations around*
>* zero! Is not that surprising?*
No, it's not. These 10 last sums and mean values you've shown are
correlated to each other: If you've accumulated a mean of 130 at some
point and add a few small random numbers to it, it will of course
remain somewhere near 130. It would only be surprising if you always
got a positive mean even if you use different initial values for the
RNG, but that's not the case (see example code below).
Cheers,
Frank
#include <time.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);
gsl_rng_set (r, time (0));
int i;
for(i=1;i<=10000;i++) {
y = gsl_ran_gaussian(r,1.);
sum=sum+y;
printf("%f, %f, %f ,\n",y,sum,sum/i);
}
}