//Tool for using the Flyvbjerg-Petersen blocking method to calculate the error on the sampling averages. This file contains code for calculating the error on the mean potential energy. By reading a plot of this code's output, one should observe a plateau, which is the estimate of the error on the mean potential energy #include #include #include int main() { FILE * energyData = fopen( "Energy.dat", "r" ); vector kineticEnergies; vector potentialEnergies; double kineticEnergy = 0.0; double potentialEnergy = 0.0; double totalEnergy = 0.0; int count = 0; while ( !feof( energyData ) ) { fscanf( energyData, "%lf %lf %lf", &kineticEnergy, &potentialEnergy, &totalEnergy ); if ( !feof( energyData ) ) { kineticEnergies.push_back( kineticEnergy ); potentialEnergies.push_back( potentialEnergy ); count++; } } fclose( energyData ); printf ( "%d\n", count ); count /= 2; FILE * constantFile = fopen( "ErrorEstimate.dat", "w" ); for ( int i=1; i-^2 = %lf, the constant = %20.14e\n", i, count/i, meanSquared, stdDev, average, meanSquared-average*average, (meanSquared-average*average)/((double)((count/i)-1)) ); fprintf ( constantFile, "%e %e\n", sqrt((meanSquared-average*average)/((double)((count/i)-1))), sqrt((meanSquared-average*average)/((double)((count/i)-1)))*(1./sqrt(2.*((double)((count/i)-1)))) ); } fclose ( constantFile ); }