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