Skip to content

Instantly share code, notes, and snippets.

@rodrigoflores
Created December 3, 2010 13:02
Show Gist options
  • Save rodrigoflores/726925 to your computer and use it in GitHub Desktop.
Save rodrigoflores/726925 to your computer and use it in GitHub Desktop.
1 3.0
0.95 10.0
0.90 15.0
0.85 8.0
0.80 7.
0.75 6.0
0.70 5.0
0.65 4.0
0.50 3.0
0.45 3.0
0.4 3.0
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include <time.h>
#define VMAX 1000
#define NMAX 67.0
int main()
{
int j;
double average,stddev, S[VMAX], Freq[VMAX], Dist[VMAX];
FILE *statdata, *data;
data=fopen("data.txt","r");
statdata=fopen("stat-data.txt","w");
while(fscanf(data,"%lf %lf", &S[j], &Freq[j]) > 0) {
// fscanf(data,"%lf", &Freq[j]);
Dist[j]=fabs(S[j]*Freq[j]-NMAX);
}
for(j=0, average=0.0;NMAX>j;j=j+1)
average=Dist[j]+average;
average=average/NMAX;
for(j=0, stddev=0.0;NMAX>j;j=j+1)
stddev=(average-Dist[j])*(average-Dist[j])+stddev;
stddev=stddev/NMAX;
stddev=sqrt(stddev);
if(average-(stddev*3)<0)
fprintf(statdata,"the sample is very bad, the average distance is %g and the standard deviation is %g",average, stddev);
else if(average-(stddev*3)>1)
fprintf(statdata,"the sample is very good, the average distance is %g and the standard deviation is %g",average, stddev);
else
fprintf(statdata,"the sample is ok, the average distance is %g and the standard deviation is %g. We recommend to add more data",average, stddev);
fclose(data);
fclose(statdata);
//system("PAUSE");
return 0;
}
@rodrigoflores
Copy link
Author

the sample is very bad, the average distance is 0.98209 and the standard deviation is 7.97853%

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment