Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <math.h>
- const int N=200;
- double x[N];
- double xs;
- double l=1.0;
- double p=0.5;
- int main(int argc, char **argv)
- {
- unsigned int i=0, j=0;
- double a=0;
- double xn, xx;
- for(i=1; i<=2e6; i++){
- xn=0;
- xx=0;
- //a =(int)(((double)rand()/RAND_MAX)/p)*2-1;
- for(j=0; j<N; j++){
- a=(double)rand()/RAND_MAX;
- if(a<p) a=-l;
- else a=+l;
- x[j]+=a;
- xn+=x[j];
- }
- for(j=0;j<N;j++){
- xx+=pow((x[j]-xn), 2);
- }
- xx=1/N*sqrt(xx);
- xs+=x[0];
- printf("%d %lf %lf %lf\n", i, xs/i, xn/N, xx);
- }
- return 0;
- }
Add Comment
Please, Sign In to add comment