Created
June 1, 2024 00:41
-
-
Save Vasuji/7fcd97887a8a8814b7e0c5a78c848c95 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import matplotlib.pyplot as plt | |
# Additional lists to store properties at each step | |
magnetizations = [] | |
energies = [] | |
heat_capacities = [] | |
# Run the simulation | |
for i in range(num_steps): | |
lattice = metropolis_step(lattice) | |
# Calculate and store magnetization | |
magnetization = np.sum(lattice) | |
magnetizations.append(magnetization) | |
# Calculate and store energy | |
E = energy(lattice) | |
energies.append(E) | |
# Calculate and store heat capacity if not the first step | |
if i > 0: | |
heat_capacity = (energies[i] - energies[i-1]) / kT | |
heat_capacities.append(heat_capacity) | |
else: | |
heat_capacities.append(0) | |
# Plot magnetization | |
plt.figure() | |
plt.plot(magnetizations) | |
plt.title('Magnetization') | |
# Plot energy | |
plt.figure() | |
plt.plot(energies) | |
plt.title('Energy') | |
# Plot heat capacity | |
plt.figure() | |
plt.plot(heat_capacities) | |
plt.title('Heat Capacity') | |
plt.show() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment