#include #include int ix=1,iy=1; void main(){ double rho; long int i,m,n; double nrnd(void); double x,y; double x1=0.0,x2=0.0; double y1=0.0,y2=0.0; double xy1=0.0; long int i025,i050,i500,i950,i975; double x0[100001]; double y0[100001]; void qsort(double x[],long int l,long int n); for(i=1;i<=10000;i++) nrnd(); scanf("%lf%ld%ld",&rho,&m,&n); x=0.0; y=0.0; for(i=-m+1;i<=n;i++){ x=rho*y+sqrt( 1.-rho*rho )*nrnd(); y=rho*x+sqrt( 1.-rho*rho )*nrnd(); if( i >= 1 ){ x1+=x/((double)n); x2+=x*x/((double)n); y1+=y/((double)n); y2+=y*y/((double)n); xy1+=x*y/((double)n); x0[i]=x; y0[i]=y; } } printf("# of Burn-in = %10ld\n",m); printf("# of Random Draws = %10ld\n",n); printf("Rho = %7.2lf\n",rho); printf("Mean = ( %10.5lf, %10.5lf )\n",x1,y1); printf("Variance = ( %10.5lf, %10.5lf )\n",x2,y2); printf("Covariance = %10.5lf\n",xy1); qsort(x0,1,n); qsort(y0,1,n); i025=(int)( 0.025*(float)n ); i050=(int)( 0.050*(float)n ); i500=(int)( 0.500*(float)n ); i950=(int)( 0.950*(float)n ); i975=(int)( 0.975*(float)n ); printf(" 2.5 percent point of (x,y) = ( %8.5lf, %8.5lf )\n", (x0[i025]+x0[i025+1])/2.0,(y0[i025]+y0[i025+1])/2.0 ); printf(" 5 percent point of (x,y) = ( %8.5lf, %8.5lf )\n", (x0[i050]+x0[i050+1])/2.0,(y0[i050]+y0[i050+1])/2.0 ); printf("50 percent point of (x,y) = ( %8.5lf, %8.5lf )\n", (x0[i500]+x0[i500+1])/2.0,(y0[i500]+y0[i500+1])/2.0 ); printf("95 percent point of (x,y) = ( %8.5lf, %8.5lf )\n", (x0[i950]+x0[i950+1])/2.0,(y0[i950]+y0[i950+1])/2.0 ); printf("97.5 percent point of (x,y) = ( %8.5lf, %8.5lf )\n", (x0[i975]+x0[i975+1])/2.0,(y0[i975]+y0[i975+1])/2.0 ); } /* ------------------------------------------------ */ double urnd(void) { int kx,ky; double rn; /* Input: ix, iy: Seeds Output: rn: Uniform Random Draw U(0,1) */ kx=ix/53668; ix=40014*(ix-kx*53668)-kx*12211; ky=iy/52774; iy=40692*(iy-ky*52774)-ky*3791; rn=(float)(ix-iy)/2147483563.; rn-=(int)rn; if( rn<0.) rn++; return rn; } /* ------------------------------------------------ */ double nrnd(void) { double rn,r1,r2; double pi=3.1415926535897932385; double urnd(); r1=urnd(); r2=urnd(); rn=sqrt( -2.*log(r1) )*sin( 2.*pi*r2 ); return rn; } /* ====================================================== */ #define THRESHOLD 10 #define STACKSIZE 32 void qsort(double a[],long int first,long int last) /**************** Quick Sort ****************/ /************ a[first],...,a[last] ************/ { long int i,j,left,right,p; long int leftstack[STACKSIZE],rightstack[STACKSIZE]; double x,t; void inssort(double a[],long int first,long int last); left=first; right=last; p=first; for(;;) { if( right-left<=THRESHOLD ) { if( p==first ) break; p--; left = leftstack[p]; right=rightstack[p]; } x=a[ (left+right)/2 ]; i=left; j=right; for(;;) { while( a[i]=j ) break; t=a[i]; a[i]=a[j]; a[j]=t; i++; j--; } if( i-left>right-j ) { if( i-left>THRESHOLD ) { leftstack[p]=left; rightstack[p]=i-1; p++; } left=j+1; } else { if( right-j>THRESHOLD ) { leftstack[p]=j+1; rightstack[p]=right; p++; } right=i-1; } } inssort(a,first,last); } /* ------------------------------------------------------ */ void inssort(double a[],long int first,long int last) { long int i,j; double x; for( i=first+1;i<=last;i++ ) { x=a[i]; for( j=i-1;j>=first && a[j]>x;j-- ) a[j+1]=a[j]; a[j+1]=x; } }