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 16x16 lattice data_16x16_mine= np.loadtxt("16x16_mine.dat") #Now we use the NumPy loadtxt function to read the corresponding file with the C++ data data_16x16_provided=np.loadtxt("16x16.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=256 #Variance of energy/spin is equal to the difference between avg(E^2) and (avgE)^2 where E is energy/spin var_energies_16x16=np.subtract(data_16x16_mine[:,2],np.multiply(data_16x16_mine[:,1],data_16x16_mine[:,1])) #Heat Capacity is equal to the Variance / T^2 Heat_Capacity_16x16 = np.divide(var_energies_16x16, np.multiply(data_16x16_mine[:,0], data_16x16_mine[:,0])) #Plotting heat capacity/spin vs temperature using BOTH sets of data pl.plot(data_16x16_mine[:,0],(Heat_Capacity_16x16)/spins,'bo-', markersize = 3, label = 'Using My Data') pl.plot(data_16x16_provided[:,0],data_16x16_provided[:,5],'ro-', markersize=3, label = 'Using Data Provided') pl.title('Plots of Heat Capacity vs Temperature for Lattice Size: 16x16') pl.ylabel("Heat Capacity (in units of kB)") pl.xlabel("Temperature") pl.legend(loc='best') pl.show()