Advertisement
Guest User

piecewise affine dynamical system -> 1/x distribution

a guest
Nov 18th, 2014
213
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.67 KB | None | 0 0
  1. #include <math.h>
  2. #include <stdio.h>
  3.  
  4. #define MAX_ITER 1000000
  5. #define K 1024
  6.  
  7. typedef unsigned long long int uint64;
  8. int main() {
  9.   const double norm = 100. / MAX_ITER;
  10.   const double Cst = 100. / log(2.);
  11.   int n;
  12.   uint64 histo[K] = { 0 };
  13.  
  14.   const double alpha = 1.9;     // slope in (1.0, 2.0)
  15.   double y = 1.;               // anything in [1., 4./alpha)
  16.   for (n = 0; n < MAX_ITER; ++n) {
  17.     y = y * alpha;
  18.     if (y > 2.) y *= 0.5;
  19.     ++histo[(int)(y * K) - K];
  20.   }
  21.  
  22.   // print histo along with theoretical distribution 1 / x.ln(2)
  23.   for (n = K; n < 2 * K; ++n) {
  24.     printf("%d %.5lf %.5lf\n", n, norm * histo[n - K], Cst / n);
  25.   }
  26.   return 0;
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement