from IsingLattice import * from matplotlib import pylab as pl import numpy as np #First, we use the NumPy loadtxt function to read our previously saved file for the 32x32 lattice data_32x32_mine= np.loadtxt("32x32_mine.dat") #Now we use the NumPy loadtxt function to read the corresponding file with the C++ data data_32x32_provided=np.loadtxt("32x32.dat") #Calculating Heat Capacity: #Define number of spins in lattice (so that we can use this to convert values of energy to energy/spin) spins=1024 #Variance of energy/spin is equal to the difference between avg(E^2) and (avgE)^2 where E is energy/spin var_energies_32x32=np.subtract(data_32x32_mine[:,2],np.multiply(data_32x32_mine[:,1],data_32x32_mine[:,1])) #Heat Capacity is equal to the Variance / T^2 Heat_Capacity_32x32 = np.divide(var_energies_32x32, np.multiply(data_32x32_mine[:,0], data_32x32_mine[:,0])) #Plotting heat capacity/spin vs temperature using BOTH sets of data pl.plot(data_32x32_mine[:,0],(Heat_Capacity_32x32)/spins,'bo-', markersize = 3, label = 'Using My Data') pl.plot(data_32x32_provided[:,0],data_32x32_provided[:,5],'ro-', markersize=3, label = 'Using Data Provided') pl.title('Plots of Heat Capacity vs Temperature for Lattice Size: 32x32') pl.ylabel("Heat Capacity (in units of kB)") pl.xlabel("Temperature") pl.legend(loc='best') pl.show()