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