Return to previous page

Contents of file 'sgfilter/example.c':




Deprecated: Function split() is deprecated in /storage/content/45/2011745/jonsson.eu/public_html/php/htmlicise.php on line 46
    1   /*9:*/
    2   #line 723 "./sgfilter.w"
    3   
    4   #include <stdio.h> 
    5   #include <stdlib.h> 
    6   #include <time.h> 
    7   #include <math.h> 
    8   #define TWOPI (2.0*3.141592653589793)
    9   
   10   float gauss(float x,float w,float xa){
   11   return(exp(-pow(((x-xa)/w),2)));
   12   }
   13   
   14   float func(float x){
   15   float retval= gauss(x,0.007,0.2);
   16   retval+= gauss(x,0.01,0.4);
   17   retval+= gauss(x,0.02,0.6);
   18   retval+= gauss(x,0.04,0.8);
   19   retval*= 4.0;
   20   retval+= cos(3.0*x)*pow(sin(pow(x,3)),2);
   21   return(retval);
   22   }
   23   
   24   int main(int argc,char*argv[]){
   25   int k,mm= 1024;
   26   float var= 1.0,xmax= 2.5,x1,x2,u,v,f,z;
   27   if(argc> 1)sscanf(argv[1],"%f",&var);
   28   srand((unsigned)time(NULL));
   29   for(k= 0;k<mm-1;k+= 2){
   30   x1= xmax*k/((double)mm-1);
   31   x2= xmax*(k+1)/((double)mm-1);
   32   u= ((float)rand())/RAND_MAX;
   33   v= ((float)rand())/RAND_MAX;
   34   if(u> 0.0){
   35   f= sqrt(-2*log(u));
   36   z= TWOPI*v;
   37   u= f*cos(z);
   38   v= f*sin(z);
   39   fprintf(stdout,"%1.8f %1.8f\n",x1,func(x1)+var*u);
   40   fprintf(stdout,"%1.8f %1.8f\n",x2,func(x2)+var*v);
   41   }
   42   }
   43   return(0);
   44   }
   45   
   46   /*:9*/
   47   

Return to previous page

Generated by ::viewsrc::

Last modified Saturday 17 Dec 2011