"Fossies" - the Fresh Open Source Software Archive

Member "ccmath-2.2.1/simu/test/distribution/unfl2dis.c" (23 Nov 2000, 1762 Bytes) of package /linux/misc/old/ccmath-2.2.1.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file.

    1 /*  unfl2dis.c    CCMATH mathematics library source code.
    2  *
    3  *  Copyright (C)  2000   Daniel A. Atkinson    All rights reserved.
    4  *  This code may be redistributed under the terms of the GNU library
    5  *  public license (LGPL). ( See the lgpl.license file for details.)
    6  * ------------------------------------------------------------------------
    7  */
    8 /*
    9      Test:  unfl2()  setunfl2()  autcor()  hist()
   10 
   11      Input parameters:  n -> integer: sample size
   12                         s -> unsigned integer: pseudorandom seed
   13 */
   14 #include "ccmath.h"
   15 int lag=20,nbin=20;
   16 double xmin=0.,xmax=1.;
   17 void main(int na,char **av)
   18 { double *x,*p,xm,bin,dsq,c,*ac;
   19   int n,i,k,*hs; unsigned int s;
   20   if(na!=3){ printf("para: siz seed(hex)\n"); exit(-1);}
   21   n=atoi(*++av); sscanf(*++av,"%x",&s);
   22   printf(" sample size= %d\n",n);
   23   printf(" seed= %x\n",s);
   24   x=(double *)calloc(sizeof(double),n);
   25 
   26 /* initialize pseudorandom generator */
   27   setunfl2(s); xm=0.;
   28 /* generate sample of pseudorandom numbers uniform on [0,1] */
   29   for(p=x,i=0; i<n ;++i){
   30     *p=unfl2(); xm+= *p++;
   31    }
   32   printf("  mean= %e\n",xm/n);
   33   for(i=0,p=x; i<n ;++i) *p++ -=0.5;
   34 
   35 /* compute autocorrelations of sample */
   36   ac=autcor(x,n,lag); dsq=ac[0]/n;
   37   for(i=0,p=x; i<n ;++i) *p++ +=0.5;
   38   printf("  variance= %e\n",dsq);
   39   printf("  autocorrelations\n");
   40   for(i=1,c=0.; i<=lag ;++i){
   41     c+=ac[i]*ac[i];
   42     printf("    %2d  %10.2e   %5.2f\n",i,ac[i],c*n);
   43    }
   44 
   45 /* compute histogram of sample distribution */
   46   hs=hist(x,n,xmin,xmax,nbin,&bin);
   47   printf(" histogram bin= %.2f\n",bin);
   48   printf("  %d < %4.1f  %d > %4.1f\n",hs[-1],xmin,hs[nbin],xmax);
   49   for(i=0,xm=xmin,k=hs[-1],dsq=n; i<nbin ;++i,xm+=bin){
   50     k+=hs[i]; c=k/dsq;
   51     printf("   %5.2f to %5.2f  %5d    %5.3f\n",xm,xm+bin,hs[i],c);
   52    }
   53 }