<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://chemwiki.ch.ic.ac.uk/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Jj1516</id>
	<title>ChemWiki - User contributions [en]</title>
	<link rel="self" type="application/atom+xml" href="https://chemwiki.ch.ic.ac.uk/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Jj1516"/>
	<link rel="alternate" type="text/html" href="https://chemwiki.ch.ic.ac.uk/wiki/Special:Contributions/Jj1516"/>
	<updated>2026-04-06T10:21:12Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.43.0</generator>
	<entry>
		<id>https://chemwiki.ch.ic.ac.uk/index.php?title=Rep:JJ1516Ising&amp;diff=737030</id>
		<title>Rep:JJ1516Ising</title>
		<link rel="alternate" type="text/html" href="https://chemwiki.ch.ic.ac.uk/index.php?title=Rep:JJ1516Ising&amp;diff=737030"/>
		<updated>2018-11-21T10:57:43Z</updated>

		<summary type="html">&lt;p&gt;Jj1516: /* Magnetisation at 0K */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Introduction to the Ising Model =&lt;br /&gt;
&lt;br /&gt;
== The Model ==&lt;br /&gt;
&lt;br /&gt;
=== Minimum Energy State ===&lt;br /&gt;
====Minimum Interaction Energy====&lt;br /&gt;
The interaction energy of an Ising lattice is given by:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;E = -\frac{1}{2}J\displaystyle\sum_{i}^{N} \displaystyle\sum_{j\;\in\;{neighbours}\;(i)} \!\!\!\!\!\!\!\!\!\!\!\!s_{i}s_{j}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In an Ising lattice with D dimensions and periodic boundary conditions, a given spin &amp;lt;math&amp;gt; s_i&amp;lt;/math&amp;gt; has 2D neighbours.&lt;br /&gt;
&lt;br /&gt;
The minimum interaction energy is achieved when all spins in the lattice are aligned (all ↑ or all ↓). As  such, any spin &amp;lt;math&amp;gt; s_i&amp;lt;/math&amp;gt; must be aligned with all 2D of its neighbours. That is, &amp;lt;math&amp;gt;s_{i}s_{j} = 1&amp;lt;/math&amp;gt; for all &amp;lt;math&amp;gt;j&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Therefore, for any &amp;lt;math&amp;gt; s_i&amp;lt;/math&amp;gt;, the sum of its interactions is &amp;lt;math&amp;gt;\displaystyle\sum_{j\;\in\;{neighbours}\;(i)} \!\!\!\!\!\!\!\!\!\!\!\!s_{i}s_{j} = 2D &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
As this is true for all N spins in the lattice, it follows that &amp;lt;math&amp;gt;\displaystyle\sum_{i}^{N} 2D = 2DN&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Thus the minimum interaction energy is given by:&lt;br /&gt;
&lt;br /&gt;
:&amp;lt;math&amp;gt;E_{min} = -\frac{1}{2}J\cdot2DN = - DNJ &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Entropy of the Minimum Energy State====&lt;br /&gt;
&lt;br /&gt;
The entropy of a state is given by:&lt;br /&gt;
&lt;br /&gt;
:&amp;lt;math&amp;gt;S = k\; ln\; \Omega &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Where &amp;lt;math&amp;gt; \Omega &amp;lt;/math&amp;gt; is the multiplicity of the state, the number of degenerate configurations of said state. The minimum energy state is achievable with all spins ↑ or with all spins ↓. In the absence of an external magnetic field, these configurations are degenerate and indistinguishable giving &amp;lt;math&amp;gt; \Omega = 2 &amp;lt;/math&amp;gt; for this state. Therefore,&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; S_{E_{min}}  = k_{B}\; ln\; 2 = 0.693k_{B} = 9.57 \times 10^{-24} J\!\cdot\!\! K^{-1}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Phase Transitions ==&lt;br /&gt;
&lt;br /&gt;
=== Changes to Minimum Energy Configuration ===&lt;br /&gt;
&lt;br /&gt;
====Energy Change ====&lt;br /&gt;
The energy change &amp;lt;math&amp;gt; \Delta E&amp;lt;/math&amp;gt; associated with a single spin &#039;flip&#039; from the lowest energy onfiguration may be calculated by considering the change in the interaction energy with the spin&#039;s neighbours.&lt;br /&gt;
&lt;br /&gt;
Let &amp;lt;math&amp;gt; D = 3, N = 1000 &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\Delta{E} = E_1 - E_0&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;E_1&amp;lt;/math&amp;gt; Interaction energy after one spin has been &#039;flipped&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;E_0&amp;lt;/math&amp;gt; Lowest energy configuration&lt;br /&gt;
&lt;br /&gt;
[[Image:Task 2 table.PNG]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\displaystyle\sum_{interactions} = -2D + 2D(2D-2) + 2D[N-(2D+1)] &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; = 2DN - 8D &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;E_1 = \displaystyle-\frac{1}{2}J\;\sum_{interactions} = 4DJ - DNJ&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\Delta{E} = E_1 - E_0 = 4DJ - DNJ + DNJ = +4DJ = +12J&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This energy change is independent of &amp;lt;math&amp;gt; N&amp;lt;/math&amp;gt; and depends only on the dimension size and the coupling constant &amp;lt;math&amp;gt; J &amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
In this calculation, the following assumption has been made.&lt;br /&gt;
&lt;br /&gt;
* The lattice dimensions are infinite relative to the size of each cell&lt;br /&gt;
&lt;br /&gt;
This allows &#039;&#039;&#039;any&#039;&#039;&#039; cell to be treated as the centre of the lattice. As every cell interacts with 2D neighbours, flipping any cell in the minimum energy configuration results in the same energy change. Alternatively, the periodic boundary conditions of the Ising model remove the necessity for such an assumption. As a consequence, the absence of &amp;lt;math&amp;gt; N &amp;lt;/math&amp;gt; from the resulting energy change is justified.&lt;br /&gt;
&lt;br /&gt;
====Entropy Change====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; S = k_{B}\; ln\; \Omega &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\Omega = \displaystyle\frac{N!}{{N_{\uparrow}!}{N_{\downarrow}!}}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Where &amp;lt;math&amp;gt;N_{x}!&amp;lt;/math&amp;gt; denotes the factorial of the number of spins in spin state &amp;lt;math&amp;gt;x&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\Delta{S} = k_{B}\;ln\;\left(\displaystyle\frac{\Omega_{2}}{\Omega_{1}}\right)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\Omega_{2} = \frac{1000!}{999!1!} = 1000&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \Omega_{1} = \frac{1000!}{1000!} = 1&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\Delta{S} = k_{B}\;ln\;1000 = 9.54 \times 10^{-23} JK^{-1}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\Delta{S_{mol}} = N_{A}k_{B}\;ln\;1000 = 57.4 \,JK^{-1}mol^{-1}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Magnetisation Values of 1D and 2D Lattices===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;M = \sum_i s_i&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====1D Lattice Magnetisation====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;M_{1D} =\;\;+1&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====2D Lattice Magnetisation====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;M_{2D} =\;\;+1&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Magnetisation at 0K====&lt;br /&gt;
&lt;br /&gt;
At 0K, no thermal energy is available to overcome the energetic barriers to spin flipping. Considering the Hemholtz free energy:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; A = E - TS &amp;lt;/math&amp;gt; &lt;br /&gt;
&lt;br /&gt;
A temperature of 0K nullifies the entropic contribution to the free energy. Thus the energetic driving force (which maximises parallel spin interactions) dominates the entropic driving force (which maximises multiplicity of lattice states). For an Ising Lattice with D =  3, N = 1000 at 0K, the alignment of all spins results in the minimum energy configuration  and an overall magnetisation of &amp;lt;math&amp;gt; M = \pm 1000 &amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
= Calculating the Energy and Magnetisation =&lt;br /&gt;
==Modifying the Files==&lt;br /&gt;
&lt;br /&gt;
===Energy and Magnetisation Functions===&lt;br /&gt;
&lt;br /&gt;
====Energy===&lt;br /&gt;
[[File:First_Ene_Method.PNG]]&lt;br /&gt;
&lt;br /&gt;
The above energy method segments a given lattice into lattice cells on the edges, corners or in the bulk of the lattice and calculates the energy interactions with its neighbours as appropriate.&lt;br /&gt;
&lt;br /&gt;
====Magnetisation====&lt;br /&gt;
[[File:First_Mag_Method.PNG]]&lt;br /&gt;
&lt;br /&gt;
The magnetisation method loops over all elements in the array representing the Ising lattice and adds the value of the spin to the magnetisation variable.&lt;br /&gt;
&lt;br /&gt;
==Testing the Files==&lt;br /&gt;
&lt;br /&gt;
===ILCheck.py===&lt;br /&gt;
&lt;br /&gt;
[[File:ILChecks.PNG]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Above, the results of the ILcheck.py script are presented.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= Introduction to the Monte Carlo Simulation =&lt;br /&gt;
==Average Energy and Magnetisation==&lt;br /&gt;
===Configurations of a 100 Spin System===&lt;br /&gt;
For a system of two spins, 4 configurations are possible (↑↑, ↓↓, ↑↓, ↓↑) i.e. &amp;lt;math&amp;gt;2^{2}&amp;lt;/math&amp;gt;. For a system of 100 spins, there are &amp;lt;math&amp;gt;2^{100}&amp;lt;/math&amp;gt; configurations. In the first example, the ↑↑ and ↓↓ are degenerate, as are the ↑↓ and ↓↑ configurations. Therefore, dividing the number of possible configurations by the multiplicity of each configuration (&amp;lt;math&amp;gt;2&amp;lt;/math&amp;gt;) gives the number of non-degenerate configurations. As previously stated, degenerate configurations are indistinguishable in the absence of an external magnetic field.&lt;br /&gt;
&lt;br /&gt;
For 100 spins, this gives &amp;lt;math&amp;gt;\displaystyle\frac{2^{100}}{2} = 6.338 \times 10^{29} &amp;lt;/math&amp;gt; distinguishable configurations.&lt;br /&gt;
&lt;br /&gt;
If processing speed permits &amp;lt;math&amp;gt; 1 \times 10^{9}&amp;lt;/math&amp;gt; calculations each second, the evaluation of a single value of &amp;lt;math&amp;gt;\left\langle M\right\rangle_T&amp;lt;/math&amp;gt; would last &amp;lt;math&amp;gt; 6.338 \times 10^{20} &amp;lt;/math&amp;gt; seconds or &amp;lt;math&amp;gt; 1458 &amp;lt;/math&amp;gt; times the age of the Universe!&lt;br /&gt;
&lt;br /&gt;
==Modifying IsingLattice.py==&lt;br /&gt;
&lt;br /&gt;
===Monte Carlo and Statistics Methods===&lt;br /&gt;
[[File:Monte_Carlo.PNG]]&lt;br /&gt;
&lt;br /&gt;
[[File:stats.PNG]]&lt;br /&gt;
&lt;br /&gt;
The Metropolis Monte Carlo (MMC) algorithm provides a computationally inexpensive path from random initial states to the minimum free energy states of the Ising lattices generated. First, a random 2D Ising lattice is generated. A single random spin within this lattice is &amp;quot;flipped&amp;quot; and the resulting (internal) energy change between these states is measured. Recalling the relationship between the Hemholtz free energy, internal energy and entropy, it follows that a decrease in internal energy also lowers the free energy of the system: thus the configuration change is accepted.&lt;br /&gt;
&lt;br /&gt;
In the case that the spin &amp;quot;flip&amp;quot; does not lower the internal energy, the MMC algorithm tests this configuration change against the Boltzman factor. In the canonical (NVT) ensemble, the free energy of the system is given by:&lt;br /&gt;
&lt;br /&gt;
:&amp;lt;math&amp;gt;A = -k_{B}T\,lnZ_{NVT} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
where Z is the canonical partition function which depends upon &amp;lt;math&amp;gt; e^{-\frac{\Delta E}{k_BT}} &amp;lt;/math&amp;gt;, the Boltzman factor. By choosing a random value in the interval [0,1)from a continuous uniformm probability distribution and rejecting any value of the Boltzman factor less than this value, the MMC algorithm allows for configuration changes with small, positive internal energy changes if they conform to the Boltzman probability distribution. Alternatively, the MMC allows small perturbations to the internal energy which prevents the system from settling in a metastable internal energy minimum and instead, ensures that the system equilibrates around the &#039;&#039;true&#039;&#039; free energy minimum.&lt;br /&gt;
&lt;br /&gt;
===Spontaneous Magnetisation===&lt;br /&gt;
&lt;br /&gt;
Below the Curie Temperature, &amp;lt;math&amp;gt; T_{C} &amp;lt;/math&amp;gt;, the energetic driving force dominates the entropic driving force, resulting in a highly ordered system and an overall magnetisation. The spins of the system align in order to maximise favourable coupling interactions rather than adopting a less ordered configuration of higher multiplicity. Therefore, when &amp;lt;math&amp;gt;T &amp;lt; T_C&amp;lt;/math&amp;gt;, the most probable configurations have an overall magnetisation resulting in &amp;lt;math&amp;gt;\left\langle M\right\rangle \neq 0&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
The plots of magnetisation per spin and energy per spin obtained from ILanim.py support this prediction. Below, the plots show that upon equilibration, the system adopts the minimum energy per spin: &amp;lt;math&amp;gt;E_{min_{spin}} = \frac{-NDJ}{N} = -DJ = -2&amp;lt;/math&amp;gt; and exhibits the maximum magnitude of magnetisation per spin: &amp;lt;math&amp;gt;|M_{spin}| = 1&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:2T=1.0.png]]&lt;br /&gt;
[[File:T=1.0.png]]&lt;br /&gt;
[[File:3T=1.0.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
An unknown system error prevented the statistics() function from printing the average values.&lt;br /&gt;
&lt;br /&gt;
=Accelerating the Code=&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Initial Method Speeds===&lt;br /&gt;
Taking 10 repeat measurements for the time taken to perform 2000 Monte Carlo steps resulted in&lt;br /&gt;
&lt;br /&gt;
* An average time of  &amp;lt;math&amp;gt;11.7s&amp;lt;/math&amp;gt; &lt;br /&gt;
* A standard error of &amp;lt;math&amp;gt;0.020s&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Updating Measurement===&lt;br /&gt;
&lt;br /&gt;
NOTE: ILtimetrial.py has been modified to:&lt;br /&gt;
* Perform a requested number of &#039;2000 Monte Carlo Step&#039; measurements&lt;br /&gt;
* Record these measurements in a CSV file&lt;br /&gt;
* Return the mean measuremd time and the Standard Error i.e.   &amp;lt;math&amp;gt; \frac{\sigma}{n} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:TimeTrialMethod.PNG]]&lt;br /&gt;
&lt;br /&gt;
===Updating Energy and Magnetisation Methods===&lt;br /&gt;
[[File:New_Mag_Method.PNG]]&lt;br /&gt;
[[File:New_Ene_Method.PNG]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Updated Method Speeds===&lt;br /&gt;
[[File:TimeTrial.PNG]]&lt;br /&gt;
&lt;br /&gt;
Taking 30 measurements of the time taken to perform 2000 Monte Carlo Steps resulted in:&lt;br /&gt;
&lt;br /&gt;
* An average time of &amp;lt;math&amp;gt;\displaystyle{0.87s}&amp;lt;/math&amp;gt;&lt;br /&gt;
* A standard error of &amp;lt;math&amp;gt;2.5 \times 10^{-3}s&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This represents a 93% decrease in the average computation time from the initial methods.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=The Effect of Temperature=&lt;br /&gt;
&lt;br /&gt;
==Correcting the Averaging  Code==&lt;br /&gt;
&lt;br /&gt;
===Finding a Delay Value===&lt;br /&gt;
To quickly find a value for &amp;lt;math&amp;gt; N_{d}&amp;lt;/math&amp;gt;, the minimum number of cycles typically needed for the equilibration of a system of within the lattice and temperature ranges of interest, it was assumed that:&lt;br /&gt;
&lt;br /&gt;
* Larger lattices would require more Monte Carlo steps to reach equilibrium from their initial, random configurations&lt;br /&gt;
&lt;br /&gt;
* Lattices at lower temperatures would require more Monte Carlo steps to reach equilibrium from their initial, random configurations.&lt;br /&gt;
&lt;br /&gt;
Therefore, an initial value for &amp;lt;math&amp;gt; N_{d}&amp;lt;/math&amp;gt; was found for a &amp;lt;math&amp;gt; 128\times128 &amp;lt;/math&amp;gt; lattice at a temperature of &amp;lt;math&amp;gt;0.5&amp;lt;/math&amp;gt; reduced temperature units.&lt;br /&gt;
*&amp;lt;math&amp;gt; N_{d} = 185000 &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
By this number of steps, all smaller lattices at all higher temperatures were found to have equilibrated also. Thus, this value of&amp;lt;math&amp;gt; N_{d}&amp;lt;/math&amp;gt; was accepted as an appropriate delay.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:AFinFrame 128 3e5 T= 0.5line.png|400px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
For the 128x128 lattices at T=0.5, equilibration was ensured from 185000 steps onwards.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Smaller lattices at the same temperature did indeed equilibrate more slowly, but all equilibrated within &amp;lt;math&amp;gt; N_{d}&amp;lt;/math&amp;gt; MC steps.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:AFinFrame 64 3e5 T= 0.5line.png|400px]]&lt;br /&gt;
[[File:AFinFrame 32 3e5 T= 0.5line2.png|400px]]&lt;br /&gt;
[[File:AFinFrame 16 3e5 T= 0.5line2.png|400px]]&lt;br /&gt;
[[File:AFinFrame 8 3e5 T= 0.5line.png|400px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The figure below shows the modifications made to IsingLattice.py to incorporate the &amp;lt;math&amp;gt; N_{d} &amp;lt;/math&amp;gt; step delay.&lt;br /&gt;
&lt;br /&gt;
==Running over a Range of Temperatures==&lt;br /&gt;
&lt;br /&gt;
To examine the effect of temperature on the average energy &amp;lt;math&amp;gt; \left\langle E\right\rangle &amp;lt;/math&amp;gt; and average magnetisation &amp;lt;math&amp;gt; \left\langle M\right\rangle &amp;lt;/math&amp;gt; of Ising lattices at equilibrium, the following parameters were used:&lt;br /&gt;
&lt;br /&gt;
* Temperature Range: &amp;lt;math&amp;gt;  0.5 - 5 &amp;lt;/math&amp;gt; reduced units&lt;br /&gt;
* Temperature Interval: &amp;lt;math&amp;gt;0.01&amp;lt;/math&amp;gt; reduced units (&amp;lt;math&amp;gt;450&amp;lt;/math&amp;gt; temperature values)&lt;br /&gt;
* Number of MMC Steps per Temperature value: &amp;lt;math&amp;gt; 2 \times 10^5 &amp;lt;/math&amp;gt; with the aforementioned value of &amp;lt;math&amp;gt; N_{d} = 1.85 \times 10^5 &amp;lt;/math&amp;gt; Monte Carlo steps&lt;br /&gt;
* Lattice Sizes:  &amp;lt;math&amp;gt; 2 \times 2 &amp;lt;/math&amp;gt;, &amp;lt;math&amp;gt; 4 \times 4 &amp;lt;/math&amp;gt; , &amp;lt;math&amp;gt; 8 \times 8 &amp;lt;/math&amp;gt; , &amp;lt;math&amp;gt; 16 \times 16 &amp;lt;/math&amp;gt; , &amp;lt;math&amp;gt; 32 \times 32 &amp;lt;/math&amp;gt; , &amp;lt;math&amp;gt; 64 \times 64 &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Plots of  &amp;lt;math&amp;gt; \left\langle E\right\rangle &amp;lt;/math&amp;gt; and  &amp;lt;math&amp;gt; \left\langle M\right\rangle &amp;lt;/math&amp;gt; per spin as versus temperature are presented below for each lattice size. Errorbars have been implemented to demonstrate how &#039;&#039;well-behaved&#039;&#039; lattice systems of each size are at each temperature, that is, how temperature and lattice size affect the size of the variations in the expected values. For the error calculations, the standard errors, &amp;lt;math&amp;gt; \sigma_\bar{X} &amp;lt;/math&amp;gt;,  in &amp;lt;math&amp;gt; \left\langle E\right\rangle &amp;lt;/math&amp;gt; and  &amp;lt;math&amp;gt; \left\langle M\right\rangle &amp;lt;/math&amp;gt; per spin have been used:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====8x8====&lt;br /&gt;
&lt;br /&gt;
[[File:8x8e+error.png]] [[File:8x8m+error.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
A Python script has been written to generate a plot of &amp;lt;math&amp;gt;\left\langle E\right\rangle&amp;lt;/math&amp;gt; or &amp;lt;math&amp;gt;\left\langle M\right\rangle&amp;lt;/math&amp;gt; against temperature based upon user input. A screenshot of this code has been inserted below.&lt;br /&gt;
&lt;br /&gt;
[[File:ExpectedvsTemp.PNG|200px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=The Effect of System Size=&lt;br /&gt;
&lt;br /&gt;
==Scaling the System Size==&lt;br /&gt;
&lt;br /&gt;
===More Lattice Sizes===&lt;br /&gt;
&lt;br /&gt;
====2x2====&lt;br /&gt;
[[File:2x2e+error.png]] [[File:2x2m+error.png]]&lt;br /&gt;
&lt;br /&gt;
====4x4====&lt;br /&gt;
[[File:4x4e+error.png]] [[File:4x4m+error.png]]&lt;br /&gt;
&lt;br /&gt;
====16x16====&lt;br /&gt;
[[File:16x16e+error.png]] [[File:16x16m+error.png]]&lt;br /&gt;
&lt;br /&gt;
====32x32====&lt;br /&gt;
[[File:32x32e+error.png]] [[File:32x32m+error.png]]&lt;br /&gt;
&lt;br /&gt;
====64x64====&lt;br /&gt;
[[File:64x64e+error.png]] [[File:64x64m+error.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Scrutiny of the plots of average energy per spin for each lattice size reveals an increase in the errorbar width with increasing lattice size. This is most notable in the low temperature region of the plots. Between the &amp;lt;math&amp;gt; 8\times8 &amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt; 16\times16 &amp;lt;/math&amp;gt; lattices, the long range fluctuations become suddenly prominent. The &amp;lt;math&amp;gt;16\times16&amp;lt;/math&amp;gt; lattice is the first (in the range of sizes tested)to clearly capture these fluctuations.&lt;br /&gt;
&lt;br /&gt;
=Determining the Heat Capacity=&lt;br /&gt;
&lt;br /&gt;
==Calculating the Heat Capacity==&lt;br /&gt;
&lt;br /&gt;
===Heat Capacity Derivation===&lt;br /&gt;
Working in the canonical ensemble (constant volume), the heat capacity &amp;lt;math&amp;gt; C_V &amp;lt;/math&amp;gt; is given by:&lt;br /&gt;
&lt;br /&gt;
:&amp;lt;math&amp;gt;C_V = \frac{\partial \left\langle E\right\rangle}{\partial T}_V&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
where &amp;lt;math&amp;gt;\left\langle E\right\rangle&amp;lt;/math&amp;gt; is the average total energy or expected value of the internal energy of the system.&lt;br /&gt;
&lt;br /&gt;
: &amp;lt;math&amp;gt; \left\langle E\right\rangle = - \frac{\partial ln Q}{\partial \beta} = -\frac{1}{Q}\frac{\partial Q}{\partial \beta} &amp;lt;/math&amp;gt;&lt;br /&gt;
where &amp;lt;math&amp;gt; Q&amp;lt;/math&amp;gt; is the partition function for the system of N interacting spins.&lt;br /&gt;
&lt;br /&gt;
By evaluating the second form of the partial derivative with respect to &amp;lt;math&amp;gt; \beta&amp;lt;/math&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \left\langle E\right\rangle = -\frac{1}{Q}\frac{\partial Q}{\partial \beta} = \frac{\Sigma \epsilon_{i} e^{-\beta \epsilon_{i}}}{\Sigma e^{-\beta \epsilon_{i}}} &amp;lt;/math&amp;gt; &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Applying the product rule enables the differentiation of this expression for &amp;lt;math&amp;gt;\left\langle E\right\rangle&amp;lt;/math&amp;gt; with respect to temperature, giving:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\frac{\partial \left\langle E\right\rangle}{\partial T} = \frac{\Sigma \epsilon_{i} \frac{\epsilon_i}{k_BT^2}e^{-\beta \epsilon_{i}}}{\Sigma e^{-\beta \epsilon_{i}}} - \frac{\Sigma \epsilon_i e^{-\beta \epsilon_i}\cdot \frac{\epsilon_i}{k_BT^2}e^{-\beta \epsilon_i}}{(\Sigma e^{-\beta \epsilon_{i}})^2}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\frac{\partial \left\langle E\right\rangle}{\partial T}  = \frac{1}{k_BT^2}\left[\frac{\Sigma \epsilon_i^2 e^{-\beta \epsilon_i}}{\Sigma e^{-\beta \epsilon_i}} - \left(\frac{\Sigma \epsilon_{i} e^{-\beta \epsilon_{i}}}{\Sigma e^{-\beta \epsilon_{i}}}\right)^2\right] &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\frac{\partial \left\langle E\right\rangle}{\partial T}  = \frac{1}{k_BT^2}\left[\left\langle E^2\right\rangle - \left\langle E\right\rangle^2 \right] &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Thus,&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\frac{\partial \left\langle E\right\rangle}{\partial T} = \frac{Var[E]}{k_BT^2} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Heat Capacity versus Temperature===&lt;br /&gt;
Below, a screenshot of the Python script written to produce plots of &amp;lt;math&amp;gt; C_V &amp;lt;/math&amp;gt; against &amp;lt;math&amp;gt; T &amp;lt;/math&amp;gt;, together with the output images of this script.&lt;br /&gt;
 &lt;br /&gt;
[[File:HeatCapScript.PNG]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====2x2====&lt;br /&gt;
[[File:HC2.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====4x4====&lt;br /&gt;
[[File:HC4.png]]&lt;br /&gt;
&lt;br /&gt;
====8x8====&lt;br /&gt;
[[File:HC8.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====16x16====&lt;br /&gt;
[[File:HC16.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====32x32====&lt;br /&gt;
[[File:HC-32.png]]&lt;br /&gt;
&lt;br /&gt;
= Locating the Curie Temperature =&lt;br /&gt;
&lt;br /&gt;
===C++ Data Comparison===&lt;br /&gt;
Below a comparison of the &amp;lt;math&amp;gt; C_V &amp;lt;/math&amp;gt; against &amp;lt;math&amp;gt; T &amp;lt;/math&amp;gt; plot generated for the &amp;lt;math&amp;gt; 2 /times 2&amp;lt;/math&amp;gt; to the corresponding C++ data is offered.&lt;br /&gt;
 &lt;br /&gt;
[[File:CHC2.png]]&lt;br /&gt;
&lt;br /&gt;
The data generated by the ILtemperaturerange.py script is a faithful match to the C++ data. However, this is an exceptional case; the plots for all other lattice sizes were found to be very dissimilar, necessitating polynomial fitting.&lt;br /&gt;
&lt;br /&gt;
==Polyfitting of C++ Data==&lt;br /&gt;
&lt;br /&gt;
===Fitting a Polynomial to the Entire Range===&lt;br /&gt;
The following Python script was written to perform a polynomial fit to the entire range of the graph of &amp;lt;math&amp;gt; C_V &amp;lt;/math&amp;gt; against &amp;lt;math&amp;gt; T &amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:HeatCapPoly.PNG]]&lt;br /&gt;
&lt;br /&gt;
Below, the result of the polyfit to the &amp;lt;math&amp;gt; 2/times2&amp;lt;/math&amp;gt; lattice data is offered (for comparison to the previous, non-fitted example).&lt;br /&gt;
&lt;br /&gt;
[[File:15Polyc2x2.png]]&lt;br /&gt;
&lt;br /&gt;
Polynomials with 5 terms and above were found to match the data in the vicinity of the critical region considerably well. Below 7 terms, the &#039;&#039;tails&#039;&#039; of the plot were matched poorly. In the above example, a polynomial of 15 terms was fit to the data.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Fitting a Polynomial to the Critical Region===&lt;br /&gt;
&lt;br /&gt;
The following Python script was written to perform a polynomial fit to the region of interest (the &#039;&#039;critical&#039;&#039; region) of the plots of &amp;lt;math&amp;gt; C_V &amp;lt;/math&amp;gt; against &amp;lt;math&amp;gt; T &amp;lt;/math&amp;gt; to facilitate the discovery of &amp;lt;math&amp;gt; T_C &amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
[[File:CapPolyCrit.PNG]]&lt;br /&gt;
&lt;br /&gt;
An example of the result returned by the script is offered below for the C++ data for the &amp;lt;math&amp;gt; 16\times16&amp;lt;/math&amp;gt; lattice.&lt;br /&gt;
&lt;br /&gt;
[[File:HHCPC16,2.6-2.1,5.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Finding the Peak C Values for Each Lattice Size===&lt;br /&gt;
Below, a screenshot of the code used to obtain the temperatures at which the maximum values of C occured is presented for each lattice size. The temperatures themselves are also featured on the image.&lt;br /&gt;
&lt;br /&gt;
[[File:Tmaxes.PNG]]&lt;br /&gt;
&lt;br /&gt;
The range of lattice sizes and their associated &amp;lt;math&amp;gt;T_{C} &amp;lt;/math&amp;gt; values were exported to a [[Media:Tmax.txt|text file]], enabling a plot to be created.&lt;br /&gt;
&lt;br /&gt;
[[File:CritTempPlot2.png]]&lt;br /&gt;
&lt;br /&gt;
Subsequently, the scipy.optimize.curve_fit function was used to fit &amp;lt;math&amp;gt;T_{C, L} = \frac{A}{L} + T_{C,\infty}&amp;lt;/math&amp;gt; function to the data obtained. This enabled the estimation the constant &amp;lt;math&amp;gt; A &amp;lt;/math&amp;gt; and the value of &amp;lt;math&amp;gt;T_{C} &amp;lt;/math&amp;gt; at &amp;lt;math&amp;gt; \frac{A}{L} = 0&amp;lt;/math&amp;gt;, otherwise &amp;lt;math&amp;gt; T_{C,\infty}&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
[[File:FindingTc.PNG]]&lt;br /&gt;
&lt;br /&gt;
A value of &amp;lt;math&amp;gt; T_{C,\infty} = 2.2799 &amp;lt;/math&amp;gt; was obtained. A comparison to the literature[https://en.wikipedia.org/wiki/Square-lattice_Ising_model#Critical_temperature] value of &amp;lt;math&amp;gt;2.269&amp;lt;/math&amp;gt; reveals a percentage error value of only &amp;lt;math&amp;gt; 0.47% &amp;lt;/math&amp;gt;. Surprisingly, the investigation of lattices in the given size range was enough to capture the theoretical behaviour of an infinite lattice. As explained by Frenkel and Smit, the implementation of periodic boundary conditions enables the simulation of an infinite bulk (or infinite adjacent lattices) surrounding the single lattice under scrutiny. The agreement of the experimental and theoretical values for &amp;lt;math&amp;gt; T_{C,\infty} &amp;lt;/math&amp;gt; prove the effectiveness of this idea.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
A likely source of error arises from the polynomial fitting of the data. The peaks in &amp;lt;math&amp;gt; C_V &amp;lt;/math&amp;gt; against &amp;lt;math&amp;gt; T &amp;lt;/math&amp;gt; were far more sharp than the broad peaks of the polynomial functions used to fit them. In several cases, the polynomial peak was a slight, yet discernible overestimate of the true peak. This has resulted in an overestimation of the final &amp;lt;math&amp;gt; T_{C,\infty} &amp;lt;/math&amp;gt; value. Fitting a function with a sharper peak (e.g. a Kronecker delta function) to the critical region could overcome this overestimation and provide a more faithful final value.&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
* Frenkel, Daan, et al. Understanding Molecular Simulation : From Algorithms to Applications, Elsevier Science &amp;amp; Technology, 2001&lt;br /&gt;
&lt;br /&gt;
* Krieger, M. Constitutions of matter : Mathematically modeling the most everyday of physical phenomena. Chicago ; London: University of Chicago Press, 1996&lt;br /&gt;
&lt;br /&gt;
* https://en.wikipedia.org/wiki/Square-lattice_Ising_model Accessed 13-11-18&lt;/div&gt;</summary>
		<author><name>Jj1516</name></author>
	</entry>
	<entry>
		<id>https://chemwiki.ch.ic.ac.uk/index.php?title=Rep:JJ1516Ising&amp;diff=737028</id>
		<title>Rep:JJ1516Ising</title>
		<link rel="alternate" type="text/html" href="https://chemwiki.ch.ic.ac.uk/index.php?title=Rep:JJ1516Ising&amp;diff=737028"/>
		<updated>2018-11-21T10:57:28Z</updated>

		<summary type="html">&lt;p&gt;Jj1516: /* Magnetisation at 0K */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Introduction to the Ising Model =&lt;br /&gt;
&lt;br /&gt;
== The Model ==&lt;br /&gt;
&lt;br /&gt;
=== Minimum Energy State ===&lt;br /&gt;
====Minimum Interaction Energy====&lt;br /&gt;
The interaction energy of an Ising lattice is given by:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;E = -\frac{1}{2}J\displaystyle\sum_{i}^{N} \displaystyle\sum_{j\;\in\;{neighbours}\;(i)} \!\!\!\!\!\!\!\!\!\!\!\!s_{i}s_{j}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In an Ising lattice with D dimensions and periodic boundary conditions, a given spin &amp;lt;math&amp;gt; s_i&amp;lt;/math&amp;gt; has 2D neighbours.&lt;br /&gt;
&lt;br /&gt;
The minimum interaction energy is achieved when all spins in the lattice are aligned (all ↑ or all ↓). As  such, any spin &amp;lt;math&amp;gt; s_i&amp;lt;/math&amp;gt; must be aligned with all 2D of its neighbours. That is, &amp;lt;math&amp;gt;s_{i}s_{j} = 1&amp;lt;/math&amp;gt; for all &amp;lt;math&amp;gt;j&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Therefore, for any &amp;lt;math&amp;gt; s_i&amp;lt;/math&amp;gt;, the sum of its interactions is &amp;lt;math&amp;gt;\displaystyle\sum_{j\;\in\;{neighbours}\;(i)} \!\!\!\!\!\!\!\!\!\!\!\!s_{i}s_{j} = 2D &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
As this is true for all N spins in the lattice, it follows that &amp;lt;math&amp;gt;\displaystyle\sum_{i}^{N} 2D = 2DN&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Thus the minimum interaction energy is given by:&lt;br /&gt;
&lt;br /&gt;
:&amp;lt;math&amp;gt;E_{min} = -\frac{1}{2}J\cdot2DN = - DNJ &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Entropy of the Minimum Energy State====&lt;br /&gt;
&lt;br /&gt;
The entropy of a state is given by:&lt;br /&gt;
&lt;br /&gt;
:&amp;lt;math&amp;gt;S = k\; ln\; \Omega &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Where &amp;lt;math&amp;gt; \Omega &amp;lt;/math&amp;gt; is the multiplicity of the state, the number of degenerate configurations of said state. The minimum energy state is achievable with all spins ↑ or with all spins ↓. In the absence of an external magnetic field, these configurations are degenerate and indistinguishable giving &amp;lt;math&amp;gt; \Omega = 2 &amp;lt;/math&amp;gt; for this state. Therefore,&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; S_{E_{min}}  = k_{B}\; ln\; 2 = 0.693k_{B} = 9.57 \times 10^{-24} J\!\cdot\!\! K^{-1}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Phase Transitions ==&lt;br /&gt;
&lt;br /&gt;
=== Changes to Minimum Energy Configuration ===&lt;br /&gt;
&lt;br /&gt;
====Energy Change ====&lt;br /&gt;
The energy change &amp;lt;math&amp;gt; \Delta E&amp;lt;/math&amp;gt; associated with a single spin &#039;flip&#039; from the lowest energy onfiguration may be calculated by considering the change in the interaction energy with the spin&#039;s neighbours.&lt;br /&gt;
&lt;br /&gt;
Let &amp;lt;math&amp;gt; D = 3, N = 1000 &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\Delta{E} = E_1 - E_0&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;E_1&amp;lt;/math&amp;gt; Interaction energy after one spin has been &#039;flipped&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;E_0&amp;lt;/math&amp;gt; Lowest energy configuration&lt;br /&gt;
&lt;br /&gt;
[[Image:Task 2 table.PNG]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\displaystyle\sum_{interactions} = -2D + 2D(2D-2) + 2D[N-(2D+1)] &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; = 2DN - 8D &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;E_1 = \displaystyle-\frac{1}{2}J\;\sum_{interactions} = 4DJ - DNJ&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\Delta{E} = E_1 - E_0 = 4DJ - DNJ + DNJ = +4DJ = +12J&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This energy change is independent of &amp;lt;math&amp;gt; N&amp;lt;/math&amp;gt; and depends only on the dimension size and the coupling constant &amp;lt;math&amp;gt; J &amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
In this calculation, the following assumption has been made.&lt;br /&gt;
&lt;br /&gt;
* The lattice dimensions are infinite relative to the size of each cell&lt;br /&gt;
&lt;br /&gt;
This allows &#039;&#039;&#039;any&#039;&#039;&#039; cell to be treated as the centre of the lattice. As every cell interacts with 2D neighbours, flipping any cell in the minimum energy configuration results in the same energy change. Alternatively, the periodic boundary conditions of the Ising model remove the necessity for such an assumption. As a consequence, the absence of &amp;lt;math&amp;gt; N &amp;lt;/math&amp;gt; from the resulting energy change is justified.&lt;br /&gt;
&lt;br /&gt;
====Entropy Change====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; S = k_{B}\; ln\; \Omega &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\Omega = \displaystyle\frac{N!}{{N_{\uparrow}!}{N_{\downarrow}!}}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Where &amp;lt;math&amp;gt;N_{x}!&amp;lt;/math&amp;gt; denotes the factorial of the number of spins in spin state &amp;lt;math&amp;gt;x&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\Delta{S} = k_{B}\;ln\;\left(\displaystyle\frac{\Omega_{2}}{\Omega_{1}}\right)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\Omega_{2} = \frac{1000!}{999!1!} = 1000&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \Omega_{1} = \frac{1000!}{1000!} = 1&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\Delta{S} = k_{B}\;ln\;1000 = 9.54 \times 10^{-23} JK^{-1}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\Delta{S_{mol}} = N_{A}k_{B}\;ln\;1000 = 57.4 \,JK^{-1}mol^{-1}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Magnetisation Values of 1D and 2D Lattices===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;M = \sum_i s_i&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====1D Lattice Magnetisation====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;M_{1D} =\;\;+1&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====2D Lattice Magnetisation====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;M_{2D} =\;\;+1&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Magnetisation at 0K====&lt;br /&gt;
&lt;br /&gt;
At 0K, no theral energy is available to overcome the energetic barriers to spin flipping. Considering the Hemholtz free energy:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; A = E - TS &amp;lt;/math&amp;gt; &lt;br /&gt;
&lt;br /&gt;
A temperature of 0K nullifies the entropic contribution to the free energy. Thus the energetic driving force (which maximises parallel spin interactions) dominates the entropic driving force (which maximises multiplicity of lattice states). For an Ising Lattice with D =  3, N = 1000 at 0K, the alignment of all spins results in the minimum energy configuration  and an overall magnetisation of &amp;lt;math&amp;gt; M = \pm 1000 &amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
= Calculating the Energy and Magnetisation =&lt;br /&gt;
==Modifying the Files==&lt;br /&gt;
&lt;br /&gt;
===Energy and Magnetisation Functions===&lt;br /&gt;
&lt;br /&gt;
====Energy===&lt;br /&gt;
[[File:First_Ene_Method.PNG]]&lt;br /&gt;
&lt;br /&gt;
The above energy method segments a given lattice into lattice cells on the edges, corners or in the bulk of the lattice and calculates the energy interactions with its neighbours as appropriate.&lt;br /&gt;
&lt;br /&gt;
====Magnetisation====&lt;br /&gt;
[[File:First_Mag_Method.PNG]]&lt;br /&gt;
&lt;br /&gt;
The magnetisation method loops over all elements in the array representing the Ising lattice and adds the value of the spin to the magnetisation variable.&lt;br /&gt;
&lt;br /&gt;
==Testing the Files==&lt;br /&gt;
&lt;br /&gt;
===ILCheck.py===&lt;br /&gt;
&lt;br /&gt;
[[File:ILChecks.PNG]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Above, the results of the ILcheck.py script are presented.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= Introduction to the Monte Carlo Simulation =&lt;br /&gt;
==Average Energy and Magnetisation==&lt;br /&gt;
===Configurations of a 100 Spin System===&lt;br /&gt;
For a system of two spins, 4 configurations are possible (↑↑, ↓↓, ↑↓, ↓↑) i.e. &amp;lt;math&amp;gt;2^{2}&amp;lt;/math&amp;gt;. For a system of 100 spins, there are &amp;lt;math&amp;gt;2^{100}&amp;lt;/math&amp;gt; configurations. In the first example, the ↑↑ and ↓↓ are degenerate, as are the ↑↓ and ↓↑ configurations. Therefore, dividing the number of possible configurations by the multiplicity of each configuration (&amp;lt;math&amp;gt;2&amp;lt;/math&amp;gt;) gives the number of non-degenerate configurations. As previously stated, degenerate configurations are indistinguishable in the absence of an external magnetic field.&lt;br /&gt;
&lt;br /&gt;
For 100 spins, this gives &amp;lt;math&amp;gt;\displaystyle\frac{2^{100}}{2} = 6.338 \times 10^{29} &amp;lt;/math&amp;gt; distinguishable configurations.&lt;br /&gt;
&lt;br /&gt;
If processing speed permits &amp;lt;math&amp;gt; 1 \times 10^{9}&amp;lt;/math&amp;gt; calculations each second, the evaluation of a single value of &amp;lt;math&amp;gt;\left\langle M\right\rangle_T&amp;lt;/math&amp;gt; would last &amp;lt;math&amp;gt; 6.338 \times 10^{20} &amp;lt;/math&amp;gt; seconds or &amp;lt;math&amp;gt; 1458 &amp;lt;/math&amp;gt; times the age of the Universe!&lt;br /&gt;
&lt;br /&gt;
==Modifying IsingLattice.py==&lt;br /&gt;
&lt;br /&gt;
===Monte Carlo and Statistics Methods===&lt;br /&gt;
[[File:Monte_Carlo.PNG]]&lt;br /&gt;
&lt;br /&gt;
[[File:stats.PNG]]&lt;br /&gt;
&lt;br /&gt;
The Metropolis Monte Carlo (MMC) algorithm provides a computationally inexpensive path from random initial states to the minimum free energy states of the Ising lattices generated. First, a random 2D Ising lattice is generated. A single random spin within this lattice is &amp;quot;flipped&amp;quot; and the resulting (internal) energy change between these states is measured. Recalling the relationship between the Hemholtz free energy, internal energy and entropy, it follows that a decrease in internal energy also lowers the free energy of the system: thus the configuration change is accepted.&lt;br /&gt;
&lt;br /&gt;
In the case that the spin &amp;quot;flip&amp;quot; does not lower the internal energy, the MMC algorithm tests this configuration change against the Boltzman factor. In the canonical (NVT) ensemble, the free energy of the system is given by:&lt;br /&gt;
&lt;br /&gt;
:&amp;lt;math&amp;gt;A = -k_{B}T\,lnZ_{NVT} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
where Z is the canonical partition function which depends upon &amp;lt;math&amp;gt; e^{-\frac{\Delta E}{k_BT}} &amp;lt;/math&amp;gt;, the Boltzman factor. By choosing a random value in the interval [0,1)from a continuous uniformm probability distribution and rejecting any value of the Boltzman factor less than this value, the MMC algorithm allows for configuration changes with small, positive internal energy changes if they conform to the Boltzman probability distribution. Alternatively, the MMC allows small perturbations to the internal energy which prevents the system from settling in a metastable internal energy minimum and instead, ensures that the system equilibrates around the &#039;&#039;true&#039;&#039; free energy minimum.&lt;br /&gt;
&lt;br /&gt;
===Spontaneous Magnetisation===&lt;br /&gt;
&lt;br /&gt;
Below the Curie Temperature, &amp;lt;math&amp;gt; T_{C} &amp;lt;/math&amp;gt;, the energetic driving force dominates the entropic driving force, resulting in a highly ordered system and an overall magnetisation. The spins of the system align in order to maximise favourable coupling interactions rather than adopting a less ordered configuration of higher multiplicity. Therefore, when &amp;lt;math&amp;gt;T &amp;lt; T_C&amp;lt;/math&amp;gt;, the most probable configurations have an overall magnetisation resulting in &amp;lt;math&amp;gt;\left\langle M\right\rangle \neq 0&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
The plots of magnetisation per spin and energy per spin obtained from ILanim.py support this prediction. Below, the plots show that upon equilibration, the system adopts the minimum energy per spin: &amp;lt;math&amp;gt;E_{min_{spin}} = \frac{-NDJ}{N} = -DJ = -2&amp;lt;/math&amp;gt; and exhibits the maximum magnitude of magnetisation per spin: &amp;lt;math&amp;gt;|M_{spin}| = 1&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:2T=1.0.png]]&lt;br /&gt;
[[File:T=1.0.png]]&lt;br /&gt;
[[File:3T=1.0.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
An unknown system error prevented the statistics() function from printing the average values.&lt;br /&gt;
&lt;br /&gt;
=Accelerating the Code=&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Initial Method Speeds===&lt;br /&gt;
Taking 10 repeat measurements for the time taken to perform 2000 Monte Carlo steps resulted in&lt;br /&gt;
&lt;br /&gt;
* An average time of  &amp;lt;math&amp;gt;11.7s&amp;lt;/math&amp;gt; &lt;br /&gt;
* A standard error of &amp;lt;math&amp;gt;0.020s&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Updating Measurement===&lt;br /&gt;
&lt;br /&gt;
NOTE: ILtimetrial.py has been modified to:&lt;br /&gt;
* Perform a requested number of &#039;2000 Monte Carlo Step&#039; measurements&lt;br /&gt;
* Record these measurements in a CSV file&lt;br /&gt;
* Return the mean measuremd time and the Standard Error i.e.   &amp;lt;math&amp;gt; \frac{\sigma}{n} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:TimeTrialMethod.PNG]]&lt;br /&gt;
&lt;br /&gt;
===Updating Energy and Magnetisation Methods===&lt;br /&gt;
[[File:New_Mag_Method.PNG]]&lt;br /&gt;
[[File:New_Ene_Method.PNG]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Updated Method Speeds===&lt;br /&gt;
[[File:TimeTrial.PNG]]&lt;br /&gt;
&lt;br /&gt;
Taking 30 measurements of the time taken to perform 2000 Monte Carlo Steps resulted in:&lt;br /&gt;
&lt;br /&gt;
* An average time of &amp;lt;math&amp;gt;\displaystyle{0.87s}&amp;lt;/math&amp;gt;&lt;br /&gt;
* A standard error of &amp;lt;math&amp;gt;2.5 \times 10^{-3}s&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This represents a 93% decrease in the average computation time from the initial methods.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=The Effect of Temperature=&lt;br /&gt;
&lt;br /&gt;
==Correcting the Averaging  Code==&lt;br /&gt;
&lt;br /&gt;
===Finding a Delay Value===&lt;br /&gt;
To quickly find a value for &amp;lt;math&amp;gt; N_{d}&amp;lt;/math&amp;gt;, the minimum number of cycles typically needed for the equilibration of a system of within the lattice and temperature ranges of interest, it was assumed that:&lt;br /&gt;
&lt;br /&gt;
* Larger lattices would require more Monte Carlo steps to reach equilibrium from their initial, random configurations&lt;br /&gt;
&lt;br /&gt;
* Lattices at lower temperatures would require more Monte Carlo steps to reach equilibrium from their initial, random configurations.&lt;br /&gt;
&lt;br /&gt;
Therefore, an initial value for &amp;lt;math&amp;gt; N_{d}&amp;lt;/math&amp;gt; was found for a &amp;lt;math&amp;gt; 128\times128 &amp;lt;/math&amp;gt; lattice at a temperature of &amp;lt;math&amp;gt;0.5&amp;lt;/math&amp;gt; reduced temperature units.&lt;br /&gt;
*&amp;lt;math&amp;gt; N_{d} = 185000 &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
By this number of steps, all smaller lattices at all higher temperatures were found to have equilibrated also. Thus, this value of&amp;lt;math&amp;gt; N_{d}&amp;lt;/math&amp;gt; was accepted as an appropriate delay.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:AFinFrame 128 3e5 T= 0.5line.png|400px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
For the 128x128 lattices at T=0.5, equilibration was ensured from 185000 steps onwards.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Smaller lattices at the same temperature did indeed equilibrate more slowly, but all equilibrated within &amp;lt;math&amp;gt; N_{d}&amp;lt;/math&amp;gt; MC steps.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:AFinFrame 64 3e5 T= 0.5line.png|400px]]&lt;br /&gt;
[[File:AFinFrame 32 3e5 T= 0.5line2.png|400px]]&lt;br /&gt;
[[File:AFinFrame 16 3e5 T= 0.5line2.png|400px]]&lt;br /&gt;
[[File:AFinFrame 8 3e5 T= 0.5line.png|400px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The figure below shows the modifications made to IsingLattice.py to incorporate the &amp;lt;math&amp;gt; N_{d} &amp;lt;/math&amp;gt; step delay.&lt;br /&gt;
&lt;br /&gt;
==Running over a Range of Temperatures==&lt;br /&gt;
&lt;br /&gt;
To examine the effect of temperature on the average energy &amp;lt;math&amp;gt; \left\langle E\right\rangle &amp;lt;/math&amp;gt; and average magnetisation &amp;lt;math&amp;gt; \left\langle M\right\rangle &amp;lt;/math&amp;gt; of Ising lattices at equilibrium, the following parameters were used:&lt;br /&gt;
&lt;br /&gt;
* Temperature Range: &amp;lt;math&amp;gt;  0.5 - 5 &amp;lt;/math&amp;gt; reduced units&lt;br /&gt;
* Temperature Interval: &amp;lt;math&amp;gt;0.01&amp;lt;/math&amp;gt; reduced units (&amp;lt;math&amp;gt;450&amp;lt;/math&amp;gt; temperature values)&lt;br /&gt;
* Number of MMC Steps per Temperature value: &amp;lt;math&amp;gt; 2 \times 10^5 &amp;lt;/math&amp;gt; with the aforementioned value of &amp;lt;math&amp;gt; N_{d} = 1.85 \times 10^5 &amp;lt;/math&amp;gt; Monte Carlo steps&lt;br /&gt;
* Lattice Sizes:  &amp;lt;math&amp;gt; 2 \times 2 &amp;lt;/math&amp;gt;, &amp;lt;math&amp;gt; 4 \times 4 &amp;lt;/math&amp;gt; , &amp;lt;math&amp;gt; 8 \times 8 &amp;lt;/math&amp;gt; , &amp;lt;math&amp;gt; 16 \times 16 &amp;lt;/math&amp;gt; , &amp;lt;math&amp;gt; 32 \times 32 &amp;lt;/math&amp;gt; , &amp;lt;math&amp;gt; 64 \times 64 &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Plots of  &amp;lt;math&amp;gt; \left\langle E\right\rangle &amp;lt;/math&amp;gt; and  &amp;lt;math&amp;gt; \left\langle M\right\rangle &amp;lt;/math&amp;gt; per spin as versus temperature are presented below for each lattice size. Errorbars have been implemented to demonstrate how &#039;&#039;well-behaved&#039;&#039; lattice systems of each size are at each temperature, that is, how temperature and lattice size affect the size of the variations in the expected values. For the error calculations, the standard errors, &amp;lt;math&amp;gt; \sigma_\bar{X} &amp;lt;/math&amp;gt;,  in &amp;lt;math&amp;gt; \left\langle E\right\rangle &amp;lt;/math&amp;gt; and  &amp;lt;math&amp;gt; \left\langle M\right\rangle &amp;lt;/math&amp;gt; per spin have been used:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====8x8====&lt;br /&gt;
&lt;br /&gt;
[[File:8x8e+error.png]] [[File:8x8m+error.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
A Python script has been written to generate a plot of &amp;lt;math&amp;gt;\left\langle E\right\rangle&amp;lt;/math&amp;gt; or &amp;lt;math&amp;gt;\left\langle M\right\rangle&amp;lt;/math&amp;gt; against temperature based upon user input. A screenshot of this code has been inserted below.&lt;br /&gt;
&lt;br /&gt;
[[File:ExpectedvsTemp.PNG|200px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=The Effect of System Size=&lt;br /&gt;
&lt;br /&gt;
==Scaling the System Size==&lt;br /&gt;
&lt;br /&gt;
===More Lattice Sizes===&lt;br /&gt;
&lt;br /&gt;
====2x2====&lt;br /&gt;
[[File:2x2e+error.png]] [[File:2x2m+error.png]]&lt;br /&gt;
&lt;br /&gt;
====4x4====&lt;br /&gt;
[[File:4x4e+error.png]] [[File:4x4m+error.png]]&lt;br /&gt;
&lt;br /&gt;
====16x16====&lt;br /&gt;
[[File:16x16e+error.png]] [[File:16x16m+error.png]]&lt;br /&gt;
&lt;br /&gt;
====32x32====&lt;br /&gt;
[[File:32x32e+error.png]] [[File:32x32m+error.png]]&lt;br /&gt;
&lt;br /&gt;
====64x64====&lt;br /&gt;
[[File:64x64e+error.png]] [[File:64x64m+error.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Scrutiny of the plots of average energy per spin for each lattice size reveals an increase in the errorbar width with increasing lattice size. This is most notable in the low temperature region of the plots. Between the &amp;lt;math&amp;gt; 8\times8 &amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt; 16\times16 &amp;lt;/math&amp;gt; lattices, the long range fluctuations become suddenly prominent. The &amp;lt;math&amp;gt;16\times16&amp;lt;/math&amp;gt; lattice is the first (in the range of sizes tested)to clearly capture these fluctuations.&lt;br /&gt;
&lt;br /&gt;
=Determining the Heat Capacity=&lt;br /&gt;
&lt;br /&gt;
==Calculating the Heat Capacity==&lt;br /&gt;
&lt;br /&gt;
===Heat Capacity Derivation===&lt;br /&gt;
Working in the canonical ensemble (constant volume), the heat capacity &amp;lt;math&amp;gt; C_V &amp;lt;/math&amp;gt; is given by:&lt;br /&gt;
&lt;br /&gt;
:&amp;lt;math&amp;gt;C_V = \frac{\partial \left\langle E\right\rangle}{\partial T}_V&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
where &amp;lt;math&amp;gt;\left\langle E\right\rangle&amp;lt;/math&amp;gt; is the average total energy or expected value of the internal energy of the system.&lt;br /&gt;
&lt;br /&gt;
: &amp;lt;math&amp;gt; \left\langle E\right\rangle = - \frac{\partial ln Q}{\partial \beta} = -\frac{1}{Q}\frac{\partial Q}{\partial \beta} &amp;lt;/math&amp;gt;&lt;br /&gt;
where &amp;lt;math&amp;gt; Q&amp;lt;/math&amp;gt; is the partition function for the system of N interacting spins.&lt;br /&gt;
&lt;br /&gt;
By evaluating the second form of the partial derivative with respect to &amp;lt;math&amp;gt; \beta&amp;lt;/math&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \left\langle E\right\rangle = -\frac{1}{Q}\frac{\partial Q}{\partial \beta} = \frac{\Sigma \epsilon_{i} e^{-\beta \epsilon_{i}}}{\Sigma e^{-\beta \epsilon_{i}}} &amp;lt;/math&amp;gt; &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Applying the product rule enables the differentiation of this expression for &amp;lt;math&amp;gt;\left\langle E\right\rangle&amp;lt;/math&amp;gt; with respect to temperature, giving:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\frac{\partial \left\langle E\right\rangle}{\partial T} = \frac{\Sigma \epsilon_{i} \frac{\epsilon_i}{k_BT^2}e^{-\beta \epsilon_{i}}}{\Sigma e^{-\beta \epsilon_{i}}} - \frac{\Sigma \epsilon_i e^{-\beta \epsilon_i}\cdot \frac{\epsilon_i}{k_BT^2}e^{-\beta \epsilon_i}}{(\Sigma e^{-\beta \epsilon_{i}})^2}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\frac{\partial \left\langle E\right\rangle}{\partial T}  = \frac{1}{k_BT^2}\left[\frac{\Sigma \epsilon_i^2 e^{-\beta \epsilon_i}}{\Sigma e^{-\beta \epsilon_i}} - \left(\frac{\Sigma \epsilon_{i} e^{-\beta \epsilon_{i}}}{\Sigma e^{-\beta \epsilon_{i}}}\right)^2\right] &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\frac{\partial \left\langle E\right\rangle}{\partial T}  = \frac{1}{k_BT^2}\left[\left\langle E^2\right\rangle - \left\langle E\right\rangle^2 \right] &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Thus,&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\frac{\partial \left\langle E\right\rangle}{\partial T} = \frac{Var[E]}{k_BT^2} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Heat Capacity versus Temperature===&lt;br /&gt;
Below, a screenshot of the Python script written to produce plots of &amp;lt;math&amp;gt; C_V &amp;lt;/math&amp;gt; against &amp;lt;math&amp;gt; T &amp;lt;/math&amp;gt;, together with the output images of this script.&lt;br /&gt;
 &lt;br /&gt;
[[File:HeatCapScript.PNG]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====2x2====&lt;br /&gt;
[[File:HC2.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====4x4====&lt;br /&gt;
[[File:HC4.png]]&lt;br /&gt;
&lt;br /&gt;
====8x8====&lt;br /&gt;
[[File:HC8.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====16x16====&lt;br /&gt;
[[File:HC16.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====32x32====&lt;br /&gt;
[[File:HC-32.png]]&lt;br /&gt;
&lt;br /&gt;
= Locating the Curie Temperature =&lt;br /&gt;
&lt;br /&gt;
===C++ Data Comparison===&lt;br /&gt;
Below a comparison of the &amp;lt;math&amp;gt; C_V &amp;lt;/math&amp;gt; against &amp;lt;math&amp;gt; T &amp;lt;/math&amp;gt; plot generated for the &amp;lt;math&amp;gt; 2 /times 2&amp;lt;/math&amp;gt; to the corresponding C++ data is offered.&lt;br /&gt;
 &lt;br /&gt;
[[File:CHC2.png]]&lt;br /&gt;
&lt;br /&gt;
The data generated by the ILtemperaturerange.py script is a faithful match to the C++ data. However, this is an exceptional case; the plots for all other lattice sizes were found to be very dissimilar, necessitating polynomial fitting.&lt;br /&gt;
&lt;br /&gt;
==Polyfitting of C++ Data==&lt;br /&gt;
&lt;br /&gt;
===Fitting a Polynomial to the Entire Range===&lt;br /&gt;
The following Python script was written to perform a polynomial fit to the entire range of the graph of &amp;lt;math&amp;gt; C_V &amp;lt;/math&amp;gt; against &amp;lt;math&amp;gt; T &amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:HeatCapPoly.PNG]]&lt;br /&gt;
&lt;br /&gt;
Below, the result of the polyfit to the &amp;lt;math&amp;gt; 2/times2&amp;lt;/math&amp;gt; lattice data is offered (for comparison to the previous, non-fitted example).&lt;br /&gt;
&lt;br /&gt;
[[File:15Polyc2x2.png]]&lt;br /&gt;
&lt;br /&gt;
Polynomials with 5 terms and above were found to match the data in the vicinity of the critical region considerably well. Below 7 terms, the &#039;&#039;tails&#039;&#039; of the plot were matched poorly. In the above example, a polynomial of 15 terms was fit to the data.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Fitting a Polynomial to the Critical Region===&lt;br /&gt;
&lt;br /&gt;
The following Python script was written to perform a polynomial fit to the region of interest (the &#039;&#039;critical&#039;&#039; region) of the plots of &amp;lt;math&amp;gt; C_V &amp;lt;/math&amp;gt; against &amp;lt;math&amp;gt; T &amp;lt;/math&amp;gt; to facilitate the discovery of &amp;lt;math&amp;gt; T_C &amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
[[File:CapPolyCrit.PNG]]&lt;br /&gt;
&lt;br /&gt;
An example of the result returned by the script is offered below for the C++ data for the &amp;lt;math&amp;gt; 16\times16&amp;lt;/math&amp;gt; lattice.&lt;br /&gt;
&lt;br /&gt;
[[File:HHCPC16,2.6-2.1,5.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Finding the Peak C Values for Each Lattice Size===&lt;br /&gt;
Below, a screenshot of the code used to obtain the temperatures at which the maximum values of C occured is presented for each lattice size. The temperatures themselves are also featured on the image.&lt;br /&gt;
&lt;br /&gt;
[[File:Tmaxes.PNG]]&lt;br /&gt;
&lt;br /&gt;
The range of lattice sizes and their associated &amp;lt;math&amp;gt;T_{C} &amp;lt;/math&amp;gt; values were exported to a [[Media:Tmax.txt|text file]], enabling a plot to be created.&lt;br /&gt;
&lt;br /&gt;
[[File:CritTempPlot2.png]]&lt;br /&gt;
&lt;br /&gt;
Subsequently, the scipy.optimize.curve_fit function was used to fit &amp;lt;math&amp;gt;T_{C, L} = \frac{A}{L} + T_{C,\infty}&amp;lt;/math&amp;gt; function to the data obtained. This enabled the estimation the constant &amp;lt;math&amp;gt; A &amp;lt;/math&amp;gt; and the value of &amp;lt;math&amp;gt;T_{C} &amp;lt;/math&amp;gt; at &amp;lt;math&amp;gt; \frac{A}{L} = 0&amp;lt;/math&amp;gt;, otherwise &amp;lt;math&amp;gt; T_{C,\infty}&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
[[File:FindingTc.PNG]]&lt;br /&gt;
&lt;br /&gt;
A value of &amp;lt;math&amp;gt; T_{C,\infty} = 2.2799 &amp;lt;/math&amp;gt; was obtained. A comparison to the literature[https://en.wikipedia.org/wiki/Square-lattice_Ising_model#Critical_temperature] value of &amp;lt;math&amp;gt;2.269&amp;lt;/math&amp;gt; reveals a percentage error value of only &amp;lt;math&amp;gt; 0.47% &amp;lt;/math&amp;gt;. Surprisingly, the investigation of lattices in the given size range was enough to capture the theoretical behaviour of an infinite lattice. As explained by Frenkel and Smit, the implementation of periodic boundary conditions enables the simulation of an infinite bulk (or infinite adjacent lattices) surrounding the single lattice under scrutiny. The agreement of the experimental and theoretical values for &amp;lt;math&amp;gt; T_{C,\infty} &amp;lt;/math&amp;gt; prove the effectiveness of this idea.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
A likely source of error arises from the polynomial fitting of the data. The peaks in &amp;lt;math&amp;gt; C_V &amp;lt;/math&amp;gt; against &amp;lt;math&amp;gt; T &amp;lt;/math&amp;gt; were far more sharp than the broad peaks of the polynomial functions used to fit them. In several cases, the polynomial peak was a slight, yet discernible overestimate of the true peak. This has resulted in an overestimation of the final &amp;lt;math&amp;gt; T_{C,\infty} &amp;lt;/math&amp;gt; value. Fitting a function with a sharper peak (e.g. a Kronecker delta function) to the critical region could overcome this overestimation and provide a more faithful final value.&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
* Frenkel, Daan, et al. Understanding Molecular Simulation : From Algorithms to Applications, Elsevier Science &amp;amp; Technology, 2001&lt;br /&gt;
&lt;br /&gt;
* Krieger, M. Constitutions of matter : Mathematically modeling the most everyday of physical phenomena. Chicago ; London: University of Chicago Press, 1996&lt;br /&gt;
&lt;br /&gt;
* https://en.wikipedia.org/wiki/Square-lattice_Ising_model Accessed 13-11-18&lt;/div&gt;</summary>
		<author><name>Jj1516</name></author>
	</entry>
	<entry>
		<id>https://chemwiki.ch.ic.ac.uk/index.php?title=Rep:JJ1516Ising&amp;diff=737026</id>
		<title>Rep:JJ1516Ising</title>
		<link rel="alternate" type="text/html" href="https://chemwiki.ch.ic.ac.uk/index.php?title=Rep:JJ1516Ising&amp;diff=737026"/>
		<updated>2018-11-21T10:56:49Z</updated>

		<summary type="html">&lt;p&gt;Jj1516: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Introduction to the Ising Model =&lt;br /&gt;
&lt;br /&gt;
== The Model ==&lt;br /&gt;
&lt;br /&gt;
=== Minimum Energy State ===&lt;br /&gt;
====Minimum Interaction Energy====&lt;br /&gt;
The interaction energy of an Ising lattice is given by:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;E = -\frac{1}{2}J\displaystyle\sum_{i}^{N} \displaystyle\sum_{j\;\in\;{neighbours}\;(i)} \!\!\!\!\!\!\!\!\!\!\!\!s_{i}s_{j}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In an Ising lattice with D dimensions and periodic boundary conditions, a given spin &amp;lt;math&amp;gt; s_i&amp;lt;/math&amp;gt; has 2D neighbours.&lt;br /&gt;
&lt;br /&gt;
The minimum interaction energy is achieved when all spins in the lattice are aligned (all ↑ or all ↓). As  such, any spin &amp;lt;math&amp;gt; s_i&amp;lt;/math&amp;gt; must be aligned with all 2D of its neighbours. That is, &amp;lt;math&amp;gt;s_{i}s_{j} = 1&amp;lt;/math&amp;gt; for all &amp;lt;math&amp;gt;j&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Therefore, for any &amp;lt;math&amp;gt; s_i&amp;lt;/math&amp;gt;, the sum of its interactions is &amp;lt;math&amp;gt;\displaystyle\sum_{j\;\in\;{neighbours}\;(i)} \!\!\!\!\!\!\!\!\!\!\!\!s_{i}s_{j} = 2D &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
As this is true for all N spins in the lattice, it follows that &amp;lt;math&amp;gt;\displaystyle\sum_{i}^{N} 2D = 2DN&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Thus the minimum interaction energy is given by:&lt;br /&gt;
&lt;br /&gt;
:&amp;lt;math&amp;gt;E_{min} = -\frac{1}{2}J\cdot2DN = - DNJ &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Entropy of the Minimum Energy State====&lt;br /&gt;
&lt;br /&gt;
The entropy of a state is given by:&lt;br /&gt;
&lt;br /&gt;
:&amp;lt;math&amp;gt;S = k\; ln\; \Omega &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Where &amp;lt;math&amp;gt; \Omega &amp;lt;/math&amp;gt; is the multiplicity of the state, the number of degenerate configurations of said state. The minimum energy state is achievable with all spins ↑ or with all spins ↓. In the absence of an external magnetic field, these configurations are degenerate and indistinguishable giving &amp;lt;math&amp;gt; \Omega = 2 &amp;lt;/math&amp;gt; for this state. Therefore,&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; S_{E_{min}}  = k_{B}\; ln\; 2 = 0.693k_{B} = 9.57 \times 10^{-24} J\!\cdot\!\! K^{-1}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Phase Transitions ==&lt;br /&gt;
&lt;br /&gt;
=== Changes to Minimum Energy Configuration ===&lt;br /&gt;
&lt;br /&gt;
====Energy Change ====&lt;br /&gt;
The energy change &amp;lt;math&amp;gt; \Delta E&amp;lt;/math&amp;gt; associated with a single spin &#039;flip&#039; from the lowest energy onfiguration may be calculated by considering the change in the interaction energy with the spin&#039;s neighbours.&lt;br /&gt;
&lt;br /&gt;
Let &amp;lt;math&amp;gt; D = 3, N = 1000 &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\Delta{E} = E_1 - E_0&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;E_1&amp;lt;/math&amp;gt; Interaction energy after one spin has been &#039;flipped&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;E_0&amp;lt;/math&amp;gt; Lowest energy configuration&lt;br /&gt;
&lt;br /&gt;
[[Image:Task 2 table.PNG]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\displaystyle\sum_{interactions} = -2D + 2D(2D-2) + 2D[N-(2D+1)] &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; = 2DN - 8D &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;E_1 = \displaystyle-\frac{1}{2}J\;\sum_{interactions} = 4DJ - DNJ&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\Delta{E} = E_1 - E_0 = 4DJ - DNJ + DNJ = +4DJ = +12J&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This energy change is independent of &amp;lt;math&amp;gt; N&amp;lt;/math&amp;gt; and depends only on the dimension size and the coupling constant &amp;lt;math&amp;gt; J &amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
In this calculation, the following assumption has been made.&lt;br /&gt;
&lt;br /&gt;
* The lattice dimensions are infinite relative to the size of each cell&lt;br /&gt;
&lt;br /&gt;
This allows &#039;&#039;&#039;any&#039;&#039;&#039; cell to be treated as the centre of the lattice. As every cell interacts with 2D neighbours, flipping any cell in the minimum energy configuration results in the same energy change. Alternatively, the periodic boundary conditions of the Ising model remove the necessity for such an assumption. As a consequence, the absence of &amp;lt;math&amp;gt; N &amp;lt;/math&amp;gt; from the resulting energy change is justified.&lt;br /&gt;
&lt;br /&gt;
====Entropy Change====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; S = k_{B}\; ln\; \Omega &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\Omega = \displaystyle\frac{N!}{{N_{\uparrow}!}{N_{\downarrow}!}}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Where &amp;lt;math&amp;gt;N_{x}!&amp;lt;/math&amp;gt; denotes the factorial of the number of spins in spin state &amp;lt;math&amp;gt;x&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\Delta{S} = k_{B}\;ln\;\left(\displaystyle\frac{\Omega_{2}}{\Omega_{1}}\right)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\Omega_{2} = \frac{1000!}{999!1!} = 1000&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \Omega_{1} = \frac{1000!}{1000!} = 1&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\Delta{S} = k_{B}\;ln\;1000 = 9.54 \times 10^{-23} JK^{-1}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\Delta{S_{mol}} = N_{A}k_{B}\;ln\;1000 = 57.4 \,JK^{-1}mol^{-1}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Magnetisation Values of 1D and 2D Lattices===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;M = \sum_i s_i&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====1D Lattice Magnetisation====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;M_{1D} =\;\;+1&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====2D Lattice Magnetisation====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;M_{2D} =\;\;+1&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Magnetisation at 0K====&lt;br /&gt;
&lt;br /&gt;
At 0K, no thermal energy is available to overcome the energetic barriers to spin flipping. Considering the Hemholtz free energy:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; A = E - TS &amp;lt;/math&amp;gt; &lt;br /&gt;
&lt;br /&gt;
A temperature of 0K nullifies the entropic contribution to the free energy. Thus the energetic driving force (which maximises parallel spin interactions) dominates the entropic driving force (which maximises multiplicity of lattice states). For an Ising Lattice with D =  3, N = 1000 at 0K, the alignment of all spins results in the minimum energy configuratio  and an overall magnetisation of &amp;lt;math&amp;gt; M = \pm 1000 &amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
= Calculating the Energy and Magnetisation =&lt;br /&gt;
==Modifying the Files==&lt;br /&gt;
&lt;br /&gt;
===Energy and Magnetisation Functions===&lt;br /&gt;
&lt;br /&gt;
====Energy===&lt;br /&gt;
[[File:First_Ene_Method.PNG]]&lt;br /&gt;
&lt;br /&gt;
The above energy method segments a given lattice into lattice cells on the edges, corners or in the bulk of the lattice and calculates the energy interactions with its neighbours as appropriate.&lt;br /&gt;
&lt;br /&gt;
====Magnetisation====&lt;br /&gt;
[[File:First_Mag_Method.PNG]]&lt;br /&gt;
&lt;br /&gt;
The magnetisation method loops over all elements in the array representing the Ising lattice and adds the value of the spin to the magnetisation variable.&lt;br /&gt;
&lt;br /&gt;
==Testing the Files==&lt;br /&gt;
&lt;br /&gt;
===ILCheck.py===&lt;br /&gt;
&lt;br /&gt;
[[File:ILChecks.PNG]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Above, the results of the ILcheck.py script are presented.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= Introduction to the Monte Carlo Simulation =&lt;br /&gt;
==Average Energy and Magnetisation==&lt;br /&gt;
===Configurations of a 100 Spin System===&lt;br /&gt;
For a system of two spins, 4 configurations are possible (↑↑, ↓↓, ↑↓, ↓↑) i.e. &amp;lt;math&amp;gt;2^{2}&amp;lt;/math&amp;gt;. For a system of 100 spins, there are &amp;lt;math&amp;gt;2^{100}&amp;lt;/math&amp;gt; configurations. In the first example, the ↑↑ and ↓↓ are degenerate, as are the ↑↓ and ↓↑ configurations. Therefore, dividing the number of possible configurations by the multiplicity of each configuration (&amp;lt;math&amp;gt;2&amp;lt;/math&amp;gt;) gives the number of non-degenerate configurations. As previously stated, degenerate configurations are indistinguishable in the absence of an external magnetic field.&lt;br /&gt;
&lt;br /&gt;
For 100 spins, this gives &amp;lt;math&amp;gt;\displaystyle\frac{2^{100}}{2} = 6.338 \times 10^{29} &amp;lt;/math&amp;gt; distinguishable configurations.&lt;br /&gt;
&lt;br /&gt;
If processing speed permits &amp;lt;math&amp;gt; 1 \times 10^{9}&amp;lt;/math&amp;gt; calculations each second, the evaluation of a single value of &amp;lt;math&amp;gt;\left\langle M\right\rangle_T&amp;lt;/math&amp;gt; would last &amp;lt;math&amp;gt; 6.338 \times 10^{20} &amp;lt;/math&amp;gt; seconds or &amp;lt;math&amp;gt; 1458 &amp;lt;/math&amp;gt; times the age of the Universe!&lt;br /&gt;
&lt;br /&gt;
==Modifying IsingLattice.py==&lt;br /&gt;
&lt;br /&gt;
===Monte Carlo and Statistics Methods===&lt;br /&gt;
[[File:Monte_Carlo.PNG]]&lt;br /&gt;
&lt;br /&gt;
[[File:stats.PNG]]&lt;br /&gt;
&lt;br /&gt;
The Metropolis Monte Carlo (MMC) algorithm provides a computationally inexpensive path from random initial states to the minimum free energy states of the Ising lattices generated. First, a random 2D Ising lattice is generated. A single random spin within this lattice is &amp;quot;flipped&amp;quot; and the resulting (internal) energy change between these states is measured. Recalling the relationship between the Hemholtz free energy, internal energy and entropy, it follows that a decrease in internal energy also lowers the free energy of the system: thus the configuration change is accepted.&lt;br /&gt;
&lt;br /&gt;
In the case that the spin &amp;quot;flip&amp;quot; does not lower the internal energy, the MMC algorithm tests this configuration change against the Boltzman factor. In the canonical (NVT) ensemble, the free energy of the system is given by:&lt;br /&gt;
&lt;br /&gt;
:&amp;lt;math&amp;gt;A = -k_{B}T\,lnZ_{NVT} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
where Z is the canonical partition function which depends upon &amp;lt;math&amp;gt; e^{-\frac{\Delta E}{k_BT}} &amp;lt;/math&amp;gt;, the Boltzman factor. By choosing a random value in the interval [0,1)from a continuous uniformm probability distribution and rejecting any value of the Boltzman factor less than this value, the MMC algorithm allows for configuration changes with small, positive internal energy changes if they conform to the Boltzman probability distribution. Alternatively, the MMC allows small perturbations to the internal energy which prevents the system from settling in a metastable internal energy minimum and instead, ensures that the system equilibrates around the &#039;&#039;true&#039;&#039; free energy minimum.&lt;br /&gt;
&lt;br /&gt;
===Spontaneous Magnetisation===&lt;br /&gt;
&lt;br /&gt;
Below the Curie Temperature, &amp;lt;math&amp;gt; T_{C} &amp;lt;/math&amp;gt;, the energetic driving force dominates the entropic driving force, resulting in a highly ordered system and an overall magnetisation. The spins of the system align in order to maximise favourable coupling interactions rather than adopting a less ordered configuration of higher multiplicity. Therefore, when &amp;lt;math&amp;gt;T &amp;lt; T_C&amp;lt;/math&amp;gt;, the most probable configurations have an overall magnetisation resulting in &amp;lt;math&amp;gt;\left\langle M\right\rangle \neq 0&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
The plots of magnetisation per spin and energy per spin obtained from ILanim.py support this prediction. Below, the plots show that upon equilibration, the system adopts the minimum energy per spin: &amp;lt;math&amp;gt;E_{min_{spin}} = \frac{-NDJ}{N} = -DJ = -2&amp;lt;/math&amp;gt; and exhibits the maximum magnitude of magnetisation per spin: &amp;lt;math&amp;gt;|M_{spin}| = 1&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:2T=1.0.png]]&lt;br /&gt;
[[File:T=1.0.png]]&lt;br /&gt;
[[File:3T=1.0.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
An unknown system error prevented the statistics() function from printing the average values.&lt;br /&gt;
&lt;br /&gt;
=Accelerating the Code=&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Initial Method Speeds===&lt;br /&gt;
Taking 10 repeat measurements for the time taken to perform 2000 Monte Carlo steps resulted in&lt;br /&gt;
&lt;br /&gt;
* An average time of  &amp;lt;math&amp;gt;11.7s&amp;lt;/math&amp;gt; &lt;br /&gt;
* A standard error of &amp;lt;math&amp;gt;0.020s&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Updating Measurement===&lt;br /&gt;
&lt;br /&gt;
NOTE: ILtimetrial.py has been modified to:&lt;br /&gt;
* Perform a requested number of &#039;2000 Monte Carlo Step&#039; measurements&lt;br /&gt;
* Record these measurements in a CSV file&lt;br /&gt;
* Return the mean measuremd time and the Standard Error i.e.   &amp;lt;math&amp;gt; \frac{\sigma}{n} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:TimeTrialMethod.PNG]]&lt;br /&gt;
&lt;br /&gt;
===Updating Energy and Magnetisation Methods===&lt;br /&gt;
[[File:New_Mag_Method.PNG]]&lt;br /&gt;
[[File:New_Ene_Method.PNG]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Updated Method Speeds===&lt;br /&gt;
[[File:TimeTrial.PNG]]&lt;br /&gt;
&lt;br /&gt;
Taking 30 measurements of the time taken to perform 2000 Monte Carlo Steps resulted in:&lt;br /&gt;
&lt;br /&gt;
* An average time of &amp;lt;math&amp;gt;\displaystyle{0.87s}&amp;lt;/math&amp;gt;&lt;br /&gt;
* A standard error of &amp;lt;math&amp;gt;2.5 \times 10^{-3}s&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This represents a 93% decrease in the average computation time from the initial methods.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=The Effect of Temperature=&lt;br /&gt;
&lt;br /&gt;
==Correcting the Averaging  Code==&lt;br /&gt;
&lt;br /&gt;
===Finding a Delay Value===&lt;br /&gt;
To quickly find a value for &amp;lt;math&amp;gt; N_{d}&amp;lt;/math&amp;gt;, the minimum number of cycles typically needed for the equilibration of a system of within the lattice and temperature ranges of interest, it was assumed that:&lt;br /&gt;
&lt;br /&gt;
* Larger lattices would require more Monte Carlo steps to reach equilibrium from their initial, random configurations&lt;br /&gt;
&lt;br /&gt;
* Lattices at lower temperatures would require more Monte Carlo steps to reach equilibrium from their initial, random configurations.&lt;br /&gt;
&lt;br /&gt;
Therefore, an initial value for &amp;lt;math&amp;gt; N_{d}&amp;lt;/math&amp;gt; was found for a &amp;lt;math&amp;gt; 128\times128 &amp;lt;/math&amp;gt; lattice at a temperature of &amp;lt;math&amp;gt;0.5&amp;lt;/math&amp;gt; reduced temperature units.&lt;br /&gt;
*&amp;lt;math&amp;gt; N_{d} = 185000 &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
By this number of steps, all smaller lattices at all higher temperatures were found to have equilibrated also. Thus, this value of&amp;lt;math&amp;gt; N_{d}&amp;lt;/math&amp;gt; was accepted as an appropriate delay.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:AFinFrame 128 3e5 T= 0.5line.png|400px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
For the 128x128 lattices at T=0.5, equilibration was ensured from 185000 steps onwards.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Smaller lattices at the same temperature did indeed equilibrate more slowly, but all equilibrated within &amp;lt;math&amp;gt; N_{d}&amp;lt;/math&amp;gt; MC steps.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:AFinFrame 64 3e5 T= 0.5line.png|400px]]&lt;br /&gt;
[[File:AFinFrame 32 3e5 T= 0.5line2.png|400px]]&lt;br /&gt;
[[File:AFinFrame 16 3e5 T= 0.5line2.png|400px]]&lt;br /&gt;
[[File:AFinFrame 8 3e5 T= 0.5line.png|400px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The figure below shows the modifications made to IsingLattice.py to incorporate the &amp;lt;math&amp;gt; N_{d} &amp;lt;/math&amp;gt; step delay.&lt;br /&gt;
&lt;br /&gt;
==Running over a Range of Temperatures==&lt;br /&gt;
&lt;br /&gt;
To examine the effect of temperature on the average energy &amp;lt;math&amp;gt; \left\langle E\right\rangle &amp;lt;/math&amp;gt; and average magnetisation &amp;lt;math&amp;gt; \left\langle M\right\rangle &amp;lt;/math&amp;gt; of Ising lattices at equilibrium, the following parameters were used:&lt;br /&gt;
&lt;br /&gt;
* Temperature Range: &amp;lt;math&amp;gt;  0.5 - 5 &amp;lt;/math&amp;gt; reduced units&lt;br /&gt;
* Temperature Interval: &amp;lt;math&amp;gt;0.01&amp;lt;/math&amp;gt; reduced units (&amp;lt;math&amp;gt;450&amp;lt;/math&amp;gt; temperature values)&lt;br /&gt;
* Number of MMC Steps per Temperature value: &amp;lt;math&amp;gt; 2 \times 10^5 &amp;lt;/math&amp;gt; with the aforementioned value of &amp;lt;math&amp;gt; N_{d} = 1.85 \times 10^5 &amp;lt;/math&amp;gt; Monte Carlo steps&lt;br /&gt;
* Lattice Sizes:  &amp;lt;math&amp;gt; 2 \times 2 &amp;lt;/math&amp;gt;, &amp;lt;math&amp;gt; 4 \times 4 &amp;lt;/math&amp;gt; , &amp;lt;math&amp;gt; 8 \times 8 &amp;lt;/math&amp;gt; , &amp;lt;math&amp;gt; 16 \times 16 &amp;lt;/math&amp;gt; , &amp;lt;math&amp;gt; 32 \times 32 &amp;lt;/math&amp;gt; , &amp;lt;math&amp;gt; 64 \times 64 &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Plots of  &amp;lt;math&amp;gt; \left\langle E\right\rangle &amp;lt;/math&amp;gt; and  &amp;lt;math&amp;gt; \left\langle M\right\rangle &amp;lt;/math&amp;gt; per spin as versus temperature are presented below for each lattice size. Errorbars have been implemented to demonstrate how &#039;&#039;well-behaved&#039;&#039; lattice systems of each size are at each temperature, that is, how temperature and lattice size affect the size of the variations in the expected values. For the error calculations, the standard errors, &amp;lt;math&amp;gt; \sigma_\bar{X} &amp;lt;/math&amp;gt;,  in &amp;lt;math&amp;gt; \left\langle E\right\rangle &amp;lt;/math&amp;gt; and  &amp;lt;math&amp;gt; \left\langle M\right\rangle &amp;lt;/math&amp;gt; per spin have been used:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====8x8====&lt;br /&gt;
&lt;br /&gt;
[[File:8x8e+error.png]] [[File:8x8m+error.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
A Python script has been written to generate a plot of &amp;lt;math&amp;gt;\left\langle E\right\rangle&amp;lt;/math&amp;gt; or &amp;lt;math&amp;gt;\left\langle M\right\rangle&amp;lt;/math&amp;gt; against temperature based upon user input. A screenshot of this code has been inserted below.&lt;br /&gt;
&lt;br /&gt;
[[File:ExpectedvsTemp.PNG|200px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=The Effect of System Size=&lt;br /&gt;
&lt;br /&gt;
==Scaling the System Size==&lt;br /&gt;
&lt;br /&gt;
===More Lattice Sizes===&lt;br /&gt;
&lt;br /&gt;
====2x2====&lt;br /&gt;
[[File:2x2e+error.png]] [[File:2x2m+error.png]]&lt;br /&gt;
&lt;br /&gt;
====4x4====&lt;br /&gt;
[[File:4x4e+error.png]] [[File:4x4m+error.png]]&lt;br /&gt;
&lt;br /&gt;
====16x16====&lt;br /&gt;
[[File:16x16e+error.png]] [[File:16x16m+error.png]]&lt;br /&gt;
&lt;br /&gt;
====32x32====&lt;br /&gt;
[[File:32x32e+error.png]] [[File:32x32m+error.png]]&lt;br /&gt;
&lt;br /&gt;
====64x64====&lt;br /&gt;
[[File:64x64e+error.png]] [[File:64x64m+error.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Scrutiny of the plots of average energy per spin for each lattice size reveals an increase in the errorbar width with increasing lattice size. This is most notable in the low temperature region of the plots. Between the &amp;lt;math&amp;gt; 8\times8 &amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt; 16\times16 &amp;lt;/math&amp;gt; lattices, the long range fluctuations become suddenly prominent. The &amp;lt;math&amp;gt;16\times16&amp;lt;/math&amp;gt; lattice is the first (in the range of sizes tested)to clearly capture these fluctuations.&lt;br /&gt;
&lt;br /&gt;
=Determining the Heat Capacity=&lt;br /&gt;
&lt;br /&gt;
==Calculating the Heat Capacity==&lt;br /&gt;
&lt;br /&gt;
===Heat Capacity Derivation===&lt;br /&gt;
Working in the canonical ensemble (constant volume), the heat capacity &amp;lt;math&amp;gt; C_V &amp;lt;/math&amp;gt; is given by:&lt;br /&gt;
&lt;br /&gt;
:&amp;lt;math&amp;gt;C_V = \frac{\partial \left\langle E\right\rangle}{\partial T}_V&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
where &amp;lt;math&amp;gt;\left\langle E\right\rangle&amp;lt;/math&amp;gt; is the average total energy or expected value of the internal energy of the system.&lt;br /&gt;
&lt;br /&gt;
: &amp;lt;math&amp;gt; \left\langle E\right\rangle = - \frac{\partial ln Q}{\partial \beta} = -\frac{1}{Q}\frac{\partial Q}{\partial \beta} &amp;lt;/math&amp;gt;&lt;br /&gt;
where &amp;lt;math&amp;gt; Q&amp;lt;/math&amp;gt; is the partition function for the system of N interacting spins.&lt;br /&gt;
&lt;br /&gt;
By evaluating the second form of the partial derivative with respect to &amp;lt;math&amp;gt; \beta&amp;lt;/math&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \left\langle E\right\rangle = -\frac{1}{Q}\frac{\partial Q}{\partial \beta} = \frac{\Sigma \epsilon_{i} e^{-\beta \epsilon_{i}}}{\Sigma e^{-\beta \epsilon_{i}}} &amp;lt;/math&amp;gt; &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Applying the product rule enables the differentiation of this expression for &amp;lt;math&amp;gt;\left\langle E\right\rangle&amp;lt;/math&amp;gt; with respect to temperature, giving:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\frac{\partial \left\langle E\right\rangle}{\partial T} = \frac{\Sigma \epsilon_{i} \frac{\epsilon_i}{k_BT^2}e^{-\beta \epsilon_{i}}}{\Sigma e^{-\beta \epsilon_{i}}} - \frac{\Sigma \epsilon_i e^{-\beta \epsilon_i}\cdot \frac{\epsilon_i}{k_BT^2}e^{-\beta \epsilon_i}}{(\Sigma e^{-\beta \epsilon_{i}})^2}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\frac{\partial \left\langle E\right\rangle}{\partial T}  = \frac{1}{k_BT^2}\left[\frac{\Sigma \epsilon_i^2 e^{-\beta \epsilon_i}}{\Sigma e^{-\beta \epsilon_i}} - \left(\frac{\Sigma \epsilon_{i} e^{-\beta \epsilon_{i}}}{\Sigma e^{-\beta \epsilon_{i}}}\right)^2\right] &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\frac{\partial \left\langle E\right\rangle}{\partial T}  = \frac{1}{k_BT^2}\left[\left\langle E^2\right\rangle - \left\langle E\right\rangle^2 \right] &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Thus,&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\frac{\partial \left\langle E\right\rangle}{\partial T} = \frac{Var[E]}{k_BT^2} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Heat Capacity versus Temperature===&lt;br /&gt;
Below, a screenshot of the Python script written to produce plots of &amp;lt;math&amp;gt; C_V &amp;lt;/math&amp;gt; against &amp;lt;math&amp;gt; T &amp;lt;/math&amp;gt;, together with the output images of this script.&lt;br /&gt;
 &lt;br /&gt;
[[File:HeatCapScript.PNG]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====2x2====&lt;br /&gt;
[[File:HC2.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====4x4====&lt;br /&gt;
[[File:HC4.png]]&lt;br /&gt;
&lt;br /&gt;
====8x8====&lt;br /&gt;
[[File:HC8.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====16x16====&lt;br /&gt;
[[File:HC16.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====32x32====&lt;br /&gt;
[[File:HC-32.png]]&lt;br /&gt;
&lt;br /&gt;
= Locating the Curie Temperature =&lt;br /&gt;
&lt;br /&gt;
===C++ Data Comparison===&lt;br /&gt;
Below a comparison of the &amp;lt;math&amp;gt; C_V &amp;lt;/math&amp;gt; against &amp;lt;math&amp;gt; T &amp;lt;/math&amp;gt; plot generated for the &amp;lt;math&amp;gt; 2 /times 2&amp;lt;/math&amp;gt; to the corresponding C++ data is offered.&lt;br /&gt;
 &lt;br /&gt;
[[File:CHC2.png]]&lt;br /&gt;
&lt;br /&gt;
The data generated by the ILtemperaturerange.py script is a faithful match to the C++ data. However, this is an exceptional case; the plots for all other lattice sizes were found to be very dissimilar, necessitating polynomial fitting.&lt;br /&gt;
&lt;br /&gt;
==Polyfitting of C++ Data==&lt;br /&gt;
&lt;br /&gt;
===Fitting a Polynomial to the Entire Range===&lt;br /&gt;
The following Python script was written to perform a polynomial fit to the entire range of the graph of &amp;lt;math&amp;gt; C_V &amp;lt;/math&amp;gt; against &amp;lt;math&amp;gt; T &amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:HeatCapPoly.PNG]]&lt;br /&gt;
&lt;br /&gt;
Below, the result of the polyfit to the &amp;lt;math&amp;gt; 2/times2&amp;lt;/math&amp;gt; lattice data is offered (for comparison to the previous, non-fitted example).&lt;br /&gt;
&lt;br /&gt;
[[File:15Polyc2x2.png]]&lt;br /&gt;
&lt;br /&gt;
Polynomials with 5 terms and above were found to match the data in the vicinity of the critical region considerably well. Below 7 terms, the &#039;&#039;tails&#039;&#039; of the plot were matched poorly. In the above example, a polynomial of 15 terms was fit to the data.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Fitting a Polynomial to the Critical Region===&lt;br /&gt;
&lt;br /&gt;
The following Python script was written to perform a polynomial fit to the region of interest (the &#039;&#039;critical&#039;&#039; region) of the plots of &amp;lt;math&amp;gt; C_V &amp;lt;/math&amp;gt; against &amp;lt;math&amp;gt; T &amp;lt;/math&amp;gt; to facilitate the discovery of &amp;lt;math&amp;gt; T_C &amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
[[File:CapPolyCrit.PNG]]&lt;br /&gt;
&lt;br /&gt;
An example of the result returned by the script is offered below for the C++ data for the &amp;lt;math&amp;gt; 16\times16&amp;lt;/math&amp;gt; lattice.&lt;br /&gt;
&lt;br /&gt;
[[File:HHCPC16,2.6-2.1,5.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Finding the Peak C Values for Each Lattice Size===&lt;br /&gt;
Below, a screenshot of the code used to obtain the temperatures at which the maximum values of C occured is presented for each lattice size. The temperatures themselves are also featured on the image.&lt;br /&gt;
&lt;br /&gt;
[[File:Tmaxes.PNG]]&lt;br /&gt;
&lt;br /&gt;
The range of lattice sizes and their associated &amp;lt;math&amp;gt;T_{C} &amp;lt;/math&amp;gt; values were exported to a [[Media:Tmax.txt|text file]], enabling a plot to be created.&lt;br /&gt;
&lt;br /&gt;
[[File:CritTempPlot2.png]]&lt;br /&gt;
&lt;br /&gt;
Subsequently, the scipy.optimize.curve_fit function was used to fit &amp;lt;math&amp;gt;T_{C, L} = \frac{A}{L} + T_{C,\infty}&amp;lt;/math&amp;gt; function to the data obtained. This enabled the estimation the constant &amp;lt;math&amp;gt; A &amp;lt;/math&amp;gt; and the value of &amp;lt;math&amp;gt;T_{C} &amp;lt;/math&amp;gt; at &amp;lt;math&amp;gt; \frac{A}{L} = 0&amp;lt;/math&amp;gt;, otherwise &amp;lt;math&amp;gt; T_{C,\infty}&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
[[File:FindingTc.PNG]]&lt;br /&gt;
&lt;br /&gt;
A value of &amp;lt;math&amp;gt; T_{C,\infty} = 2.2799 &amp;lt;/math&amp;gt; was obtained. A comparison to the literature[https://en.wikipedia.org/wiki/Square-lattice_Ising_model#Critical_temperature] value of &amp;lt;math&amp;gt;2.269&amp;lt;/math&amp;gt; reveals a percentage error value of only &amp;lt;math&amp;gt; 0.47% &amp;lt;/math&amp;gt;. Surprisingly, the investigation of lattices in the given size range was enough to capture the theoretical behaviour of an infinite lattice. As explained by Frenkel and Smit, the implementation of periodic boundary conditions enables the simulation of an infinite bulk (or infinite adjacent lattices) surrounding the single lattice under scrutiny. The agreement of the experimental and theoretical values for &amp;lt;math&amp;gt; T_{C,\infty} &amp;lt;/math&amp;gt; prove the effectiveness of this idea.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
A likely source of error arises from the polynomial fitting of the data. The peaks in &amp;lt;math&amp;gt; C_V &amp;lt;/math&amp;gt; against &amp;lt;math&amp;gt; T &amp;lt;/math&amp;gt; were far more sharp than the broad peaks of the polynomial functions used to fit them. In several cases, the polynomial peak was a slight, yet discernible overestimate of the true peak. This has resulted in an overestimation of the final &amp;lt;math&amp;gt; T_{C,\infty} &amp;lt;/math&amp;gt; value. Fitting a function with a sharper peak (e.g. a Kronecker delta function) to the critical region could overcome this overestimation and provide a more faithful final value.&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
* Frenkel, Daan, et al. Understanding Molecular Simulation : From Algorithms to Applications, Elsevier Science &amp;amp; Technology, 2001&lt;br /&gt;
&lt;br /&gt;
* Krieger, M. Constitutions of matter : Mathematically modeling the most everyday of physical phenomena. Chicago ; London: University of Chicago Press, 1996&lt;br /&gt;
&lt;br /&gt;
* https://en.wikipedia.org/wiki/Square-lattice_Ising_model Accessed 13-11-18&lt;/div&gt;</summary>
		<author><name>Jj1516</name></author>
	</entry>
	<entry>
		<id>https://chemwiki.ch.ic.ac.uk/index.php?title=Rep:JJ1516Ising&amp;diff=737024</id>
		<title>Rep:JJ1516Ising</title>
		<link rel="alternate" type="text/html" href="https://chemwiki.ch.ic.ac.uk/index.php?title=Rep:JJ1516Ising&amp;diff=737024"/>
		<updated>2018-11-21T10:53:17Z</updated>

		<summary type="html">&lt;p&gt;Jj1516: /* Heat Capacity versus Temperature */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Introduction to the Ising Model =&lt;br /&gt;
&lt;br /&gt;
== The Model ==&lt;br /&gt;
&lt;br /&gt;
=== Minimum Energy State ===&lt;br /&gt;
====Minimum Interaction Energy====&lt;br /&gt;
The interaction energy of an Ising lattice is given by:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;E = -\frac{1}{2}J\displaystyle\sum_{i}^{N} \displaystyle\sum_{j\;\in\;{neighbours}\;(i)} \!\!\!\!\!\!\!\!\!\!\!\!s_{i}s_{j}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In an Ising lattice with D dimensions and periodic boundary conditions, a given spin &amp;lt;math&amp;gt; s_i&amp;lt;/math&amp;gt; has 2D neighbours.&lt;br /&gt;
&lt;br /&gt;
The minimum interaction energy is achieved when all spins in the lattice are aligned (all ↑ or all ↓). As  such, any spin &amp;lt;math&amp;gt; s_i&amp;lt;/math&amp;gt; must be aligned with all 2D of its neighbours. That is, &amp;lt;math&amp;gt;s_{i}s_{j} = 1&amp;lt;/math&amp;gt; for all &amp;lt;math&amp;gt;j&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Therefore, for any &amp;lt;math&amp;gt; s_i&amp;lt;/math&amp;gt;, the sum of its interactions is &amp;lt;math&amp;gt;\displaystyle\sum_{j\;\in\;{neighbours}\;(i)} \!\!\!\!\!\!\!\!\!\!\!\!s_{i}s_{j} = 2D &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
As this is true for all N spins in the lattice, it follows that &amp;lt;math&amp;gt;\displaystyle\sum_{i}^{N} 2D = 2DN&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Thus the minimum interaction energy is given by:&lt;br /&gt;
&lt;br /&gt;
:&amp;lt;math&amp;gt;E_{min} = -\frac{1}{2}J\cdot2DN = - DNJ &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Entropy of the Minimum Energy State====&lt;br /&gt;
&lt;br /&gt;
The entropy of a state is given by:&lt;br /&gt;
&lt;br /&gt;
:&amp;lt;math&amp;gt;S = k\; ln\; \Omega &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Where &amp;lt;math&amp;gt; \Omega &amp;lt;/math&amp;gt; is the multiplicity of the state, the number of degenerate configurations of said state. The minimum energy state is achievable with all spins ↑ or with all spins ↓. In the absence of an external magnetic field, these configurations are degenerate and indistinguishable giving &amp;lt;math&amp;gt; \Omega = 2 &amp;lt;/math&amp;gt; for this state. Therefore,&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; S_{E_{min}}  = k_{B}\; ln\; 2 = 0.693k_{B} = 9.57 \times 10^{-24} J\!\cdot\!\! K^{-1}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Phase Transitions ==&lt;br /&gt;
&lt;br /&gt;
=== Changes to Minimum Energy Configuration ===&lt;br /&gt;
&lt;br /&gt;
====Energy Change ====&lt;br /&gt;
The energy change &amp;lt;math&amp;gt; \Delta E&amp;lt;/math&amp;gt; associated with a single spin &#039;flip&#039; from the lowest energy onfiguration may be calculated by considering the change in the interaction energy with the spin&#039;s neighbours.&lt;br /&gt;
&lt;br /&gt;
Let &amp;lt;math&amp;gt; D = 3, N = 1000 &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\Delta{E} = E_1 - E_0&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;E_1&amp;lt;/math&amp;gt; Interaction energy after one spin has been &#039;flipped&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;E_0&amp;lt;/math&amp;gt; Lowest energy configuration&lt;br /&gt;
&lt;br /&gt;
[[Image:Task 2 table.PNG]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\displaystyle\sum_{interactions} = -2D + 2D(2D-2) + 2D[N-(2D+1)] &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; = 2DN - 8D &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;E_1 = \displaystyle-\frac{1}{2}J\;\sum_{interactions} = 4DJ - DNJ&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\Delta{E} = E_1 - E_0 = 4DJ - DNJ + DNJ = +4DJ = +12J&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This energy change is independent of &amp;lt;math&amp;gt; N&amp;lt;/math&amp;gt; and depends only on the dimension size and the coupling constant &amp;lt;math&amp;gt; J &amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
In this calculation, the following assumption has been made.&lt;br /&gt;
&lt;br /&gt;
* The lattice dimensions are infinite relative to the size of each cell&lt;br /&gt;
&lt;br /&gt;
This allows &#039;&#039;&#039;any&#039;&#039;&#039; cell to be treated as the centre of the lattice. As every cell interacts with 2D neighbours, flipping any cell in the minimum energy configuration results in the same energy change. Alternatively, the periodic boundary conditions of the Ising model remove the necessity for such an assumption. As a consequence, the absence of &amp;lt;math&amp;gt; N &amp;lt;/math&amp;gt; from the resulting energy change is justified.&lt;br /&gt;
&lt;br /&gt;
====Entropy Change====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; S = k_{B}\; ln\; \Omega &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\Omega = \displaystyle\frac{N!}{{N_{\uparrow}!}{N_{\downarrow}!}}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Where &amp;lt;math&amp;gt;N_{x}!&amp;lt;/math&amp;gt; denotes the factorial of the number of spins in spin state &amp;lt;math&amp;gt;x&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\Delta{S} = k_{B}\;ln\;\left(\displaystyle\frac{\Omega_{2}}{\Omega_{1}}\right)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\Omega_{2} = \frac{1000!}{999!1!} = 1000&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \Omega_{1} = \frac{1000!}{1000!} = 1&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\Delta{S} = k_{B}\;ln\;1000 = 9.54 \times 10^{-23} JK^{-1}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\Delta{S_{mol}} = N_{A}k_{B}\;ln\;1000 = 57.4 \,JK^{-1}mol^{-1}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Magnetisation Values of 1D and 2D Lattices===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;M = \sum_i s_i&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====1D Lattice Magnetisation====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;M_{1D} =\;\;+1&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====2D Lattice Magnetisation====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;M_{2D} =\;\;+1&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Magnetisation at 0K====&lt;br /&gt;
&lt;br /&gt;
At 0K, no thermal energy is available to overcome the energetic barriers to spin flipping. Considering the Hemholtz free energy:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; A = E - TS &amp;lt;/math&amp;gt; &lt;br /&gt;
&lt;br /&gt;
A temperature of 0K nullifies the entropic contribution to the free energy. Thus the energetic driving force (which maximises parallel spin interactions) dominates the entropic driving force (which maximises multiplicity of lattice states). For an Ising Lattice with D =  3, N = 1000 at 0K, the alignment of all spins results in the minimum energy configuration  and an overall magnetisation of &amp;lt;math&amp;gt; M = \pm 1000 &amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
= Calculating the Energy and Magnetisation =&lt;br /&gt;
==Modifying the Files==&lt;br /&gt;
&lt;br /&gt;
===Energy and Magnetisation Functions===&lt;br /&gt;
&lt;br /&gt;
====Energy===&lt;br /&gt;
[[File:First_Ene_Method.PNG]]&lt;br /&gt;
&lt;br /&gt;
The above energy method segments a given lattice into lattice cells on the edges, corners or in the bulk of the lattice and calculates the energy interactions with its neighbours as appropriate.&lt;br /&gt;
&lt;br /&gt;
====Magnetisation====&lt;br /&gt;
[[File:First_Mag_Method.PNG]]&lt;br /&gt;
&lt;br /&gt;
The magnetisation method loops over all elements in the array representing the Ising lattice and adds the value of the spin to the magnetisation variable.&lt;br /&gt;
&lt;br /&gt;
==Testing the Files==&lt;br /&gt;
&lt;br /&gt;
===ILCheck.py===&lt;br /&gt;
&lt;br /&gt;
[[File:ILChecks.PNG]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Above, the results of the ILcheck.py script are presented.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= Introduction to the Monte Carlo Simulation =&lt;br /&gt;
==Average Energy and Magnetisation==&lt;br /&gt;
===Configurations of a 100 Spin System===&lt;br /&gt;
For a system of two spins, 4 configurations are possible (↑↑, ↓↓, ↑↓, ↓↑) i.e. &amp;lt;math&amp;gt;2^{2}&amp;lt;/math&amp;gt;. For a system of 100 spins, there are &amp;lt;math&amp;gt;2^{100}&amp;lt;/math&amp;gt; configurations. In the first example, the ↑↑ and ↓↓ are degenerate, as are the ↑↓ and ↓↑ configurations. Therefore, dividing the number of possible configurations by the multiplicity of each configuration (&amp;lt;math&amp;gt;2&amp;lt;/math&amp;gt;) gives the number of non-degenerate configurations. As previously stated, degenerate configurations are indistinguishable in the absence of an external magnetic field.&lt;br /&gt;
&lt;br /&gt;
For 100 spins, this gives &amp;lt;math&amp;gt;\displaystyle\frac{2^{100}}{2} = 6.338 \times 10^{29} &amp;lt;/math&amp;gt; distinguishable configurations.&lt;br /&gt;
&lt;br /&gt;
If processing speed permits &amp;lt;math&amp;gt; 1 \times 10^{9}&amp;lt;/math&amp;gt; calculations each second, the evaluation of a single value of &amp;lt;math&amp;gt;\left\langle M\right\rangle_T&amp;lt;/math&amp;gt; would last &amp;lt;math&amp;gt; 6.338 \times 10^{20} &amp;lt;/math&amp;gt; seconds or &amp;lt;math&amp;gt; 1458 &amp;lt;/math&amp;gt; times the age of the Universe!&lt;br /&gt;
&lt;br /&gt;
==Modifying IsingLattice.py==&lt;br /&gt;
&lt;br /&gt;
===Monte Carlo and Statistics Methods===&lt;br /&gt;
[[File:Monte_Carlo.PNG]]&lt;br /&gt;
&lt;br /&gt;
[[File:stats.PNG]]&lt;br /&gt;
&lt;br /&gt;
The Metropolis Monte Carlo (MMC) algorithm provides a computationally inexpensive path from random initial states to the minimum free energy states of the Ising lattices generated. First, a random 2D Ising lattice is generated. A single random spin within this lattice is &amp;quot;flipped&amp;quot; and the resulting (internal) energy change between these states is measured. Recalling the relationship between the Hemholtz free energy, internal energy and entropy, it follows that a decrease in internal energy also lowers the free energy of the system: thus the configuration change is accepted.&lt;br /&gt;
&lt;br /&gt;
In the case that the spin &amp;quot;flip&amp;quot; does not lower the internal energy, the MMC algorithm tests this configuration change against the Boltzman factor. In the canonical (NVT) ensemble, the free energy of the system is given by:&lt;br /&gt;
&lt;br /&gt;
:&amp;lt;math&amp;gt;A = -k_{B}T\,lnZ_{NVT} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
where Z is the canonical partition function which depends upon &amp;lt;math&amp;gt; e^{-\frac{\Delta E}{k_BT}} &amp;lt;/math&amp;gt;, the Boltzman factor. By choosing a random value in the interval [0,1)from a continuous uniformm probability distribution and rejecting any value of the Boltzman factor less than this value, the MMC algorithm allows for configuration changes with small, positive internal energy changes if they conform to the Boltzman probability distribution. Alternatively, the MMC allows small perturbations to the internal energy which prevents the system from settling in a metastable internal energy minimum and instead, ensures that the system equilibrates around the &#039;&#039;true&#039;&#039; free energy minimum.&lt;br /&gt;
&lt;br /&gt;
===Spontaneous Magnetisation===&lt;br /&gt;
&lt;br /&gt;
Below the Curie Temperature, &amp;lt;math&amp;gt; T_{C} &amp;lt;/math&amp;gt;, the energetic driving force dominates the entropic driving force, resulting in a highly ordered system and an overall magnetisation. The spins of the system align in order to maximise favourable coupling interactions rather than adopting a less ordered configuration of higher multiplicity. Therefore, when &amp;lt;math&amp;gt;T &amp;lt; T_C&amp;lt;/math&amp;gt;, the most probable configurations have an overall magnetisation resulting in &amp;lt;math&amp;gt;\left\langle M\right\rangle \neq 0&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
The plots of magnetisation per spin and energy per spin obtained from ILanim.py support this prediction. Below, the plots show that upon equilibration, the system adopts the minimum energy per spin: &amp;lt;math&amp;gt;E_{min_{spin}} = \frac{-NDJ}{N} = -DJ = -2&amp;lt;/math&amp;gt; and exhibits the maximum magnitude of magnetisation per spin: &amp;lt;math&amp;gt;|M_{spin}| = 1&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:2T=1.0.png]]&lt;br /&gt;
[[File:T=1.0.png]]&lt;br /&gt;
[[File:3T=1.0.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
An unknown system error prevented the statistics() function from printing the average values.&lt;br /&gt;
&lt;br /&gt;
=Accelerating the Code=&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Initial Method Speeds===&lt;br /&gt;
Taking 10 repeat measurements for the time taken to perform 2000 Monte Carlo steps resulted in&lt;br /&gt;
&lt;br /&gt;
* An average time of  &amp;lt;math&amp;gt;11.7s&amp;lt;/math&amp;gt; &lt;br /&gt;
* A standard error of &amp;lt;math&amp;gt;0.020s&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Updating Measurement===&lt;br /&gt;
&lt;br /&gt;
NOTE: ILtimetrial.py has been modified to:&lt;br /&gt;
* Perform a requested number of &#039;2000 Monte Carlo Step&#039; measurements&lt;br /&gt;
* Record these measurements in a CSV file&lt;br /&gt;
* Return the mean measuremd time and the Standard Error i.e.   &amp;lt;math&amp;gt; \frac{\sigma}{n} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:TimeTrialMethod.PNG]]&lt;br /&gt;
&lt;br /&gt;
===Updating Energy and Magnetisation Methods===&lt;br /&gt;
[[File:New_Mag_Method.PNG]]&lt;br /&gt;
[[File:New_Ene_Method.PNG]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Updated Method Speeds===&lt;br /&gt;
[[File:TimeTrial.PNG]]&lt;br /&gt;
&lt;br /&gt;
Taking 30 measurements of the time taken to perform 2000 Monte Carlo Steps resulted in:&lt;br /&gt;
&lt;br /&gt;
* An average time of &amp;lt;math&amp;gt;\displaystyle{0.87s}&amp;lt;/math&amp;gt;&lt;br /&gt;
* A standard error of &amp;lt;math&amp;gt;2.5 \times 10^{-3}s&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This represents a 93% decrease in the average computation time from the initial methods.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=The Effect of Temperature=&lt;br /&gt;
&lt;br /&gt;
==Correcting the Averaging  Code==&lt;br /&gt;
&lt;br /&gt;
===Finding a Delay Value===&lt;br /&gt;
To quickly find a value for &amp;lt;math&amp;gt; N_{d}&amp;lt;/math&amp;gt;, the minimum number of cycles typically needed for the equilibration of a system of within the lattice and temperature ranges of interest, it was assumed that:&lt;br /&gt;
&lt;br /&gt;
* Larger lattices would require more Monte Carlo steps to reach equilibrium from their initial, random configurations&lt;br /&gt;
&lt;br /&gt;
* Lattices at lower temperatures would require more Monte Carlo steps to reach equilibrium from their initial, random configurations.&lt;br /&gt;
&lt;br /&gt;
Therefore, an initial value for &amp;lt;math&amp;gt; N_{d}&amp;lt;/math&amp;gt; was found for a &amp;lt;math&amp;gt; 128\times128 &amp;lt;/math&amp;gt; lattice at a temperature of &amp;lt;math&amp;gt;0.5&amp;lt;/math&amp;gt; reduced temperature units.&lt;br /&gt;
*&amp;lt;math&amp;gt; N_{d} = 185000 &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
By this number of steps, all smaller lattices at all higher temperatures were found to have equilibrated also. Thus, this value of&amp;lt;math&amp;gt; N_{d}&amp;lt;/math&amp;gt; was accepted as an appropriate delay.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:AFinFrame 128 3e5 T= 0.5line.png|400px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
For the 128x128 lattices at T=0.5, equilibration was ensured from 185000 steps onwards.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Smaller lattices at the same temperature did indeed equilibrate more slowly, but all equilibrated within &amp;lt;math&amp;gt; N_{d}&amp;lt;/math&amp;gt; MC steps.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:AFinFrame 64 3e5 T= 0.5line.png|400px]]&lt;br /&gt;
[[File:AFinFrame 32 3e5 T= 0.5line2.png|400px]]&lt;br /&gt;
[[File:AFinFrame 16 3e5 T= 0.5line2.png|400px]]&lt;br /&gt;
[[File:AFinFrame 8 3e5 T= 0.5line.png|400px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The figure below shows the modifications made to IsingLattice.py to incorporate the &amp;lt;math&amp;gt; N_{d} &amp;lt;/math&amp;gt; step delay.&lt;br /&gt;
&lt;br /&gt;
==Running over a Range of Temperatures==&lt;br /&gt;
&lt;br /&gt;
To examine the effect of temperature on the average energy &amp;lt;math&amp;gt; \left\langle E\right\rangle &amp;lt;/math&amp;gt; and average magnetisation &amp;lt;math&amp;gt; \left\langle M\right\rangle &amp;lt;/math&amp;gt; of Ising lattices at equilibrium, the following parameters were used:&lt;br /&gt;
&lt;br /&gt;
* Temperature Range: &amp;lt;math&amp;gt;  0.5 - 5 &amp;lt;/math&amp;gt; reduced units&lt;br /&gt;
* Temperature Interval: &amp;lt;math&amp;gt;0.01&amp;lt;/math&amp;gt; reduced units (&amp;lt;math&amp;gt;450&amp;lt;/math&amp;gt; temperature values)&lt;br /&gt;
* Number of MMC Steps per Temperature value: &amp;lt;math&amp;gt; 2 \times 10^5 &amp;lt;/math&amp;gt; with the aforementioned value of &amp;lt;math&amp;gt; N_{d} = 1.85 \times 10^5 &amp;lt;/math&amp;gt; Monte Carlo steps&lt;br /&gt;
* Lattice Sizes:  &amp;lt;math&amp;gt; 2 \times 2 &amp;lt;/math&amp;gt;, &amp;lt;math&amp;gt; 4 \times 4 &amp;lt;/math&amp;gt; , &amp;lt;math&amp;gt; 8 \times 8 &amp;lt;/math&amp;gt; , &amp;lt;math&amp;gt; 16 \times 16 &amp;lt;/math&amp;gt; , &amp;lt;math&amp;gt; 32 \times 32 &amp;lt;/math&amp;gt; , &amp;lt;math&amp;gt; 64 \times 64 &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Plots of  &amp;lt;math&amp;gt; \left\langle E\right\rangle &amp;lt;/math&amp;gt; and  &amp;lt;math&amp;gt; \left\langle M\right\rangle &amp;lt;/math&amp;gt; per spin as versus temperature are presented below for each lattice size. Errorbars have been implemented to demonstrate how &#039;&#039;well-behaved&#039;&#039; lattice systems of each size are at each temperature, that is, how temperature and lattice size affect the size of the variations in the expected values. For the error calculations, the standard errors, &amp;lt;math&amp;gt; \sigma_\bar{X} &amp;lt;/math&amp;gt;,  in &amp;lt;math&amp;gt; \left\langle E\right\rangle &amp;lt;/math&amp;gt; and  &amp;lt;math&amp;gt; \left\langle M\right\rangle &amp;lt;/math&amp;gt; per spin have been used:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====8x8====&lt;br /&gt;
&lt;br /&gt;
[[File:8x8e+error.png]] [[File:8x8m+error.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
A Python script has been written to generate a plot of &amp;lt;math&amp;gt;\left\langle E\right\rangle&amp;lt;/math&amp;gt; or &amp;lt;math&amp;gt;\left\langle M\right\rangle&amp;lt;/math&amp;gt; against temperature based upon user input. A screenshot of this code has been inserted below.&lt;br /&gt;
&lt;br /&gt;
[[File:ExpectedvsTemp.PNG|200px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=The Effect of System Size=&lt;br /&gt;
&lt;br /&gt;
==Scaling the System Size==&lt;br /&gt;
&lt;br /&gt;
===More Lattice Sizes===&lt;br /&gt;
&lt;br /&gt;
====2x2====&lt;br /&gt;
[[File:2x2e+error.png]] [[File:2x2m+error.png]]&lt;br /&gt;
&lt;br /&gt;
====4x4====&lt;br /&gt;
[[File:4x4e+error.png]] [[File:4x4m+error.png]]&lt;br /&gt;
&lt;br /&gt;
====16x16====&lt;br /&gt;
[[File:16x16e+error.png]] [[File:16x16m+error.png]]&lt;br /&gt;
&lt;br /&gt;
====32x32====&lt;br /&gt;
[[File:32x32e+error.png]] [[File:32x32m+error.png]]&lt;br /&gt;
&lt;br /&gt;
====64x64====&lt;br /&gt;
[[File:64x64e+error.png]] [[File:64x64m+error.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Scrutiny of the plots of average energy per spin for each lattice size reveals an increase in the errorbar width with increasing lattice size. This is most notable in the low temperature region of the plots. Between the &amp;lt;math&amp;gt; 8\times8 &amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt; 16\times16 &amp;lt;/math&amp;gt; lattices, the long range fluctuations become suddenly prominent. The &amp;lt;math&amp;gt;16\times16&amp;lt;/math&amp;gt; lattice is the first (in the range of sizes tested)to clearly capture these fluctuations.&lt;br /&gt;
&lt;br /&gt;
=Determining the Heat Capacity=&lt;br /&gt;
&lt;br /&gt;
==Calculating the Heat Capacity==&lt;br /&gt;
&lt;br /&gt;
===Heat Capacity Derivation===&lt;br /&gt;
Working in the canonical ensemble (constant volume), the heat capacity &amp;lt;math&amp;gt; C_V &amp;lt;/math&amp;gt; is given by:&lt;br /&gt;
&lt;br /&gt;
:&amp;lt;math&amp;gt;C_V = \frac{\partial \left\langle E\right\rangle}{\partial T}_V&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
where &amp;lt;math&amp;gt;\left\langle E\right\rangle&amp;lt;/math&amp;gt; is the average total energy or expected value of the internal energy of the system.&lt;br /&gt;
&lt;br /&gt;
: &amp;lt;math&amp;gt; \left\langle E\right\rangle = - \frac{\partial ln Q}{\partial \beta} = -\frac{1}{Q}\frac{\partial Q}{\partial \beta} &amp;lt;/math&amp;gt;&lt;br /&gt;
where &amp;lt;math&amp;gt; Q&amp;lt;/math&amp;gt; is the partition function for the system of N interacting spins.&lt;br /&gt;
&lt;br /&gt;
By evaluating the second form of the partial derivative with respect to &amp;lt;math&amp;gt; \beta&amp;lt;/math&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \left\langle E\right\rangle = -\frac{1}{Q}\frac{\partial Q}{\partial \beta} = \frac{\Sigma \epsilon_{i} e^{-\beta \epsilon_{i}}}{\Sigma e^{-\beta \epsilon_{i}}} &amp;lt;/math&amp;gt; &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Applying the product rule enables the differentiation of this expression for &amp;lt;math&amp;gt;\left\langle E\right\rangle&amp;lt;/math&amp;gt; with respect to temperature, giving:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\frac{\partial \left\langle E\right\rangle}{\partial T} = \frac{\Sigma \epsilon_{i} \frac{\epsilon_i}{k_BT^2}e^{-\beta \epsilon_{i}}}{\Sigma e^{-\beta \epsilon_{i}}} - \frac{\Sigma \epsilon_i e^{-\beta \epsilon_i}\cdot \frac{\epsilon_i}{k_BT^2}e^{-\beta \epsilon_i}}{(\Sigma e^{-\beta \epsilon_{i}})^2}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\frac{\partial \left\langle E\right\rangle}{\partial T}  = \frac{1}{k_BT^2}\left[\frac{\Sigma \epsilon_i^2 e^{-\beta \epsilon_i}}{\Sigma e^{-\beta \epsilon_i}} - \left(\frac{\Sigma \epsilon_{i} e^{-\beta \epsilon_{i}}}{\Sigma e^{-\beta \epsilon_{i}}}\right)^2\right] &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\frac{\partial \left\langle E\right\rangle}{\partial T}  = \frac{1}{k_BT^2}\left[\left\langle E^2\right\rangle - \left\langle E\right\rangle^2 \right] &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Thus,&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\frac{\partial \left\langle E\right\rangle}{\partial T} = \frac{Var[E]}{k_BT^2} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Heat Capacity versus Temperature===&lt;br /&gt;
Below, a screenshot of the Python script written to produce plots of &amp;lt;math&amp;gt; C_V &amp;lt;/math&amp;gt; against &amp;lt;math&amp;gt; T &amp;lt;/math&amp;gt;, together with the output images of this script.&lt;br /&gt;
 &lt;br /&gt;
[[File:HeatCapScript.PNG]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====2x2====&lt;br /&gt;
[[File:HC2.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====4x4====&lt;br /&gt;
[[File:HC4.png]]&lt;br /&gt;
&lt;br /&gt;
====8x8====&lt;br /&gt;
[[File:HC8.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====16x16====&lt;br /&gt;
[[File:HC16.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====32x32====&lt;br /&gt;
[[File:HC-32.png]]&lt;br /&gt;
&lt;br /&gt;
= Locating the Curie Temperature =&lt;br /&gt;
&lt;br /&gt;
===C++ Data Comparison===&lt;br /&gt;
Below a comparison of the &amp;lt;math&amp;gt; C_V &amp;lt;/math&amp;gt; against &amp;lt;math&amp;gt; T &amp;lt;/math&amp;gt; plot generated for the &amp;lt;math&amp;gt; 2 /times 2&amp;lt;/math&amp;gt; to the corresponding C++ data is offered.&lt;br /&gt;
 &lt;br /&gt;
[[File:CHC2.png]]&lt;br /&gt;
&lt;br /&gt;
The data generated by the ILtemperaturerange.py script is a faithful match to the C++ data. However, this is an exceptional case; the plots for all other lattice sizes were found to be very dissimilar, necessitating polynomial fitting.&lt;br /&gt;
&lt;br /&gt;
==Polyfitting of C++ Data==&lt;br /&gt;
&lt;br /&gt;
===Fitting a Polynomial to the Entire Range===&lt;br /&gt;
The following Python script was written to perform a polynomial fit to the entire range of the graph of &amp;lt;math&amp;gt; C_V &amp;lt;/math&amp;gt; against &amp;lt;math&amp;gt; T &amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:HeatCapPoly.PNG]]&lt;br /&gt;
&lt;br /&gt;
Below, the result of the polyfit to the &amp;lt;math&amp;gt; 2/times2&amp;lt;/math&amp;gt; lattice data is offered (for comparison to the previous, non-fitted example).&lt;br /&gt;
&lt;br /&gt;
[[File:15Polyc2x2.png]]&lt;br /&gt;
&lt;br /&gt;
Polynomials with 5 terms and above were found to match the data in the vicinity of the critical region considerably well. Below 7 terms, the &#039;&#039;tails&#039;&#039; of the plot were matched poorly. In the above example, a polynomial of 15 terms was fit to the data.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Fitting a Polynomial to the Critical Region===&lt;br /&gt;
&lt;br /&gt;
The following Python script was written to perform a polynomial fit to the region of interest (the &#039;&#039;critical&#039;&#039; region) of the plots of &amp;lt;math&amp;gt; C_V &amp;lt;/math&amp;gt; against &amp;lt;math&amp;gt; T &amp;lt;/math&amp;gt; to facilitate the discovery of &amp;lt;math&amp;gt; T_C &amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
[[File:CapPolyCrit.PNG]]&lt;br /&gt;
&lt;br /&gt;
An example of the result returned by the script is offered below for the C++ data for the &amp;lt;math&amp;gt; 16\times16&amp;lt;/math&amp;gt; lattice.&lt;br /&gt;
&lt;br /&gt;
[[File:HHCPC16,2.6-2.1,5.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Finding the Peak C Values for Each Lattice Size===&lt;br /&gt;
Below, a screenshot of the code used to obtain the temperatures at which the maximum values of C occured is presented for each lattice size. The temperatures themselves are also featured on the image.&lt;br /&gt;
&lt;br /&gt;
[[File:Tmaxes.PNG]]&lt;br /&gt;
&lt;br /&gt;
The range of lattice sizes and their associated &amp;lt;math&amp;gt;T_{C} &amp;lt;/math&amp;gt; values were exported to a [[Media:Tmax.txt|text file]], enabling a plot to be created.&lt;br /&gt;
&lt;br /&gt;
[[File:CritTempPlot2.png]]&lt;br /&gt;
&lt;br /&gt;
Subsequently, the scipy.optimize.curve_fit function was used to fit &amp;lt;math&amp;gt;T_{C, L} = \frac{A}{L} + T_{C,\infty}&amp;lt;/math&amp;gt; function to the data obtained. This enabled the estimation the constant &amp;lt;math&amp;gt; A &amp;lt;/math&amp;gt; and the value of &amp;lt;math&amp;gt;T_{C} &amp;lt;/math&amp;gt; at &amp;lt;math&amp;gt; \frac{A}{L} = 0&amp;lt;/math&amp;gt;, otherwise &amp;lt;math&amp;gt; T_{C,\infty}&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
[[File:FindingTc.PNG]]&lt;br /&gt;
&lt;br /&gt;
A value of &amp;lt;math&amp;gt; T_{C,\infty} = 2.2799 &amp;lt;/math&amp;gt; was obtained. A comparison to the literature[https://en.wikipedia.org/wiki/Square-lattice_Ising_model#Critical_temperature] value of &amp;lt;math&amp;gt;2.269&amp;lt;/math&amp;gt; reveals a percentage error value of only &amp;lt;math&amp;gt; 0.47% &amp;lt;/math&amp;gt;. Surprisingly, the investigation of lattices in the given size range was enough to capture the theoretical behaviour of an infinite lattice. As explained by Frenkel and Smit, the implementation of periodic boundary conditions enables the simulation of an infinite bulk (or infinite adjacent lattices) surrounding the single lattice under scrutiny. The agreement of the experimental and theoretical values for &amp;lt;math&amp;gt; T_{C,\infty} &amp;lt;/math&amp;gt; prove the effectiveness of this idea.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
A likely source of error arises from the polynomial fitting of the data. The peaks in &amp;lt;math&amp;gt; C_V &amp;lt;/math&amp;gt; against &amp;lt;math&amp;gt; T &amp;lt;/math&amp;gt; were far more sharp than the broad peaks of the polynomial functions used to fit them. In several cases, the polynomial peak was a slight, yet discernible overestimate of the true peak. This has resulted in an overestimation of the final &amp;lt;math&amp;gt; T_{C,\infty} &amp;lt;/math&amp;gt; value. Fitting a function with a sharper peak (e.g. a Kronecker delta function) to the critical region could overcome this overestimation and provide a more faithful final value.&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
* Frenkel, Daan, et al. Understanding Molecular Simulation : From Algorithms to Applications, Elsevier Science &amp;amp; Technology, 2001&lt;br /&gt;
&lt;br /&gt;
* Krieger, M. Constitutions of matter : Mathematically modeling the most everyday of physical phenomena. Chicago ; London: University of Chicago Press, 1996&lt;br /&gt;
&lt;br /&gt;
* https://en.wikipedia.org/wiki/Square-lattice_Ising_model Accessed 13-11-18&lt;/div&gt;</summary>
		<author><name>Jj1516</name></author>
	</entry>
	<entry>
		<id>https://chemwiki.ch.ic.ac.uk/index.php?title=File:HC-32.png&amp;diff=737023</id>
		<title>File:HC-32.png</title>
		<link rel="alternate" type="text/html" href="https://chemwiki.ch.ic.ac.uk/index.php?title=File:HC-32.png&amp;diff=737023"/>
		<updated>2018-11-21T10:53:06Z</updated>

		<summary type="html">&lt;p&gt;Jj1516: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Jj1516</name></author>
	</entry>
	<entry>
		<id>https://chemwiki.ch.ic.ac.uk/index.php?title=Rep:JJ1516Ising&amp;diff=736998</id>
		<title>Rep:JJ1516Ising</title>
		<link rel="alternate" type="text/html" href="https://chemwiki.ch.ic.ac.uk/index.php?title=Rep:JJ1516Ising&amp;diff=736998"/>
		<updated>2018-11-21T10:13:35Z</updated>

		<summary type="html">&lt;p&gt;Jj1516: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Introduction to the Ising Model =&lt;br /&gt;
&lt;br /&gt;
== The Model ==&lt;br /&gt;
&lt;br /&gt;
=== Minimum Energy State ===&lt;br /&gt;
====Minimum Interaction Energy====&lt;br /&gt;
The interaction energy of an Ising lattice is given by:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;E = -\frac{1}{2}J\displaystyle\sum_{i}^{N} \displaystyle\sum_{j\;\in\;{neighbours}\;(i)} \!\!\!\!\!\!\!\!\!\!\!\!s_{i}s_{j}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In an Ising lattice with D dimensions and periodic boundary conditions, a given spin &amp;lt;math&amp;gt; s_i&amp;lt;/math&amp;gt; has 2D neighbours.&lt;br /&gt;
&lt;br /&gt;
The minimum interaction energy is achieved when all spins in the lattice are aligned (all ↑ or all ↓). As  such, any spin &amp;lt;math&amp;gt; s_i&amp;lt;/math&amp;gt; must be aligned with all 2D of its neighbours. That is, &amp;lt;math&amp;gt;s_{i}s_{j} = 1&amp;lt;/math&amp;gt; for all &amp;lt;math&amp;gt;j&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Therefore, for any &amp;lt;math&amp;gt; s_i&amp;lt;/math&amp;gt;, the sum of its interactions is &amp;lt;math&amp;gt;\displaystyle\sum_{j\;\in\;{neighbours}\;(i)} \!\!\!\!\!\!\!\!\!\!\!\!s_{i}s_{j} = 2D &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
As this is true for all N spins in the lattice, it follows that &amp;lt;math&amp;gt;\displaystyle\sum_{i}^{N} 2D = 2DN&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Thus the minimum interaction energy is given by:&lt;br /&gt;
&lt;br /&gt;
:&amp;lt;math&amp;gt;E_{min} = -\frac{1}{2}J\cdot2DN = - DNJ &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Entropy of the Minimum Energy State====&lt;br /&gt;
&lt;br /&gt;
The entropy of a state is given by:&lt;br /&gt;
&lt;br /&gt;
:&amp;lt;math&amp;gt;S = k\; ln\; \Omega &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Where &amp;lt;math&amp;gt; \Omega &amp;lt;/math&amp;gt; is the multiplicity of the state, the number of degenerate configurations of said state. The minimum energy state is achievable with all spins ↑ or with all spins ↓. In the absence of an external magnetic field, these configurations are degenerate and indistinguishable giving &amp;lt;math&amp;gt; \Omega = 2 &amp;lt;/math&amp;gt; for this state. Therefore,&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; S_{E_{min}}  = k_{B}\; ln\; 2 = 0.693k_{B} = 9.57 \times 10^{-24} J\!\cdot\!\! K^{-1}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Phase Transitions ==&lt;br /&gt;
&lt;br /&gt;
=== Changes to Minimum Energy Configuration ===&lt;br /&gt;
&lt;br /&gt;
====Energy Change ====&lt;br /&gt;
The energy change &amp;lt;math&amp;gt; \Delta E&amp;lt;/math&amp;gt; associated with a single spin &#039;flip&#039; from the lowest energy onfiguration may be calculated by considering the change in the interaction energy with the spin&#039;s neighbours.&lt;br /&gt;
&lt;br /&gt;
Let &amp;lt;math&amp;gt; D = 3, N = 1000 &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\Delta{E} = E_1 - E_0&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;E_1&amp;lt;/math&amp;gt; Interaction energy after one spin has been &#039;flipped&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;E_0&amp;lt;/math&amp;gt; Lowest energy configuration&lt;br /&gt;
&lt;br /&gt;
[[Image:Task 2 table.PNG]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\displaystyle\sum_{interactions} = -2D + 2D(2D-2) + 2D[N-(2D+1)] &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; = 2DN - 8D &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;E_1 = \displaystyle-\frac{1}{2}J\;\sum_{interactions} = 4DJ - DNJ&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\Delta{E} = E_1 - E_0 = 4DJ - DNJ + DNJ = +4DJ = +12J&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This energy change is independent of &amp;lt;math&amp;gt; N&amp;lt;/math&amp;gt; and depends only on the dimension size and the coupling constant &amp;lt;math&amp;gt; J &amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
In this calculation, the following assumption has been made.&lt;br /&gt;
&lt;br /&gt;
* The lattice dimensions are infinite relative to the size of each cell&lt;br /&gt;
&lt;br /&gt;
This allows &#039;&#039;&#039;any&#039;&#039;&#039; cell to be treated as the centre of the lattice. As every cell interacts with 2D neighbours, flipping any cell in the minimum energy configuration results in the same energy change. Alternatively, the periodic boundary conditions of the Ising model remove the necessity for such an assumption. As a consequence, the absence of &amp;lt;math&amp;gt; N &amp;lt;/math&amp;gt; from the resulting energy change is justified.&lt;br /&gt;
&lt;br /&gt;
====Entropy Change====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; S = k_{B}\; ln\; \Omega &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\Omega = \displaystyle\frac{N!}{{N_{\uparrow}!}{N_{\downarrow}!}}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Where &amp;lt;math&amp;gt;N_{x}!&amp;lt;/math&amp;gt; denotes the factorial of the number of spins in spin state &amp;lt;math&amp;gt;x&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\Delta{S} = k_{B}\;ln\;\left(\displaystyle\frac{\Omega_{2}}{\Omega_{1}}\right)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\Omega_{2} = \frac{1000!}{999!1!} = 1000&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \Omega_{1} = \frac{1000!}{1000!} = 1&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\Delta{S} = k_{B}\;ln\;1000 = 9.54 \times 10^{-23} JK^{-1}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\Delta{S_{mol}} = N_{A}k_{B}\;ln\;1000 = 57.4 \,JK^{-1}mol^{-1}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Magnetisation Values of 1D and 2D Lattices===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;M = \sum_i s_i&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====1D Lattice Magnetisation====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;M_{1D} =\;\;+1&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====2D Lattice Magnetisation====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;M_{2D} =\;\;+1&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Magnetisation at 0K====&lt;br /&gt;
&lt;br /&gt;
At 0K, no thermal energy is available to overcome the energetic barriers to spin flipping. Considering the Hemholtz free energy:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; A = E - TS &amp;lt;/math&amp;gt; &lt;br /&gt;
&lt;br /&gt;
A temperature of 0K nullifies the entropic contribution to the free energy. Thus the energetic driving force (which maximises parallel spin interactions) dominates the entropic driving force (which maximises multiplicity of lattice states). For an Ising Lattice with D =  3, N = 1000 at 0K, the alignment of all spins results in the minimum energy configuration  and an overall magnetisation of &amp;lt;math&amp;gt; M = \pm 1000 &amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
= Calculating the Energy and Magnetisation =&lt;br /&gt;
==Modifying the Files==&lt;br /&gt;
&lt;br /&gt;
===Energy and Magnetisation Functions===&lt;br /&gt;
&lt;br /&gt;
====Energy===&lt;br /&gt;
[[File:First_Ene_Method.PNG]]&lt;br /&gt;
&lt;br /&gt;
The above energy method segments a given lattice into lattice cells on the edges, corners or in the bulk of the lattice and calculates the energy interactions with its neighbours as appropriate.&lt;br /&gt;
&lt;br /&gt;
====Magnetisation====&lt;br /&gt;
[[File:First_Mag_Method.PNG]]&lt;br /&gt;
&lt;br /&gt;
The magnetisation method loops over all elements in the array representing the Ising lattice and adds the value of the spin to the magnetisation variable.&lt;br /&gt;
&lt;br /&gt;
==Testing the Files==&lt;br /&gt;
&lt;br /&gt;
===ILCheck.py===&lt;br /&gt;
&lt;br /&gt;
[[File:ILChecks.PNG]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Above, the results of the ILcheck.py script are presented.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= Introduction to the Monte Carlo Simulation =&lt;br /&gt;
==Average Energy and Magnetisation==&lt;br /&gt;
===Configurations of a 100 Spin System===&lt;br /&gt;
For a system of two spins, 4 configurations are possible (↑↑, ↓↓, ↑↓, ↓↑) i.e. &amp;lt;math&amp;gt;2^{2}&amp;lt;/math&amp;gt;. For a system of 100 spins, there are &amp;lt;math&amp;gt;2^{100}&amp;lt;/math&amp;gt; configurations. In the first example, the ↑↑ and ↓↓ are degenerate, as are the ↑↓ and ↓↑ configurations. Therefore, dividing the number of possible configurations by the multiplicity of each configuration (&amp;lt;math&amp;gt;2&amp;lt;/math&amp;gt;) gives the number of non-degenerate configurations. As previously stated, degenerate configurations are indistinguishable in the absence of an external magnetic field.&lt;br /&gt;
&lt;br /&gt;
For 100 spins, this gives &amp;lt;math&amp;gt;\displaystyle\frac{2^{100}}{2} = 6.338 \times 10^{29} &amp;lt;/math&amp;gt; distinguishable configurations.&lt;br /&gt;
&lt;br /&gt;
If processing speed permits &amp;lt;math&amp;gt; 1 \times 10^{9}&amp;lt;/math&amp;gt; calculations each second, the evaluation of a single value of &amp;lt;math&amp;gt;\left\langle M\right\rangle_T&amp;lt;/math&amp;gt; would last &amp;lt;math&amp;gt; 6.338 \times 10^{20} &amp;lt;/math&amp;gt; seconds or &amp;lt;math&amp;gt; 1458 &amp;lt;/math&amp;gt; times the age of the Universe!&lt;br /&gt;
&lt;br /&gt;
==Modifying IsingLattice.py==&lt;br /&gt;
&lt;br /&gt;
===Monte Carlo and Statistics Methods===&lt;br /&gt;
[[File:Monte_Carlo.PNG]]&lt;br /&gt;
&lt;br /&gt;
[[File:stats.PNG]]&lt;br /&gt;
&lt;br /&gt;
The Metropolis Monte Carlo (MMC) algorithm provides a computationally inexpensive path from random initial states to the minimum free energy states of the Ising lattices generated. First, a random 2D Ising lattice is generated. A single random spin within this lattice is &amp;quot;flipped&amp;quot; and the resulting (internal) energy change between these states is measured. Recalling the relationship between the Hemholtz free energy, internal energy and entropy, it follows that a decrease in internal energy also lowers the free energy of the system: thus the configuration change is accepted.&lt;br /&gt;
&lt;br /&gt;
In the case that the spin &amp;quot;flip&amp;quot; does not lower the internal energy, the MMC algorithm tests this configuration change against the Boltzman factor. In the canonical (NVT) ensemble, the free energy of the system is given by:&lt;br /&gt;
&lt;br /&gt;
:&amp;lt;math&amp;gt;A = -k_{B}T\,lnZ_{NVT} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
where Z is the canonical partition function which depends upon &amp;lt;math&amp;gt; e^{-\frac{\Delta E}{k_BT}} &amp;lt;/math&amp;gt;, the Boltzman factor. By choosing a random value in the interval [0,1)from a continuous uniformm probability distribution and rejecting any value of the Boltzman factor less than this value, the MMC algorithm allows for configuration changes with small, positive internal energy changes if they conform to the Boltzman probability distribution. Alternatively, the MMC allows small perturbations to the internal energy which prevents the system from settling in a metastable internal energy minimum and instead, ensures that the system equilibrates around the &#039;&#039;true&#039;&#039; free energy minimum.&lt;br /&gt;
&lt;br /&gt;
===Spontaneous Magnetisation===&lt;br /&gt;
&lt;br /&gt;
Below the Curie Temperature, &amp;lt;math&amp;gt; T_{C} &amp;lt;/math&amp;gt;, the energetic driving force dominates the entropic driving force, resulting in a highly ordered system and an overall magnetisation. The spins of the system align in order to maximise favourable coupling interactions rather than adopting a less ordered configuration of higher multiplicity. Therefore, when &amp;lt;math&amp;gt;T &amp;lt; T_C&amp;lt;/math&amp;gt;, the most probable configurations have an overall magnetisation resulting in &amp;lt;math&amp;gt;\left\langle M\right\rangle \neq 0&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
The plots of magnetisation per spin and energy per spin obtained from ILanim.py support this prediction. Below, the plots show that upon equilibration, the system adopts the minimum energy per spin: &amp;lt;math&amp;gt;E_{min_{spin}} = \frac{-NDJ}{N} = -DJ = -2&amp;lt;/math&amp;gt; and exhibits the maximum magnitude of magnetisation per spin: &amp;lt;math&amp;gt;|M_{spin}| = 1&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:2T=1.0.png]]&lt;br /&gt;
[[File:T=1.0.png]]&lt;br /&gt;
[[File:3T=1.0.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
An unknown system error prevented the statistics() function from printing the average values.&lt;br /&gt;
&lt;br /&gt;
=Accelerating the Code=&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Initial Method Speeds===&lt;br /&gt;
Taking 10 repeat measurements for the time taken to perform 2000 Monte Carlo steps resulted in&lt;br /&gt;
&lt;br /&gt;
* An average time of  &amp;lt;math&amp;gt;11.7s&amp;lt;/math&amp;gt; &lt;br /&gt;
* A standard error of &amp;lt;math&amp;gt;0.020s&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Updating Measurement===&lt;br /&gt;
&lt;br /&gt;
NOTE: ILtimetrial.py has been modified to:&lt;br /&gt;
* Perform a requested number of &#039;2000 Monte Carlo Step&#039; measurements&lt;br /&gt;
* Record these measurements in a CSV file&lt;br /&gt;
* Return the mean measuremd time and the Standard Error i.e.   &amp;lt;math&amp;gt; \frac{\sigma}{n} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:TimeTrialMethod.PNG]]&lt;br /&gt;
&lt;br /&gt;
===Updating Energy and Magnetisation Methods===&lt;br /&gt;
[[File:New_Mag_Method.PNG]]&lt;br /&gt;
[[File:New_Ene_Method.PNG]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Updated Method Speeds===&lt;br /&gt;
[[File:TimeTrial.PNG]]&lt;br /&gt;
&lt;br /&gt;
Taking 30 measurements of the time taken to perform 2000 Monte Carlo Steps resulted in:&lt;br /&gt;
&lt;br /&gt;
* An average time of &amp;lt;math&amp;gt;\displaystyle{0.87s}&amp;lt;/math&amp;gt;&lt;br /&gt;
* A standard error of &amp;lt;math&amp;gt;2.5 \times 10^{-3}s&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This represents a 93% decrease in the average computation time from the initial methods.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=The Effect of Temperature=&lt;br /&gt;
&lt;br /&gt;
==Correcting the Averaging  Code==&lt;br /&gt;
&lt;br /&gt;
===Finding a Delay Value===&lt;br /&gt;
To quickly find a value for &amp;lt;math&amp;gt; N_{d}&amp;lt;/math&amp;gt;, the minimum number of cycles typically needed for the equilibration of a system of within the lattice and temperature ranges of interest, it was assumed that:&lt;br /&gt;
&lt;br /&gt;
* Larger lattices would require more Monte Carlo steps to reach equilibrium from their initial, random configurations&lt;br /&gt;
&lt;br /&gt;
* Lattices at lower temperatures would require more Monte Carlo steps to reach equilibrium from their initial, random configurations.&lt;br /&gt;
&lt;br /&gt;
Therefore, an initial value for &amp;lt;math&amp;gt; N_{d}&amp;lt;/math&amp;gt; was found for a &amp;lt;math&amp;gt; 128\times128 &amp;lt;/math&amp;gt; lattice at a temperature of &amp;lt;math&amp;gt;0.5&amp;lt;/math&amp;gt; reduced temperature units.&lt;br /&gt;
*&amp;lt;math&amp;gt; N_{d} = 185000 &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
By this number of steps, all smaller lattices at all higher temperatures were found to have equilibrated also. Thus, this value of&amp;lt;math&amp;gt; N_{d}&amp;lt;/math&amp;gt; was accepted as an appropriate delay.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:AFinFrame 128 3e5 T= 0.5line.png|400px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
For the 128x128 lattices at T=0.5, equilibration was ensured from 185000 steps onwards.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Smaller lattices at the same temperature did indeed equilibrate more slowly, but all equilibrated within &amp;lt;math&amp;gt; N_{d}&amp;lt;/math&amp;gt; MC steps.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:AFinFrame 64 3e5 T= 0.5line.png|400px]]&lt;br /&gt;
[[File:AFinFrame 32 3e5 T= 0.5line2.png|400px]]&lt;br /&gt;
[[File:AFinFrame 16 3e5 T= 0.5line2.png|400px]]&lt;br /&gt;
[[File:AFinFrame 8 3e5 T= 0.5line.png|400px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The figure below shows the modifications made to IsingLattice.py to incorporate the &amp;lt;math&amp;gt; N_{d} &amp;lt;/math&amp;gt; step delay.&lt;br /&gt;
&lt;br /&gt;
==Running over a Range of Temperatures==&lt;br /&gt;
&lt;br /&gt;
To examine the effect of temperature on the average energy &amp;lt;math&amp;gt; \left\langle E\right\rangle &amp;lt;/math&amp;gt; and average magnetisation &amp;lt;math&amp;gt; \left\langle M\right\rangle &amp;lt;/math&amp;gt; of Ising lattices at equilibrium, the following parameters were used:&lt;br /&gt;
&lt;br /&gt;
* Temperature Range: &amp;lt;math&amp;gt;  0.5 - 5 &amp;lt;/math&amp;gt; reduced units&lt;br /&gt;
* Temperature Interval: &amp;lt;math&amp;gt;0.01&amp;lt;/math&amp;gt; reduced units (&amp;lt;math&amp;gt;450&amp;lt;/math&amp;gt; temperature values)&lt;br /&gt;
* Number of MMC Steps per Temperature value: &amp;lt;math&amp;gt; 2 \times 10^5 &amp;lt;/math&amp;gt; with the aforementioned value of &amp;lt;math&amp;gt; N_{d} = 1.85 \times 10^5 &amp;lt;/math&amp;gt; Monte Carlo steps&lt;br /&gt;
* Lattice Sizes:  &amp;lt;math&amp;gt; 2 \times 2 &amp;lt;/math&amp;gt;, &amp;lt;math&amp;gt; 4 \times 4 &amp;lt;/math&amp;gt; , &amp;lt;math&amp;gt; 8 \times 8 &amp;lt;/math&amp;gt; , &amp;lt;math&amp;gt; 16 \times 16 &amp;lt;/math&amp;gt; , &amp;lt;math&amp;gt; 32 \times 32 &amp;lt;/math&amp;gt; , &amp;lt;math&amp;gt; 64 \times 64 &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Plots of  &amp;lt;math&amp;gt; \left\langle E\right\rangle &amp;lt;/math&amp;gt; and  &amp;lt;math&amp;gt; \left\langle M\right\rangle &amp;lt;/math&amp;gt; per spin as versus temperature are presented below for each lattice size. Errorbars have been implemented to demonstrate how &#039;&#039;well-behaved&#039;&#039; lattice systems of each size are at each temperature, that is, how temperature and lattice size affect the size of the variations in the expected values. For the error calculations, the standard errors, &amp;lt;math&amp;gt; \sigma_\bar{X} &amp;lt;/math&amp;gt;,  in &amp;lt;math&amp;gt; \left\langle E\right\rangle &amp;lt;/math&amp;gt; and  &amp;lt;math&amp;gt; \left\langle M\right\rangle &amp;lt;/math&amp;gt; per spin have been used:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====8x8====&lt;br /&gt;
&lt;br /&gt;
[[File:8x8e+error.png]] [[File:8x8m+error.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
A Python script has been written to generate a plot of &amp;lt;math&amp;gt;\left\langle E\right\rangle&amp;lt;/math&amp;gt; or &amp;lt;math&amp;gt;\left\langle M\right\rangle&amp;lt;/math&amp;gt; against temperature based upon user input. A screenshot of this code has been inserted below.&lt;br /&gt;
&lt;br /&gt;
[[File:ExpectedvsTemp.PNG|200px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=The Effect of System Size=&lt;br /&gt;
&lt;br /&gt;
==Scaling the System Size==&lt;br /&gt;
&lt;br /&gt;
===More Lattice Sizes===&lt;br /&gt;
&lt;br /&gt;
====2x2====&lt;br /&gt;
[[File:2x2e+error.png]] [[File:2x2m+error.png]]&lt;br /&gt;
&lt;br /&gt;
====4x4====&lt;br /&gt;
[[File:4x4e+error.png]] [[File:4x4m+error.png]]&lt;br /&gt;
&lt;br /&gt;
====16x16====&lt;br /&gt;
[[File:16x16e+error.png]] [[File:16x16m+error.png]]&lt;br /&gt;
&lt;br /&gt;
====32x32====&lt;br /&gt;
[[File:32x32e+error.png]] [[File:32x32m+error.png]]&lt;br /&gt;
&lt;br /&gt;
====64x64====&lt;br /&gt;
[[File:64x64e+error.png]] [[File:64x64m+error.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Scrutiny of the plots of average energy per spin for each lattice size reveals an increase in the errorbar width with increasing lattice size. This is most notable in the low temperature region of the plots. Between the &amp;lt;math&amp;gt; 8\times8 &amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt; 16\times16 &amp;lt;/math&amp;gt; lattices, the long range fluctuations become suddenly prominent. The &amp;lt;math&amp;gt;16\times16&amp;lt;/math&amp;gt; lattice is the first (in the range of sizes tested)to clearly capture these fluctuations.&lt;br /&gt;
&lt;br /&gt;
=Determining the Heat Capacity=&lt;br /&gt;
&lt;br /&gt;
==Calculating the Heat Capacity==&lt;br /&gt;
&lt;br /&gt;
===Heat Capacity Derivation===&lt;br /&gt;
Working in the canonical ensemble (constant volume), the heat capacity &amp;lt;math&amp;gt; C_V &amp;lt;/math&amp;gt; is given by:&lt;br /&gt;
&lt;br /&gt;
:&amp;lt;math&amp;gt;C_V = \frac{\partial \left\langle E\right\rangle}{\partial T}_V&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
where &amp;lt;math&amp;gt;\left\langle E\right\rangle&amp;lt;/math&amp;gt; is the average total energy or expected value of the internal energy of the system.&lt;br /&gt;
&lt;br /&gt;
: &amp;lt;math&amp;gt; \left\langle E\right\rangle = - \frac{\partial ln Q}{\partial \beta} = -\frac{1}{Q}\frac{\partial Q}{\partial \beta} &amp;lt;/math&amp;gt;&lt;br /&gt;
where &amp;lt;math&amp;gt; Q&amp;lt;/math&amp;gt; is the partition function for the system of N interacting spins.&lt;br /&gt;
&lt;br /&gt;
By evaluating the second form of the partial derivative with respect to &amp;lt;math&amp;gt; \beta&amp;lt;/math&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \left\langle E\right\rangle = -\frac{1}{Q}\frac{\partial Q}{\partial \beta} = \frac{\Sigma \epsilon_{i} e^{-\beta \epsilon_{i}}}{\Sigma e^{-\beta \epsilon_{i}}} &amp;lt;/math&amp;gt; &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Applying the product rule enables the differentiation of this expression for &amp;lt;math&amp;gt;\left\langle E\right\rangle&amp;lt;/math&amp;gt; with respect to temperature, giving:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\frac{\partial \left\langle E\right\rangle}{\partial T} = \frac{\Sigma \epsilon_{i} \frac{\epsilon_i}{k_BT^2}e^{-\beta \epsilon_{i}}}{\Sigma e^{-\beta \epsilon_{i}}} - \frac{\Sigma \epsilon_i e^{-\beta \epsilon_i}\cdot \frac{\epsilon_i}{k_BT^2}e^{-\beta \epsilon_i}}{(\Sigma e^{-\beta \epsilon_{i}})^2}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\frac{\partial \left\langle E\right\rangle}{\partial T}  = \frac{1}{k_BT^2}\left[\frac{\Sigma \epsilon_i^2 e^{-\beta \epsilon_i}}{\Sigma e^{-\beta \epsilon_i}} - \left(\frac{\Sigma \epsilon_{i} e^{-\beta \epsilon_{i}}}{\Sigma e^{-\beta \epsilon_{i}}}\right)^2\right] &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\frac{\partial \left\langle E\right\rangle}{\partial T}  = \frac{1}{k_BT^2}\left[\left\langle E^2\right\rangle - \left\langle E\right\rangle^2 \right] &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Thus,&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\frac{\partial \left\langle E\right\rangle}{\partial T} = \frac{Var[E]}{k_BT^2} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Heat Capacity versus Temperature===&lt;br /&gt;
Below, a screenshot of the Python script written to produce plots of &amp;lt;math&amp;gt; C_V &amp;lt;/math&amp;gt; against &amp;lt;math&amp;gt; T &amp;lt;/math&amp;gt;, together with the output images of this script.&lt;br /&gt;
 &lt;br /&gt;
[[File:HeatCapScript.PNG]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====2x2====&lt;br /&gt;
[[File:HC2.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====4x4====&lt;br /&gt;
[[File:HC4.png]]&lt;br /&gt;
&lt;br /&gt;
====8x8====&lt;br /&gt;
[[File:HC8.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====16x16====&lt;br /&gt;
[[File:HC16.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====32x32====&lt;br /&gt;
[[File:HC32.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= Locating the Curie Temperature =&lt;br /&gt;
&lt;br /&gt;
===C++ Data Comparison===&lt;br /&gt;
Below a comparison of the &amp;lt;math&amp;gt; C_V &amp;lt;/math&amp;gt; against &amp;lt;math&amp;gt; T &amp;lt;/math&amp;gt; plot generated for the &amp;lt;math&amp;gt; 2 /times 2&amp;lt;/math&amp;gt; to the corresponding C++ data is offered.&lt;br /&gt;
 &lt;br /&gt;
[[File:CHC2.png]]&lt;br /&gt;
&lt;br /&gt;
The data generated by the ILtemperaturerange.py script is a faithful match to the C++ data. However, this is an exceptional case; the plots for all other lattice sizes were found to be very dissimilar, necessitating polynomial fitting.&lt;br /&gt;
&lt;br /&gt;
==Polyfitting of C++ Data==&lt;br /&gt;
&lt;br /&gt;
===Fitting a Polynomial to the Entire Range===&lt;br /&gt;
The following Python script was written to perform a polynomial fit to the entire range of the graph of &amp;lt;math&amp;gt; C_V &amp;lt;/math&amp;gt; against &amp;lt;math&amp;gt; T &amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:HeatCapPoly.PNG]]&lt;br /&gt;
&lt;br /&gt;
Below, the result of the polyfit to the &amp;lt;math&amp;gt; 2/times2&amp;lt;/math&amp;gt; lattice data is offered (for comparison to the previous, non-fitted example).&lt;br /&gt;
&lt;br /&gt;
[[File:15Polyc2x2.png]]&lt;br /&gt;
&lt;br /&gt;
Polynomials with 5 terms and above were found to match the data in the vicinity of the critical region considerably well. Below 7 terms, the &#039;&#039;tails&#039;&#039; of the plot were matched poorly. In the above example, a polynomial of 15 terms was fit to the data.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Fitting a Polynomial to the Critical Region===&lt;br /&gt;
&lt;br /&gt;
The following Python script was written to perform a polynomial fit to the region of interest (the &#039;&#039;critical&#039;&#039; region) of the plots of &amp;lt;math&amp;gt; C_V &amp;lt;/math&amp;gt; against &amp;lt;math&amp;gt; T &amp;lt;/math&amp;gt; to facilitate the discovery of &amp;lt;math&amp;gt; T_C &amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
[[File:CapPolyCrit.PNG]]&lt;br /&gt;
&lt;br /&gt;
An example of the result returned by the script is offered below for the C++ data for the &amp;lt;math&amp;gt; 16\times16&amp;lt;/math&amp;gt; lattice.&lt;br /&gt;
&lt;br /&gt;
[[File:HHCPC16,2.6-2.1,5.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Finding the Peak C Values for Each Lattice Size===&lt;br /&gt;
Below, a screenshot of the code used to obtain the temperatures at which the maximum values of C occured is presented for each lattice size. The temperatures themselves are also featured on the image.&lt;br /&gt;
&lt;br /&gt;
[[File:Tmaxes.PNG]]&lt;br /&gt;
&lt;br /&gt;
The range of lattice sizes and their associated &amp;lt;math&amp;gt;T_{C} &amp;lt;/math&amp;gt; values were exported to a [[Media:Tmax.txt|text file]], enabling a plot to be created.&lt;br /&gt;
&lt;br /&gt;
[[File:CritTempPlot2.png]]&lt;br /&gt;
&lt;br /&gt;
Subsequently, the scipy.optimize.curve_fit function was used to fit &amp;lt;math&amp;gt;T_{C, L} = \frac{A}{L} + T_{C,\infty}&amp;lt;/math&amp;gt; function to the data obtained. This enabled the estimation the constant &amp;lt;math&amp;gt; A &amp;lt;/math&amp;gt; and the value of &amp;lt;math&amp;gt;T_{C} &amp;lt;/math&amp;gt; at &amp;lt;math&amp;gt; \frac{A}{L} = 0&amp;lt;/math&amp;gt;, otherwise &amp;lt;math&amp;gt; T_{C,\infty}&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
[[File:FindingTc.PNG]]&lt;br /&gt;
&lt;br /&gt;
A value of &amp;lt;math&amp;gt; T_{C,\infty} = 2.2799 &amp;lt;/math&amp;gt; was obtained. A comparison to the literature[https://en.wikipedia.org/wiki/Square-lattice_Ising_model#Critical_temperature] value of &amp;lt;math&amp;gt;2.269&amp;lt;/math&amp;gt; reveals a percentage error value of only &amp;lt;math&amp;gt; 0.47% &amp;lt;/math&amp;gt;. Surprisingly, the investigation of lattices in the given size range was enough to capture the theoretical behaviour of an infinite lattice. As explained by Frenkel and Smit, the implementation of periodic boundary conditions enables the simulation of an infinite bulk (or infinite adjacent lattices) surrounding the single lattice under scrutiny. The agreement of the experimental and theoretical values for &amp;lt;math&amp;gt; T_{C,\infty} &amp;lt;/math&amp;gt; prove the effectiveness of this idea.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
A likely source of error arises from the polynomial fitting of the data. The peaks in &amp;lt;math&amp;gt; C_V &amp;lt;/math&amp;gt; against &amp;lt;math&amp;gt; T &amp;lt;/math&amp;gt; were far more sharp than the broad peaks of the polynomial functions used to fit them. In several cases, the polynomial peak was a slight, yet discernible overestimate of the true peak. This has resulted in an overestimation of the final &amp;lt;math&amp;gt; T_{C,\infty} &amp;lt;/math&amp;gt; value. Fitting a function with a sharper peak (e.g. a Kronecker delta function) to the critical region could overcome this overestimation and provide a more faithful final value.&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
* Frenkel, Daan, et al. Understanding Molecular Simulation : From Algorithms to Applications, Elsevier Science &amp;amp; Technology, 2001&lt;br /&gt;
&lt;br /&gt;
* Krieger, M. Constitutions of matter : Mathematically modeling the most everyday of physical phenomena. Chicago ; London: University of Chicago Press, 1996&lt;br /&gt;
&lt;br /&gt;
* https://en.wikipedia.org/wiki/Square-lattice_Ising_model Accessed 13-11-18&lt;/div&gt;</summary>
		<author><name>Jj1516</name></author>
	</entry>
	<entry>
		<id>https://chemwiki.ch.ic.ac.uk/index.php?title=Rep:JJ1516Ising&amp;diff=736994</id>
		<title>Rep:JJ1516Ising</title>
		<link rel="alternate" type="text/html" href="https://chemwiki.ch.ic.ac.uk/index.php?title=Rep:JJ1516Ising&amp;diff=736994"/>
		<updated>2018-11-21T10:12:23Z</updated>

		<summary type="html">&lt;p&gt;Jj1516: /* Finding the Peak C Values for Each Lattice Size */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Ex Script Link:&lt;br /&gt;
https://wiki.ch.ic.ac.uk/wiki/index.php?title=Third_year_CMP_compulsory_experiment&lt;br /&gt;
&lt;br /&gt;
= Introduction to the Ising Model =&lt;br /&gt;
&lt;br /&gt;
== The Model ==&lt;br /&gt;
&lt;br /&gt;
=== Minimum Energy State ===&lt;br /&gt;
====Minimum Interaction Energy====&lt;br /&gt;
The interaction energy of an Ising lattice is given by:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;E = -\frac{1}{2}J\displaystyle\sum_{i}^{N} \displaystyle\sum_{j\;\in\;{neighbours}\;(i)} \!\!\!\!\!\!\!\!\!\!\!\!s_{i}s_{j}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In an Ising lattice with D dimensions and periodic boundary conditions, a given spin &amp;lt;math&amp;gt; s_i&amp;lt;/math&amp;gt; has 2D neighbours.&lt;br /&gt;
&lt;br /&gt;
The minimum interaction energy is achieved when all spins in the lattice are aligned (all ↑ or all ↓). As  such, any spin &amp;lt;math&amp;gt; s_i&amp;lt;/math&amp;gt; must be aligned with all 2D of its neighbours. That is, &amp;lt;math&amp;gt;s_{i}s_{j} = 1&amp;lt;/math&amp;gt; for all &amp;lt;math&amp;gt;j&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Therefore, for any &amp;lt;math&amp;gt; s_i&amp;lt;/math&amp;gt;, the sum of its interactions is &amp;lt;math&amp;gt;\displaystyle\sum_{j\;\in\;{neighbours}\;(i)} \!\!\!\!\!\!\!\!\!\!\!\!s_{i}s_{j} = 2D &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
As this is true for all N spins in the lattice, it follows that &amp;lt;math&amp;gt;\displaystyle\sum_{i}^{N} 2D = 2DN&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Thus the minimum interaction energy is given by:&lt;br /&gt;
&lt;br /&gt;
:&amp;lt;math&amp;gt;E_{min} = -\frac{1}{2}J\cdot2DN = - DNJ &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Entropy of the Minimum Energy State====&lt;br /&gt;
&lt;br /&gt;
The entropy of a state is given by:&lt;br /&gt;
&lt;br /&gt;
:&amp;lt;math&amp;gt;S = k\; ln\; \Omega &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Where &amp;lt;math&amp;gt; \Omega &amp;lt;/math&amp;gt; is the multiplicity of the state, the number of degenerate configurations of said state. The minimum energy state is achievable with all spins ↑ or with all spins ↓. In the absence of an external magnetic field, these configurations are degenerate and indistinguishable giving &amp;lt;math&amp;gt; \Omega = 2 &amp;lt;/math&amp;gt; for this state. Therefore,&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; S_{E_{min}}  = k_{B}\; ln\; 2 = 0.693k_{B} = 9.57 \times 10^{-24} J\!\cdot\!\! K^{-1}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Phase Transitions ==&lt;br /&gt;
&lt;br /&gt;
=== Changes to Minimum Energy Configuration ===&lt;br /&gt;
&lt;br /&gt;
====Energy Change ====&lt;br /&gt;
The energy change &amp;lt;math&amp;gt; \Delta E&amp;lt;/math&amp;gt; associated with a single spin &#039;flip&#039; from the lowest energy onfiguration may be calculated by considering the change in the interaction energy with the spin&#039;s neighbours.&lt;br /&gt;
&lt;br /&gt;
Let &amp;lt;math&amp;gt; D = 3, N = 1000 &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\Delta{E} = E_1 - E_0&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;E_1&amp;lt;/math&amp;gt; Interaction energy after one spin has been &#039;flipped&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;E_0&amp;lt;/math&amp;gt; Lowest energy configuration&lt;br /&gt;
&lt;br /&gt;
[[Image:Task 2 table.PNG]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\displaystyle\sum_{interactions} = -2D + 2D(2D-2) + 2D[N-(2D+1)] &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; = 2DN - 8D &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;E_1 = \displaystyle-\frac{1}{2}J\;\sum_{interactions} = 4DJ - DNJ&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\Delta{E} = E_1 - E_0 = 4DJ - DNJ + DNJ = +4DJ = +12J&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This energy change is independent of &amp;lt;math&amp;gt; N&amp;lt;/math&amp;gt; and depends only on the dimension size and the coupling constant &amp;lt;math&amp;gt; J &amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
In this calculation, the following assumption has been made.&lt;br /&gt;
&lt;br /&gt;
* The lattice dimensions are infinite relative to the size of each cell&lt;br /&gt;
&lt;br /&gt;
This allows &#039;&#039;&#039;any&#039;&#039;&#039; cell to be treated as the centre of the lattice. As every cell interacts with 2D neighbours, flipping any cell in the minimum energy configuration results in the same energy change. Alternatively, the periodic boundary conditions of the Ising model remove the necessity for such an assumption. As a consequence, the absence of &amp;lt;math&amp;gt; N &amp;lt;/math&amp;gt; from the resulting energy change is justified.&lt;br /&gt;
&lt;br /&gt;
====Entropy Change====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; S = k_{B}\; ln\; \Omega &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\Omega = \displaystyle\frac{N!}{{N_{\uparrow}!}{N_{\downarrow}!}}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Where &amp;lt;math&amp;gt;N_{x}!&amp;lt;/math&amp;gt; denotes the factorial of the number of spins in spin state &amp;lt;math&amp;gt;x&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\Delta{S} = k_{B}\;ln\;\left(\displaystyle\frac{\Omega_{2}}{\Omega_{1}}\right)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\Omega_{2} = \frac{1000!}{999!1!} = 1000&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \Omega_{1} = \frac{1000!}{1000!} = 1&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\Delta{S} = k_{B}\;ln\;1000 = 9.54 \times 10^{-23} JK^{-1}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\Delta{S_{mol}} = N_{A}k_{B}\;ln\;1000 = 57.4 \,JK^{-1}mol^{-1}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Magnetisation Values of 1D and 2D Lattices===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;M = \sum_i s_i&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====1D Lattice Magnetisation====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;M_{1D} =\;\;+1&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====2D Lattice Magnetisation====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;M_{2D} =\;\;+1&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Magnetisation at 0K====&lt;br /&gt;
&lt;br /&gt;
At 0K, no thermal energy is available to overcome the energetic barriers to spin flipping. Considering the Hemholtz free energy:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; A = E - TS &amp;lt;/math&amp;gt; &lt;br /&gt;
&lt;br /&gt;
A temperature of 0K nullifies the entropic contribution to the free energy. Thus the energetic driving force (which maximises parallel spin interactions) dominates the entropic driving force (which maximises multiplicity of lattice states). For an Ising Lattice with D =  3, N = 1000 at 0K, the alignment of all spins results in the minimum energy configuration  and an overall magnetisation of &amp;lt;math&amp;gt; M = \pm 1000 &amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
= Calculating the Energy and Magnetisation =&lt;br /&gt;
==Modifying the Files==&lt;br /&gt;
&lt;br /&gt;
===Energy and Magnetisation Functions===&lt;br /&gt;
&lt;br /&gt;
====Energy===&lt;br /&gt;
[[File:First_Ene_Method.PNG]]&lt;br /&gt;
&lt;br /&gt;
The above energy method segments a given lattice into lattice cells on the edges, corners or in the bulk of the lattice and calculates the energy interactions with its neighbours as appropriate.&lt;br /&gt;
&lt;br /&gt;
====Magnetisation====&lt;br /&gt;
[[File:First_Mag_Method.PNG]]&lt;br /&gt;
&lt;br /&gt;
The magnetisation method loops over all elements in the array representing the Ising lattice and adds the value of the spin to the magnetisation variable.&lt;br /&gt;
&lt;br /&gt;
==Testing the Files==&lt;br /&gt;
&lt;br /&gt;
===ILCheck.py===&lt;br /&gt;
&lt;br /&gt;
[[File:ILChecks.PNG]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Above, the results of the ILcheck.py script are presented.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= Introduction to the Monte Carlo Simulation =&lt;br /&gt;
==Average Energy and Magnetisation==&lt;br /&gt;
===Configurations of a 100 Spin System===&lt;br /&gt;
For a system of two spins, 4 configurations are possible (↑↑, ↓↓, ↑↓, ↓↑) i.e. &amp;lt;math&amp;gt;2^{2}&amp;lt;/math&amp;gt;. For a system of 100 spins, there are &amp;lt;math&amp;gt;2^{100}&amp;lt;/math&amp;gt; configurations. In the first example, the ↑↑ and ↓↓ are degenerate, as are the ↑↓ and ↓↑ configurations. Therefore, dividing the number of possible configurations by the multiplicity of each configuration (&amp;lt;math&amp;gt;2&amp;lt;/math&amp;gt;) gives the number of non-degenerate configurations. As previously stated, degenerate configurations are indistinguishable in the absence of an external magnetic field.&lt;br /&gt;
&lt;br /&gt;
For 100 spins, this gives &amp;lt;math&amp;gt;\displaystyle\frac{2^{100}}{2} = 6.338 \times 10^{29} &amp;lt;/math&amp;gt; distinguishable configurations.&lt;br /&gt;
&lt;br /&gt;
If processing speed permits &amp;lt;math&amp;gt; 1 \times 10^{9}&amp;lt;/math&amp;gt; calculations each second, the evaluation of a single value of &amp;lt;math&amp;gt;\left\langle M\right\rangle_T&amp;lt;/math&amp;gt; would last &amp;lt;math&amp;gt; 6.338 \times 10^{20} &amp;lt;/math&amp;gt; seconds or &amp;lt;math&amp;gt; 1458 &amp;lt;/math&amp;gt; times the age of the Universe!&lt;br /&gt;
&lt;br /&gt;
==Modifying IsingLattice.py==&lt;br /&gt;
&lt;br /&gt;
===Monte Carlo and Statistics Methods===&lt;br /&gt;
[[File:Monte_Carlo.PNG]]&lt;br /&gt;
&lt;br /&gt;
[[File:stats.PNG]]&lt;br /&gt;
&lt;br /&gt;
The Metropolis Monte Carlo (MMC) algorithm provides a computationally inexpensive path from random initial states to the minimum free energy states of the Ising lattices generated. First, a random 2D Ising lattice is generated. A single random spin within this lattice is &amp;quot;flipped&amp;quot; and the resulting (internal) energy change between these states is measured. Recalling the relationship between the Hemholtz free energy, internal energy and entropy, it follows that a decrease in internal energy also lowers the free energy of the system: thus the configuration change is accepted.&lt;br /&gt;
&lt;br /&gt;
In the case that the spin &amp;quot;flip&amp;quot; does not lower the internal energy, the MMC algorithm tests this configuration change against the Boltzman factor. In the canonical (NVT) ensemble, the free energy of the system is given by:&lt;br /&gt;
&lt;br /&gt;
:&amp;lt;math&amp;gt;A = -k_{B}T\,lnZ_{NVT} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
where Z is the canonical partition function which depends upon &amp;lt;math&amp;gt; e^{-\frac{\Delta E}{k_BT}} &amp;lt;/math&amp;gt;, the Boltzman factor. By choosing a random value in the interval [0,1)from a continuous uniformm probability distribution and rejecting any value of the Boltzman factor less than this value, the MMC algorithm allows for configuration changes with small, positive internal energy changes if they conform to the Boltzman probability distribution. Alternatively, the MMC allows small perturbations to the internal energy which prevents the system from settling in a metastable internal energy minimum and instead, ensures that the system equilibrates around the &#039;&#039;true&#039;&#039; free energy minimum.&lt;br /&gt;
&lt;br /&gt;
===Spontaneous Magnetisation===&lt;br /&gt;
&lt;br /&gt;
Below the Curie Temperature, &amp;lt;math&amp;gt; T_{C} &amp;lt;/math&amp;gt;, the energetic driving force dominates the entropic driving force, resulting in a highly ordered system and an overall magnetisation. The spins of the system align in order to maximise favourable coupling interactions rather than adopting a less ordered configuration of higher multiplicity. Therefore, when &amp;lt;math&amp;gt;T &amp;lt; T_C&amp;lt;/math&amp;gt;, the most probable configurations have an overall magnetisation resulting in &amp;lt;math&amp;gt;\left\langle M\right\rangle \neq 0&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
The plots of magnetisation per spin and energy per spin obtained from ILanim.py support this prediction. Below, the plots show that upon equilibration, the system adopts the minimum energy per spin: &amp;lt;math&amp;gt;E_{min_{spin}} = \frac{-NDJ}{N} = -DJ = -2&amp;lt;/math&amp;gt; and exhibits the maximum magnitude of magnetisation per spin: &amp;lt;math&amp;gt;|M_{spin}| = 1&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:2T=1.0.png]]&lt;br /&gt;
[[File:T=1.0.png]]&lt;br /&gt;
[[File:3T=1.0.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
An unknown system error prevented the statistics() function from printing the average values.&lt;br /&gt;
&lt;br /&gt;
=Accelerating the Code=&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Initial Method Speeds===&lt;br /&gt;
Taking 10 repeat measurements for the time taken to perform 2000 Monte Carlo steps resulted in&lt;br /&gt;
&lt;br /&gt;
* An average time of  &amp;lt;math&amp;gt;11.7s&amp;lt;/math&amp;gt; &lt;br /&gt;
* A standard error of &amp;lt;math&amp;gt;0.020s&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Updating Measurement===&lt;br /&gt;
&lt;br /&gt;
NOTE: ILtimetrial.py has been modified to:&lt;br /&gt;
* Perform a requested number of &#039;2000 Monte Carlo Step&#039; measurements&lt;br /&gt;
* Record these measurements in a CSV file&lt;br /&gt;
* Return the mean measuremd time and the Standard Error i.e.   &amp;lt;math&amp;gt; \frac{\sigma}{n} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:TimeTrialMethod.PNG]]&lt;br /&gt;
&lt;br /&gt;
===Updating Energy and Magnetisation Methods===&lt;br /&gt;
[[File:New_Mag_Method.PNG]]&lt;br /&gt;
[[File:New_Ene_Method.PNG]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Updated Method Speeds===&lt;br /&gt;
[[File:TimeTrial.PNG]]&lt;br /&gt;
&lt;br /&gt;
Taking 30 measurements of the time taken to perform 2000 Monte Carlo Steps resulted in:&lt;br /&gt;
&lt;br /&gt;
* An average time of &amp;lt;math&amp;gt;\displaystyle{0.87s}&amp;lt;/math&amp;gt;&lt;br /&gt;
* A standard error of &amp;lt;math&amp;gt;2.5 \times 10^{-3}s&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This represents a 93% decrease in the average computation time from the initial methods.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=The Effect of Temperature=&lt;br /&gt;
&lt;br /&gt;
==Correcting the Averaging  Code==&lt;br /&gt;
&lt;br /&gt;
===Finding a Delay Value===&lt;br /&gt;
To quickly find a value for &amp;lt;math&amp;gt; N_{d}&amp;lt;/math&amp;gt;, the minimum number of cycles typically needed for the equilibration of a system of within the lattice and temperature ranges of interest, it was assumed that:&lt;br /&gt;
&lt;br /&gt;
* Larger lattices would require more Monte Carlo steps to reach equilibrium from their initial, random configurations&lt;br /&gt;
&lt;br /&gt;
* Lattices at lower temperatures would require more Monte Carlo steps to reach equilibrium from their initial, random configurations.&lt;br /&gt;
&lt;br /&gt;
Therefore, an initial value for &amp;lt;math&amp;gt; N_{d}&amp;lt;/math&amp;gt; was found for a &amp;lt;math&amp;gt; 128\times128 &amp;lt;/math&amp;gt; lattice at a temperature of &amp;lt;math&amp;gt;0.5&amp;lt;/math&amp;gt; reduced temperature units.&lt;br /&gt;
*&amp;lt;math&amp;gt; N_{d} = 185000 &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
By this number of steps, all smaller lattices at all higher temperatures were found to have equilibrated also. Thus, this value of&amp;lt;math&amp;gt; N_{d}&amp;lt;/math&amp;gt; was accepted as an appropriate delay.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:AFinFrame 128 3e5 T= 0.5line.png|400px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
For the 128x128 lattices at T=0.5, equilibration was ensured from 185000 steps onwards.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Smaller lattices at the same temperature did indeed equilibrate more slowly, but all equilibrated within &amp;lt;math&amp;gt; N_{d}&amp;lt;/math&amp;gt; MC steps.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:AFinFrame 64 3e5 T= 0.5line.png|400px]]&lt;br /&gt;
[[File:AFinFrame 32 3e5 T= 0.5line2.png|400px]]&lt;br /&gt;
[[File:AFinFrame 16 3e5 T= 0.5line2.png|400px]]&lt;br /&gt;
[[File:AFinFrame 8 3e5 T= 0.5line.png|400px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The figure below shows the modifications made to IsingLattice.py to incorporate the &amp;lt;math&amp;gt; N_{d} &amp;lt;/math&amp;gt; step delay.&lt;br /&gt;
&lt;br /&gt;
==Running over a Range of Temperatures==&lt;br /&gt;
&lt;br /&gt;
To examine the effect of temperature on the average energy &amp;lt;math&amp;gt; \left\langle E\right\rangle &amp;lt;/math&amp;gt; and average magnetisation &amp;lt;math&amp;gt; \left\langle M\right\rangle &amp;lt;/math&amp;gt; of Ising lattices at equilibrium, the following parameters were used:&lt;br /&gt;
&lt;br /&gt;
* Temperature Range: &amp;lt;math&amp;gt;  0.5 - 5 &amp;lt;/math&amp;gt; reduced units&lt;br /&gt;
* Temperature Interval: &amp;lt;math&amp;gt;0.01&amp;lt;/math&amp;gt; reduced units (&amp;lt;math&amp;gt;450&amp;lt;/math&amp;gt; temperature values)&lt;br /&gt;
* Number of MMC Steps per Temperature value: &amp;lt;math&amp;gt; 2 \times 10^5 &amp;lt;/math&amp;gt; with the aforementioned value of &amp;lt;math&amp;gt; N_{d} = 1.85 \times 10^5 &amp;lt;/math&amp;gt; Monte Carlo steps&lt;br /&gt;
* Lattice Sizes:  &amp;lt;math&amp;gt; 2 \times 2 &amp;lt;/math&amp;gt;, &amp;lt;math&amp;gt; 4 \times 4 &amp;lt;/math&amp;gt; , &amp;lt;math&amp;gt; 8 \times 8 &amp;lt;/math&amp;gt; , &amp;lt;math&amp;gt; 16 \times 16 &amp;lt;/math&amp;gt; , &amp;lt;math&amp;gt; 32 \times 32 &amp;lt;/math&amp;gt; , &amp;lt;math&amp;gt; 64 \times 64 &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Plots of  &amp;lt;math&amp;gt; \left\langle E\right\rangle &amp;lt;/math&amp;gt; and  &amp;lt;math&amp;gt; \left\langle M\right\rangle &amp;lt;/math&amp;gt; per spin as versus temperature are presented below for each lattice size. Errorbars have been implemented to demonstrate how &#039;&#039;well-behaved&#039;&#039; lattice systems of each size are at each temperature, that is, how temperature and lattice size affect the size of the variations in the expected values. For the error calculations, the standard errors, &amp;lt;math&amp;gt; \sigma_\bar{X} &amp;lt;/math&amp;gt;,  in &amp;lt;math&amp;gt; \left\langle E\right\rangle &amp;lt;/math&amp;gt; and  &amp;lt;math&amp;gt; \left\langle M\right\rangle &amp;lt;/math&amp;gt; per spin have been used:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====8x8====&lt;br /&gt;
&lt;br /&gt;
[[File:8x8e+error.png]] [[File:8x8m+error.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
A Python script has been written to generate a plot of &amp;lt;math&amp;gt;\left\langle E\right\rangle&amp;lt;/math&amp;gt; or &amp;lt;math&amp;gt;\left\langle M\right\rangle&amp;lt;/math&amp;gt; against temperature based upon user input. A screenshot of this code has been inserted below.&lt;br /&gt;
&lt;br /&gt;
[[File:ExpectedvsTemp.PNG|200px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=The Effect of System Size=&lt;br /&gt;
&lt;br /&gt;
==Scaling the System Size==&lt;br /&gt;
&lt;br /&gt;
===More Lattice Sizes===&lt;br /&gt;
&lt;br /&gt;
====2x2====&lt;br /&gt;
[[File:2x2e+error.png]] [[File:2x2m+error.png]]&lt;br /&gt;
&lt;br /&gt;
====4x4====&lt;br /&gt;
[[File:4x4e+error.png]] [[File:4x4m+error.png]]&lt;br /&gt;
&lt;br /&gt;
====16x16====&lt;br /&gt;
[[File:16x16e+error.png]] [[File:16x16m+error.png]]&lt;br /&gt;
&lt;br /&gt;
====32x32====&lt;br /&gt;
[[File:32x32e+error.png]] [[File:32x32m+error.png]]&lt;br /&gt;
&lt;br /&gt;
====64x64====&lt;br /&gt;
[[File:64x64e+error.png]] [[File:64x64m+error.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Scrutiny of the plots of average energy per spin for each lattice size reveals an increase in the errorbar width with increasing lattice size. This is most notable in the low temperature region of the plots. Between the &amp;lt;math&amp;gt; 8\times8 &amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt; 16\times16 &amp;lt;/math&amp;gt; lattices, the long range fluctuations become suddenly prominent. The &amp;lt;math&amp;gt;16\times16&amp;lt;/math&amp;gt; lattice is the first (in the range of sizes tested)to clearly capture these fluctuations.&lt;br /&gt;
&lt;br /&gt;
=Determining the Heat Capacity=&lt;br /&gt;
&lt;br /&gt;
==Calculating the Heat Capacity==&lt;br /&gt;
&lt;br /&gt;
===Heat Capacity Derivation===&lt;br /&gt;
Working in the canonical ensemble (constant volume), the heat capacity &amp;lt;math&amp;gt; C_V &amp;lt;/math&amp;gt; is given by:&lt;br /&gt;
&lt;br /&gt;
:&amp;lt;math&amp;gt;C_V = \frac{\partial \left\langle E\right\rangle}{\partial T}_V&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
where &amp;lt;math&amp;gt;\left\langle E\right\rangle&amp;lt;/math&amp;gt; is the average total energy or expected value of the internal energy of the system.&lt;br /&gt;
&lt;br /&gt;
: &amp;lt;math&amp;gt; \left\langle E\right\rangle = - \frac{\partial ln Q}{\partial \beta} = -\frac{1}{Q}\frac{\partial Q}{\partial \beta} &amp;lt;/math&amp;gt;&lt;br /&gt;
where &amp;lt;math&amp;gt; Q&amp;lt;/math&amp;gt; is the partition function for the system of N interacting spins.&lt;br /&gt;
&lt;br /&gt;
By evaluating the second form of the partial derivative with respect to &amp;lt;math&amp;gt; \beta&amp;lt;/math&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \left\langle E\right\rangle = -\frac{1}{Q}\frac{\partial Q}{\partial \beta} = \frac{\Sigma \epsilon_{i} e^{-\beta \epsilon_{i}}}{\Sigma e^{-\beta \epsilon_{i}}} &amp;lt;/math&amp;gt; &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Applying the product rule enables the differentiation of this expression for &amp;lt;math&amp;gt;\left\langle E\right\rangle&amp;lt;/math&amp;gt; with respect to temperature, giving:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\frac{\partial \left\langle E\right\rangle}{\partial T} = \frac{\Sigma \epsilon_{i} \frac{\epsilon_i}{k_BT^2}e^{-\beta \epsilon_{i}}}{\Sigma e^{-\beta \epsilon_{i}}} - \frac{\Sigma \epsilon_i e^{-\beta \epsilon_i}\cdot \frac{\epsilon_i}{k_BT^2}e^{-\beta \epsilon_i}}{(\Sigma e^{-\beta \epsilon_{i}})^2}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\frac{\partial \left\langle E\right\rangle}{\partial T}  = \frac{1}{k_BT^2}\left[\frac{\Sigma \epsilon_i^2 e^{-\beta \epsilon_i}}{\Sigma e^{-\beta \epsilon_i}} - \left(\frac{\Sigma \epsilon_{i} e^{-\beta \epsilon_{i}}}{\Sigma e^{-\beta \epsilon_{i}}}\right)^2\right] &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\frac{\partial \left\langle E\right\rangle}{\partial T}  = \frac{1}{k_BT^2}\left[\left\langle E^2\right\rangle - \left\langle E\right\rangle^2 \right] &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Thus,&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\frac{\partial \left\langle E\right\rangle}{\partial T} = \frac{Var[E]}{k_BT^2} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Heat Capacity versus Temperature===&lt;br /&gt;
Below, a screenshot of the Python script written to produce plots of &amp;lt;math&amp;gt; C_V &amp;lt;/math&amp;gt; against &amp;lt;math&amp;gt; T &amp;lt;/math&amp;gt;, together with the output images of this script.&lt;br /&gt;
 &lt;br /&gt;
[[File:HeatCapScript.PNG]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====2x2====&lt;br /&gt;
[[File:HC2.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====4x4====&lt;br /&gt;
[[File:HC4.png]]&lt;br /&gt;
&lt;br /&gt;
====8x8====&lt;br /&gt;
[[File:HC8.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====16x16====&lt;br /&gt;
[[File:HC16.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====32x32====&lt;br /&gt;
[[File:HC32.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= Locating the Curie Temperature =&lt;br /&gt;
&lt;br /&gt;
===C++ Data Comparison===&lt;br /&gt;
Below a comparison of the &amp;lt;math&amp;gt; C_V &amp;lt;/math&amp;gt; against &amp;lt;math&amp;gt; T &amp;lt;/math&amp;gt; plot generated for the &amp;lt;math&amp;gt; 2 /times 2&amp;lt;/math&amp;gt; to the corresponding C++ data is offered.&lt;br /&gt;
 &lt;br /&gt;
[[File:CHC2.png]]&lt;br /&gt;
&lt;br /&gt;
The data generated by the ILtemperaturerange.py script is a faithful match to the C++ data. However, this is an exceptional case; the plots for all other lattice sizes were found to be very dissimilar, necessitating polynomial fitting.&lt;br /&gt;
&lt;br /&gt;
==Polyfitting of C++ Data==&lt;br /&gt;
&lt;br /&gt;
===Fitting a Polynomial to the Entire Range===&lt;br /&gt;
The following Python script was written to perform a polynomial fit to the entire range of the graph of &amp;lt;math&amp;gt; C_V &amp;lt;/math&amp;gt; against &amp;lt;math&amp;gt; T &amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:HeatCapPoly.PNG]]&lt;br /&gt;
&lt;br /&gt;
Below, the result of the polyfit to the &amp;lt;math&amp;gt; 2/times2&amp;lt;/math&amp;gt; lattice data is offered (for comparison to the previous, non-fitted example).&lt;br /&gt;
&lt;br /&gt;
[[File:15Polyc2x2.png]]&lt;br /&gt;
&lt;br /&gt;
Polynomials with 5 terms and above were found to match the data in the vicinity of the critical region considerably well. Below 7 terms, the &#039;&#039;tails&#039;&#039; of the plot were matched poorly. In the above example, a polynomial of 15 terms was fit to the data.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Fitting a Polynomial to the Critical Region===&lt;br /&gt;
&lt;br /&gt;
The following Python script was written to perform a polynomial fit to the region of interest (the &#039;&#039;critical&#039;&#039; region) of the plots of &amp;lt;math&amp;gt; C_V &amp;lt;/math&amp;gt; against &amp;lt;math&amp;gt; T &amp;lt;/math&amp;gt; to facilitate the discovery of &amp;lt;math&amp;gt; T_C &amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
[[File:CapPolyCrit.PNG]]&lt;br /&gt;
&lt;br /&gt;
An example of the result returned by the script is offered below for the C++ data for the &amp;lt;math&amp;gt; 16\times16&amp;lt;/math&amp;gt; lattice.&lt;br /&gt;
&lt;br /&gt;
[[File:HHCPC16,2.6-2.1,5.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Finding the Peak C Values for Each Lattice Size===&lt;br /&gt;
Below, a screenshot of the code used to obtain the temperatures at which the maximum values of C occured is presented for each lattice size. The temperatures themselves are also featured on the image.&lt;br /&gt;
&lt;br /&gt;
[[File:Tmaxes.PNG]]&lt;br /&gt;
&lt;br /&gt;
The range of lattice sizes and their associated &amp;lt;math&amp;gt;T_{C} &amp;lt;/math&amp;gt; values were exported to a [[Media:Tmax.txt|text file]], enabling a plot to be created.&lt;br /&gt;
&lt;br /&gt;
[[File:CritTempPlot2.png]]&lt;br /&gt;
&lt;br /&gt;
Subsequently, the scipy.optimize.curve_fit function was used to fit &amp;lt;math&amp;gt;T_{C, L} = \frac{A}{L} + T_{C,\infty}&amp;lt;/math&amp;gt; function to the data obtained. This enabled the estimation the constant &amp;lt;math&amp;gt; A &amp;lt;/math&amp;gt; and the value of &amp;lt;math&amp;gt;T_{C} &amp;lt;/math&amp;gt; at &amp;lt;math&amp;gt; \frac{A}{L} = 0&amp;lt;/math&amp;gt;, otherwise &amp;lt;math&amp;gt; T_{C,\infty}&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
[[File:FindingTc.PNG]]&lt;br /&gt;
&lt;br /&gt;
A value of &amp;lt;math&amp;gt; T_{C,\infty} = 2.2799 &amp;lt;/math&amp;gt; was obtained. A comparison to the literature[https://en.wikipedia.org/wiki/Square-lattice_Ising_model#Critical_temperature] value of &amp;lt;math&amp;gt;2.269&amp;lt;/math&amp;gt; reveals a percentage error value of only &amp;lt;math&amp;gt; 0.47% &amp;lt;/math&amp;gt;. Surprisingly, the investigation of lattices in the given size range was enough to capture the theoretical behaviour of an infinite lattice. As explained by Frenkel and Smit, the implementation of periodic boundary conditions enables the simulation of an infinite bulk (or infinite adjacent lattices) surrounding the single lattice under scrutiny. The agreement of the experimental and theoretical values for &amp;lt;math&amp;gt; T_{C,\infty} &amp;lt;/math&amp;gt; prove the effectiveness of this idea.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
A likely source of error arises from the polynomial fitting of the data. The peaks in &amp;lt;math&amp;gt; C_V &amp;lt;/math&amp;gt; against &amp;lt;math&amp;gt; T &amp;lt;/math&amp;gt; were far more sharp than the broad peaks of the polynomial functions used to fit them. In several cases, the polynomial peak was a slight, yet discernible overestimate of the true peak. This has resulted in an overestimation of the final &amp;lt;math&amp;gt; T_{C,\infty} &amp;lt;/math&amp;gt; value. Fitting a function with a sharper peak (e.g. a Kronecker delta function) to the critical region could overcome this overestimation and provide a more faithful final value.&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
* Frenkel, Daan, et al. Understanding Molecular Simulation : From Algorithms to Applications, Elsevier Science &amp;amp; Technology, 2001&lt;br /&gt;
&lt;br /&gt;
* Krieger, M. Constitutions of matter : Mathematically modeling the most everyday of physical phenomena. Chicago ; London: University of Chicago Press, 1996&lt;br /&gt;
&lt;br /&gt;
* https://en.wikipedia.org/wiki/Square-lattice_Ising_model Accessed 13-11-18&lt;/div&gt;</summary>
		<author><name>Jj1516</name></author>
	</entry>
	<entry>
		<id>https://chemwiki.ch.ic.ac.uk/index.php?title=Rep:JJ1516Ising&amp;diff=736990</id>
		<title>Rep:JJ1516Ising</title>
		<link rel="alternate" type="text/html" href="https://chemwiki.ch.ic.ac.uk/index.php?title=Rep:JJ1516Ising&amp;diff=736990"/>
		<updated>2018-11-21T10:09:22Z</updated>

		<summary type="html">&lt;p&gt;Jj1516: /* Monte Carlo and Statistics Methods */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Ex Script Link:&lt;br /&gt;
https://wiki.ch.ic.ac.uk/wiki/index.php?title=Third_year_CMP_compulsory_experiment&lt;br /&gt;
&lt;br /&gt;
= Introduction to the Ising Model =&lt;br /&gt;
&lt;br /&gt;
== The Model ==&lt;br /&gt;
&lt;br /&gt;
=== Minimum Energy State ===&lt;br /&gt;
====Minimum Interaction Energy====&lt;br /&gt;
The interaction energy of an Ising lattice is given by:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;E = -\frac{1}{2}J\displaystyle\sum_{i}^{N} \displaystyle\sum_{j\;\in\;{neighbours}\;(i)} \!\!\!\!\!\!\!\!\!\!\!\!s_{i}s_{j}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In an Ising lattice with D dimensions and periodic boundary conditions, a given spin &amp;lt;math&amp;gt; s_i&amp;lt;/math&amp;gt; has 2D neighbours.&lt;br /&gt;
&lt;br /&gt;
The minimum interaction energy is achieved when all spins in the lattice are aligned (all ↑ or all ↓). As  such, any spin &amp;lt;math&amp;gt; s_i&amp;lt;/math&amp;gt; must be aligned with all 2D of its neighbours. That is, &amp;lt;math&amp;gt;s_{i}s_{j} = 1&amp;lt;/math&amp;gt; for all &amp;lt;math&amp;gt;j&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Therefore, for any &amp;lt;math&amp;gt; s_i&amp;lt;/math&amp;gt;, the sum of its interactions is &amp;lt;math&amp;gt;\displaystyle\sum_{j\;\in\;{neighbours}\;(i)} \!\!\!\!\!\!\!\!\!\!\!\!s_{i}s_{j} = 2D &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
As this is true for all N spins in the lattice, it follows that &amp;lt;math&amp;gt;\displaystyle\sum_{i}^{N} 2D = 2DN&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Thus the minimum interaction energy is given by:&lt;br /&gt;
&lt;br /&gt;
:&amp;lt;math&amp;gt;E_{min} = -\frac{1}{2}J\cdot2DN = - DNJ &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Entropy of the Minimum Energy State====&lt;br /&gt;
&lt;br /&gt;
The entropy of a state is given by:&lt;br /&gt;
&lt;br /&gt;
:&amp;lt;math&amp;gt;S = k\; ln\; \Omega &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Where &amp;lt;math&amp;gt; \Omega &amp;lt;/math&amp;gt; is the multiplicity of the state, the number of degenerate configurations of said state. The minimum energy state is achievable with all spins ↑ or with all spins ↓. In the absence of an external magnetic field, these configurations are degenerate and indistinguishable giving &amp;lt;math&amp;gt; \Omega = 2 &amp;lt;/math&amp;gt; for this state. Therefore,&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; S_{E_{min}}  = k_{B}\; ln\; 2 = 0.693k_{B} = 9.57 \times 10^{-24} J\!\cdot\!\! K^{-1}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Phase Transitions ==&lt;br /&gt;
&lt;br /&gt;
=== Changes to Minimum Energy Configuration ===&lt;br /&gt;
&lt;br /&gt;
====Energy Change ====&lt;br /&gt;
The energy change &amp;lt;math&amp;gt; \Delta E&amp;lt;/math&amp;gt; associated with a single spin &#039;flip&#039; from the lowest energy onfiguration may be calculated by considering the change in the interaction energy with the spin&#039;s neighbours.&lt;br /&gt;
&lt;br /&gt;
Let &amp;lt;math&amp;gt; D = 3, N = 1000 &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\Delta{E} = E_1 - E_0&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;E_1&amp;lt;/math&amp;gt; Interaction energy after one spin has been &#039;flipped&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;E_0&amp;lt;/math&amp;gt; Lowest energy configuration&lt;br /&gt;
&lt;br /&gt;
[[Image:Task 2 table.PNG]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\displaystyle\sum_{interactions} = -2D + 2D(2D-2) + 2D[N-(2D+1)] &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; = 2DN - 8D &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;E_1 = \displaystyle-\frac{1}{2}J\;\sum_{interactions} = 4DJ - DNJ&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\Delta{E} = E_1 - E_0 = 4DJ - DNJ + DNJ = +4DJ = +12J&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This energy change is independent of &amp;lt;math&amp;gt; N&amp;lt;/math&amp;gt; and depends only on the dimension size and the coupling constant &amp;lt;math&amp;gt; J &amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
In this calculation, the following assumption has been made.&lt;br /&gt;
&lt;br /&gt;
* The lattice dimensions are infinite relative to the size of each cell&lt;br /&gt;
&lt;br /&gt;
This allows &#039;&#039;&#039;any&#039;&#039;&#039; cell to be treated as the centre of the lattice. As every cell interacts with 2D neighbours, flipping any cell in the minimum energy configuration results in the same energy change. Alternatively, the periodic boundary conditions of the Ising model remove the necessity for such an assumption. As a consequence, the absence of &amp;lt;math&amp;gt; N &amp;lt;/math&amp;gt; from the resulting energy change is justified.&lt;br /&gt;
&lt;br /&gt;
====Entropy Change====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; S = k_{B}\; ln\; \Omega &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\Omega = \displaystyle\frac{N!}{{N_{\uparrow}!}{N_{\downarrow}!}}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Where &amp;lt;math&amp;gt;N_{x}!&amp;lt;/math&amp;gt; denotes the factorial of the number of spins in spin state &amp;lt;math&amp;gt;x&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\Delta{S} = k_{B}\;ln\;\left(\displaystyle\frac{\Omega_{2}}{\Omega_{1}}\right)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\Omega_{2} = \frac{1000!}{999!1!} = 1000&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \Omega_{1} = \frac{1000!}{1000!} = 1&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\Delta{S} = k_{B}\;ln\;1000 = 9.54 \times 10^{-23} JK^{-1}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\Delta{S_{mol}} = N_{A}k_{B}\;ln\;1000 = 57.4 \,JK^{-1}mol^{-1}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Magnetisation Values of 1D and 2D Lattices===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;M = \sum_i s_i&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====1D Lattice Magnetisation====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;M_{1D} =\;\;+1&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====2D Lattice Magnetisation====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;M_{2D} =\;\;+1&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Magnetisation at 0K====&lt;br /&gt;
&lt;br /&gt;
At 0K, no thermal energy is available to overcome the energetic barriers to spin flipping. Considering the Hemholtz free energy:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; A = E - TS &amp;lt;/math&amp;gt; &lt;br /&gt;
&lt;br /&gt;
A temperature of 0K nullifies the entropic contribution to the free energy. Thus the energetic driving force (which maximises parallel spin interactions) dominates the entropic driving force (which maximises multiplicity of lattice states). For an Ising Lattice with D =  3, N = 1000 at 0K, the alignment of all spins results in the minimum energy configuration  and an overall magnetisation of &amp;lt;math&amp;gt; M = \pm 1000 &amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
= Calculating the Energy and Magnetisation =&lt;br /&gt;
==Modifying the Files==&lt;br /&gt;
&lt;br /&gt;
===Energy and Magnetisation Functions===&lt;br /&gt;
&lt;br /&gt;
====Energy===&lt;br /&gt;
[[File:First_Ene_Method.PNG]]&lt;br /&gt;
&lt;br /&gt;
The above energy method segments a given lattice into lattice cells on the edges, corners or in the bulk of the lattice and calculates the energy interactions with its neighbours as appropriate.&lt;br /&gt;
&lt;br /&gt;
====Magnetisation====&lt;br /&gt;
[[File:First_Mag_Method.PNG]]&lt;br /&gt;
&lt;br /&gt;
The magnetisation method loops over all elements in the array representing the Ising lattice and adds the value of the spin to the magnetisation variable.&lt;br /&gt;
&lt;br /&gt;
==Testing the Files==&lt;br /&gt;
&lt;br /&gt;
===ILCheck.py===&lt;br /&gt;
&lt;br /&gt;
[[File:ILChecks.PNG]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Above, the results of the ILcheck.py script are presented.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= Introduction to the Monte Carlo Simulation =&lt;br /&gt;
==Average Energy and Magnetisation==&lt;br /&gt;
===Configurations of a 100 Spin System===&lt;br /&gt;
For a system of two spins, 4 configurations are possible (↑↑, ↓↓, ↑↓, ↓↑) i.e. &amp;lt;math&amp;gt;2^{2}&amp;lt;/math&amp;gt;. For a system of 100 spins, there are &amp;lt;math&amp;gt;2^{100}&amp;lt;/math&amp;gt; configurations. In the first example, the ↑↑ and ↓↓ are degenerate, as are the ↑↓ and ↓↑ configurations. Therefore, dividing the number of possible configurations by the multiplicity of each configuration (&amp;lt;math&amp;gt;2&amp;lt;/math&amp;gt;) gives the number of non-degenerate configurations. As previously stated, degenerate configurations are indistinguishable in the absence of an external magnetic field.&lt;br /&gt;
&lt;br /&gt;
For 100 spins, this gives &amp;lt;math&amp;gt;\displaystyle\frac{2^{100}}{2} = 6.338 \times 10^{29} &amp;lt;/math&amp;gt; distinguishable configurations.&lt;br /&gt;
&lt;br /&gt;
If processing speed permits &amp;lt;math&amp;gt; 1 \times 10^{9}&amp;lt;/math&amp;gt; calculations each second, the evaluation of a single value of &amp;lt;math&amp;gt;\left\langle M\right\rangle_T&amp;lt;/math&amp;gt; would last &amp;lt;math&amp;gt; 6.338 \times 10^{20} &amp;lt;/math&amp;gt; seconds or &amp;lt;math&amp;gt; 1458 &amp;lt;/math&amp;gt; times the age of the Universe!&lt;br /&gt;
&lt;br /&gt;
==Modifying IsingLattice.py==&lt;br /&gt;
&lt;br /&gt;
===Monte Carlo and Statistics Methods===&lt;br /&gt;
[[File:Monte_Carlo.PNG]]&lt;br /&gt;
&lt;br /&gt;
[[File:stats.PNG]]&lt;br /&gt;
&lt;br /&gt;
The Metropolis Monte Carlo (MMC) algorithm provides a computationally inexpensive path from random initial states to the minimum free energy states of the Ising lattices generated. First, a random 2D Ising lattice is generated. A single random spin within this lattice is &amp;quot;flipped&amp;quot; and the resulting (internal) energy change between these states is measured. Recalling the relationship between the Hemholtz free energy, internal energy and entropy, it follows that a decrease in internal energy also lowers the free energy of the system: thus the configuration change is accepted.&lt;br /&gt;
&lt;br /&gt;
In the case that the spin &amp;quot;flip&amp;quot; does not lower the internal energy, the MMC algorithm tests this configuration change against the Boltzman factor. In the canonical (NVT) ensemble, the free energy of the system is given by:&lt;br /&gt;
&lt;br /&gt;
:&amp;lt;math&amp;gt;A = -k_{B}T\,lnZ_{NVT} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
where Z is the canonical partition function which depends upon &amp;lt;math&amp;gt; e^{-\frac{\Delta E}{k_BT}} &amp;lt;/math&amp;gt;, the Boltzman factor. By choosing a random value in the interval [0,1)from a continuous uniformm probability distribution and rejecting any value of the Boltzman factor less than this value, the MMC algorithm allows for configuration changes with small, positive internal energy changes if they conform to the Boltzman probability distribution. Alternatively, the MMC allows small perturbations to the internal energy which prevents the system from settling in a metastable internal energy minimum and instead, ensures that the system equilibrates around the &#039;&#039;true&#039;&#039; free energy minimum.&lt;br /&gt;
&lt;br /&gt;
===Spontaneous Magnetisation===&lt;br /&gt;
&lt;br /&gt;
Below the Curie Temperature, &amp;lt;math&amp;gt; T_{C} &amp;lt;/math&amp;gt;, the energetic driving force dominates the entropic driving force, resulting in a highly ordered system and an overall magnetisation. The spins of the system align in order to maximise favourable coupling interactions rather than adopting a less ordered configuration of higher multiplicity. Therefore, when &amp;lt;math&amp;gt;T &amp;lt; T_C&amp;lt;/math&amp;gt;, the most probable configurations have an overall magnetisation resulting in &amp;lt;math&amp;gt;\left\langle M\right\rangle \neq 0&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
The plots of magnetisation per spin and energy per spin obtained from ILanim.py support this prediction. Below, the plots show that upon equilibration, the system adopts the minimum energy per spin: &amp;lt;math&amp;gt;E_{min_{spin}} = \frac{-NDJ}{N} = -DJ = -2&amp;lt;/math&amp;gt; and exhibits the maximum magnitude of magnetisation per spin: &amp;lt;math&amp;gt;|M_{spin}| = 1&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:2T=1.0.png]]&lt;br /&gt;
[[File:T=1.0.png]]&lt;br /&gt;
[[File:3T=1.0.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
An unknown system error prevented the statistics() function from printing the average values.&lt;br /&gt;
&lt;br /&gt;
=Accelerating the Code=&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Initial Method Speeds===&lt;br /&gt;
Taking 10 repeat measurements for the time taken to perform 2000 Monte Carlo steps resulted in&lt;br /&gt;
&lt;br /&gt;
* An average time of  &amp;lt;math&amp;gt;11.7s&amp;lt;/math&amp;gt; &lt;br /&gt;
* A standard error of &amp;lt;math&amp;gt;0.020s&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Updating Measurement===&lt;br /&gt;
&lt;br /&gt;
NOTE: ILtimetrial.py has been modified to:&lt;br /&gt;
* Perform a requested number of &#039;2000 Monte Carlo Step&#039; measurements&lt;br /&gt;
* Record these measurements in a CSV file&lt;br /&gt;
* Return the mean measuremd time and the Standard Error i.e.   &amp;lt;math&amp;gt; \frac{\sigma}{n} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:TimeTrialMethod.PNG]]&lt;br /&gt;
&lt;br /&gt;
===Updating Energy and Magnetisation Methods===&lt;br /&gt;
[[File:New_Mag_Method.PNG]]&lt;br /&gt;
[[File:New_Ene_Method.PNG]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Updated Method Speeds===&lt;br /&gt;
[[File:TimeTrial.PNG]]&lt;br /&gt;
&lt;br /&gt;
Taking 30 measurements of the time taken to perform 2000 Monte Carlo Steps resulted in:&lt;br /&gt;
&lt;br /&gt;
* An average time of &amp;lt;math&amp;gt;\displaystyle{0.87s}&amp;lt;/math&amp;gt;&lt;br /&gt;
* A standard error of &amp;lt;math&amp;gt;2.5 \times 10^{-3}s&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This represents a 93% decrease in the average computation time from the initial methods.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=The Effect of Temperature=&lt;br /&gt;
&lt;br /&gt;
==Correcting the Averaging  Code==&lt;br /&gt;
&lt;br /&gt;
===Finding a Delay Value===&lt;br /&gt;
To quickly find a value for &amp;lt;math&amp;gt; N_{d}&amp;lt;/math&amp;gt;, the minimum number of cycles typically needed for the equilibration of a system of within the lattice and temperature ranges of interest, it was assumed that:&lt;br /&gt;
&lt;br /&gt;
* Larger lattices would require more Monte Carlo steps to reach equilibrium from their initial, random configurations&lt;br /&gt;
&lt;br /&gt;
* Lattices at lower temperatures would require more Monte Carlo steps to reach equilibrium from their initial, random configurations.&lt;br /&gt;
&lt;br /&gt;
Therefore, an initial value for &amp;lt;math&amp;gt; N_{d}&amp;lt;/math&amp;gt; was found for a &amp;lt;math&amp;gt; 128\times128 &amp;lt;/math&amp;gt; lattice at a temperature of &amp;lt;math&amp;gt;0.5&amp;lt;/math&amp;gt; reduced temperature units.&lt;br /&gt;
*&amp;lt;math&amp;gt; N_{d} = 185000 &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
By this number of steps, all smaller lattices at all higher temperatures were found to have equilibrated also. Thus, this value of&amp;lt;math&amp;gt; N_{d}&amp;lt;/math&amp;gt; was accepted as an appropriate delay.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:AFinFrame 128 3e5 T= 0.5line.png|400px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
For the 128x128 lattices at T=0.5, equilibration was ensured from 185000 steps onwards.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Smaller lattices at the same temperature did indeed equilibrate more slowly, but all equilibrated within &amp;lt;math&amp;gt; N_{d}&amp;lt;/math&amp;gt; MC steps.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:AFinFrame 64 3e5 T= 0.5line.png|400px]]&lt;br /&gt;
[[File:AFinFrame 32 3e5 T= 0.5line2.png|400px]]&lt;br /&gt;
[[File:AFinFrame 16 3e5 T= 0.5line2.png|400px]]&lt;br /&gt;
[[File:AFinFrame 8 3e5 T= 0.5line.png|400px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The figure below shows the modifications made to IsingLattice.py to incorporate the &amp;lt;math&amp;gt; N_{d} &amp;lt;/math&amp;gt; step delay.&lt;br /&gt;
&lt;br /&gt;
==Running over a Range of Temperatures==&lt;br /&gt;
&lt;br /&gt;
To examine the effect of temperature on the average energy &amp;lt;math&amp;gt; \left\langle E\right\rangle &amp;lt;/math&amp;gt; and average magnetisation &amp;lt;math&amp;gt; \left\langle M\right\rangle &amp;lt;/math&amp;gt; of Ising lattices at equilibrium, the following parameters were used:&lt;br /&gt;
&lt;br /&gt;
* Temperature Range: &amp;lt;math&amp;gt;  0.5 - 5 &amp;lt;/math&amp;gt; reduced units&lt;br /&gt;
* Temperature Interval: &amp;lt;math&amp;gt;0.01&amp;lt;/math&amp;gt; reduced units (&amp;lt;math&amp;gt;450&amp;lt;/math&amp;gt; temperature values)&lt;br /&gt;
* Number of MMC Steps per Temperature value: &amp;lt;math&amp;gt; 2 \times 10^5 &amp;lt;/math&amp;gt; with the aforementioned value of &amp;lt;math&amp;gt; N_{d} = 1.85 \times 10^5 &amp;lt;/math&amp;gt; Monte Carlo steps&lt;br /&gt;
* Lattice Sizes:  &amp;lt;math&amp;gt; 2 \times 2 &amp;lt;/math&amp;gt;, &amp;lt;math&amp;gt; 4 \times 4 &amp;lt;/math&amp;gt; , &amp;lt;math&amp;gt; 8 \times 8 &amp;lt;/math&amp;gt; , &amp;lt;math&amp;gt; 16 \times 16 &amp;lt;/math&amp;gt; , &amp;lt;math&amp;gt; 32 \times 32 &amp;lt;/math&amp;gt; , &amp;lt;math&amp;gt; 64 \times 64 &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Plots of  &amp;lt;math&amp;gt; \left\langle E\right\rangle &amp;lt;/math&amp;gt; and  &amp;lt;math&amp;gt; \left\langle M\right\rangle &amp;lt;/math&amp;gt; per spin as versus temperature are presented below for each lattice size. Errorbars have been implemented to demonstrate how &#039;&#039;well-behaved&#039;&#039; lattice systems of each size are at each temperature, that is, how temperature and lattice size affect the size of the variations in the expected values. For the error calculations, the standard errors, &amp;lt;math&amp;gt; \sigma_\bar{X} &amp;lt;/math&amp;gt;,  in &amp;lt;math&amp;gt; \left\langle E\right\rangle &amp;lt;/math&amp;gt; and  &amp;lt;math&amp;gt; \left\langle M\right\rangle &amp;lt;/math&amp;gt; per spin have been used:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====8x8====&lt;br /&gt;
&lt;br /&gt;
[[File:8x8e+error.png]] [[File:8x8m+error.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
A Python script has been written to generate a plot of &amp;lt;math&amp;gt;\left\langle E\right\rangle&amp;lt;/math&amp;gt; or &amp;lt;math&amp;gt;\left\langle M\right\rangle&amp;lt;/math&amp;gt; against temperature based upon user input. A screenshot of this code has been inserted below.&lt;br /&gt;
&lt;br /&gt;
[[File:ExpectedvsTemp.PNG|200px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=The Effect of System Size=&lt;br /&gt;
&lt;br /&gt;
==Scaling the System Size==&lt;br /&gt;
&lt;br /&gt;
===More Lattice Sizes===&lt;br /&gt;
&lt;br /&gt;
====2x2====&lt;br /&gt;
[[File:2x2e+error.png]] [[File:2x2m+error.png]]&lt;br /&gt;
&lt;br /&gt;
====4x4====&lt;br /&gt;
[[File:4x4e+error.png]] [[File:4x4m+error.png]]&lt;br /&gt;
&lt;br /&gt;
====16x16====&lt;br /&gt;
[[File:16x16e+error.png]] [[File:16x16m+error.png]]&lt;br /&gt;
&lt;br /&gt;
====32x32====&lt;br /&gt;
[[File:32x32e+error.png]] [[File:32x32m+error.png]]&lt;br /&gt;
&lt;br /&gt;
====64x64====&lt;br /&gt;
[[File:64x64e+error.png]] [[File:64x64m+error.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Scrutiny of the plots of average energy per spin for each lattice size reveals an increase in the errorbar width with increasing lattice size. This is most notable in the low temperature region of the plots. Between the &amp;lt;math&amp;gt; 8\times8 &amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt; 16\times16 &amp;lt;/math&amp;gt; lattices, the long range fluctuations become suddenly prominent. The &amp;lt;math&amp;gt;16\times16&amp;lt;/math&amp;gt; lattice is the first (in the range of sizes tested)to clearly capture these fluctuations.&lt;br /&gt;
&lt;br /&gt;
=Determining the Heat Capacity=&lt;br /&gt;
&lt;br /&gt;
==Calculating the Heat Capacity==&lt;br /&gt;
&lt;br /&gt;
===Heat Capacity Derivation===&lt;br /&gt;
Working in the canonical ensemble (constant volume), the heat capacity &amp;lt;math&amp;gt; C_V &amp;lt;/math&amp;gt; is given by:&lt;br /&gt;
&lt;br /&gt;
:&amp;lt;math&amp;gt;C_V = \frac{\partial \left\langle E\right\rangle}{\partial T}_V&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
where &amp;lt;math&amp;gt;\left\langle E\right\rangle&amp;lt;/math&amp;gt; is the average total energy or expected value of the internal energy of the system.&lt;br /&gt;
&lt;br /&gt;
: &amp;lt;math&amp;gt; \left\langle E\right\rangle = - \frac{\partial ln Q}{\partial \beta} = -\frac{1}{Q}\frac{\partial Q}{\partial \beta} &amp;lt;/math&amp;gt;&lt;br /&gt;
where &amp;lt;math&amp;gt; Q&amp;lt;/math&amp;gt; is the partition function for the system of N interacting spins.&lt;br /&gt;
&lt;br /&gt;
By evaluating the second form of the partial derivative with respect to &amp;lt;math&amp;gt; \beta&amp;lt;/math&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \left\langle E\right\rangle = -\frac{1}{Q}\frac{\partial Q}{\partial \beta} = \frac{\Sigma \epsilon_{i} e^{-\beta \epsilon_{i}}}{\Sigma e^{-\beta \epsilon_{i}}} &amp;lt;/math&amp;gt; &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Applying the product rule enables the differentiation of this expression for &amp;lt;math&amp;gt;\left\langle E\right\rangle&amp;lt;/math&amp;gt; with respect to temperature, giving:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\frac{\partial \left\langle E\right\rangle}{\partial T} = \frac{\Sigma \epsilon_{i} \frac{\epsilon_i}{k_BT^2}e^{-\beta \epsilon_{i}}}{\Sigma e^{-\beta \epsilon_{i}}} - \frac{\Sigma \epsilon_i e^{-\beta \epsilon_i}\cdot \frac{\epsilon_i}{k_BT^2}e^{-\beta \epsilon_i}}{(\Sigma e^{-\beta \epsilon_{i}})^2}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\frac{\partial \left\langle E\right\rangle}{\partial T}  = \frac{1}{k_BT^2}\left[\frac{\Sigma \epsilon_i^2 e^{-\beta \epsilon_i}}{\Sigma e^{-\beta \epsilon_i}} - \left(\frac{\Sigma \epsilon_{i} e^{-\beta \epsilon_{i}}}{\Sigma e^{-\beta \epsilon_{i}}}\right)^2\right] &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\frac{\partial \left\langle E\right\rangle}{\partial T}  = \frac{1}{k_BT^2}\left[\left\langle E^2\right\rangle - \left\langle E\right\rangle^2 \right] &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Thus,&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\frac{\partial \left\langle E\right\rangle}{\partial T} = \frac{Var[E]}{k_BT^2} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Heat Capacity versus Temperature===&lt;br /&gt;
Below, a screenshot of the Python script written to produce plots of &amp;lt;math&amp;gt; C_V &amp;lt;/math&amp;gt; against &amp;lt;math&amp;gt; T &amp;lt;/math&amp;gt;, together with the output images of this script.&lt;br /&gt;
 &lt;br /&gt;
[[File:HeatCapScript.PNG]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====2x2====&lt;br /&gt;
[[File:HC2.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====4x4====&lt;br /&gt;
[[File:HC4.png]]&lt;br /&gt;
&lt;br /&gt;
====8x8====&lt;br /&gt;
[[File:HC8.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====16x16====&lt;br /&gt;
[[File:HC16.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====32x32====&lt;br /&gt;
[[File:HC32.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= Locating the Curie Temperature =&lt;br /&gt;
&lt;br /&gt;
===C++ Data Comparison===&lt;br /&gt;
Below a comparison of the &amp;lt;math&amp;gt; C_V &amp;lt;/math&amp;gt; against &amp;lt;math&amp;gt; T &amp;lt;/math&amp;gt; plot generated for the &amp;lt;math&amp;gt; 2 /times 2&amp;lt;/math&amp;gt; to the corresponding C++ data is offered.&lt;br /&gt;
 &lt;br /&gt;
[[File:CHC2.png]]&lt;br /&gt;
&lt;br /&gt;
The data generated by the ILtemperaturerange.py script is a faithful match to the C++ data. However, this is an exceptional case; the plots for all other lattice sizes were found to be very dissimilar, necessitating polynomial fitting.&lt;br /&gt;
&lt;br /&gt;
==Polyfitting of C++ Data==&lt;br /&gt;
&lt;br /&gt;
===Fitting a Polynomial to the Entire Range===&lt;br /&gt;
The following Python script was written to perform a polynomial fit to the entire range of the graph of &amp;lt;math&amp;gt; C_V &amp;lt;/math&amp;gt; against &amp;lt;math&amp;gt; T &amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:HeatCapPoly.PNG]]&lt;br /&gt;
&lt;br /&gt;
Below, the result of the polyfit to the &amp;lt;math&amp;gt; 2/times2&amp;lt;/math&amp;gt; lattice data is offered (for comparison to the previous, non-fitted example).&lt;br /&gt;
&lt;br /&gt;
[[File:15Polyc2x2.png]]&lt;br /&gt;
&lt;br /&gt;
Polynomials with 5 terms and above were found to match the data in the vicinity of the critical region considerably well. Below 7 terms, the &#039;&#039;tails&#039;&#039; of the plot were matched poorly. In the above example, a polynomial of 15 terms was fit to the data.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Fitting a Polynomial to the Critical Region===&lt;br /&gt;
&lt;br /&gt;
The following Python script was written to perform a polynomial fit to the region of interest (the &#039;&#039;critical&#039;&#039; region) of the plots of &amp;lt;math&amp;gt; C_V &amp;lt;/math&amp;gt; against &amp;lt;math&amp;gt; T &amp;lt;/math&amp;gt; to facilitate the discovery of &amp;lt;math&amp;gt; T_C &amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
[[File:CapPolyCrit.PNG]]&lt;br /&gt;
&lt;br /&gt;
An example of the result returned by the script is offered below for the C++ data for the &amp;lt;math&amp;gt; 16\times16&amp;lt;/math&amp;gt; lattice.&lt;br /&gt;
&lt;br /&gt;
[[File:HHCPC16,2.6-2.1,5.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Finding the Peak C Values for Each Lattice Size===&lt;br /&gt;
Below, a screenshot of the code used to obtain the temperatures at which the maximum values of C occured is presented for each lattice size. The temperatures themselves are also featured on the image.&lt;br /&gt;
&lt;br /&gt;
[[File:Tmaxes.PNG]]&lt;br /&gt;
&lt;br /&gt;
The range of lattice sizes and their associated &amp;lt;math&amp;gt;T_{C} &amp;lt;/math&amp;gt; values were exported to a [[Media:Tmax.txt|text file]], enabling a plot to be created.&lt;br /&gt;
&lt;br /&gt;
[[File:CritTempPlot2.png]]&lt;br /&gt;
&lt;br /&gt;
Subsequently, the scipy.optimize.curve_fit function was used to fit &amp;lt;math&amp;gt;T_{C, L} = \frac{A}{L} + T_{C,\infty}&amp;lt;/math&amp;gt; function to the data obtained. This enabled the estimation the constant &amp;lt;math&amp;gt; A &amp;lt;/math&amp;gt; and the value of &amp;lt;math&amp;gt;T_{C} &amp;lt;/math&amp;gt; at &amp;lt;math&amp;gt; \frac{A}{L} = 0&amp;lt;/math&amp;gt;, otherwise &amp;lt;math&amp;gt; T_{C,\infty}&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
[[File:FindingTc.PNG]]&lt;br /&gt;
&lt;br /&gt;
A value of &amp;lt;math&amp;gt; T_{C,\infty} = 2.2799 &amp;lt;/math&amp;gt; was obtained. A comparison to the literature[https://en.wikipedia.org/wiki/Square-lattice_Ising_model#Critical_temperature] value of &amp;lt;math&amp;gt;2.269&amp;lt;/math&amp;gt; reveals a percentage error value of only &amp;lt;math&amp;gt; 0.47% &amp;lt;/math&amp;gt;. Surprisingly, the investigation of lattices in the given size range was enough to capture the theoretical behaviour of an infinite lattice. As explained by Frenkel and Smit, the implementation of periodic boundary conditions enables the simulation of an infinite bulk (or infinite adjacent lattices) surrounding the single lattice under scrutiny. The agreement of the experimental and theoretical values for &amp;lt;math&amp;gt; T_{C,\infty} &amp;lt;/math&amp;gt; prove the effectiveness of this idea.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
A likely source of error arises from the polynomial fitting of the data. The peaks in &amp;lt;math&amp;gt; C_V &amp;lt;/math&amp;gt; against &amp;lt;math&amp;gt; T &amp;lt;/math&amp;gt; were far more sharp than the broad peaks of the polynomial functions used to fit them. In several cases, the polynomial peak was a slight, yet discernible overestimate of the true peak. This has resulted in an overestimation of the final &amp;lt;math&amp;gt; T_{C,\infty} &amp;lt;/math&amp;gt; value. Fitting a function with a sharper peak to the critical region could overcome this overestimation and provide a more faithful final value.&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
* Frenkel, Daan, et al. Understanding Molecular Simulation : From Algorithms to Applications, Elsevier Science &amp;amp; Technology, 2001&lt;br /&gt;
&lt;br /&gt;
* Krieger, M. Constitutions of matter : Mathematically modeling the most everyday of physical phenomena. Chicago ; London: University of Chicago Press, 1996&lt;br /&gt;
&lt;br /&gt;
* https://en.wikipedia.org/wiki/Square-lattice_Ising_model Accessed 13-11-18&lt;/div&gt;</summary>
		<author><name>Jj1516</name></author>
	</entry>
	<entry>
		<id>https://chemwiki.ch.ic.ac.uk/index.php?title=Rep:JJ1516Ising&amp;diff=736977</id>
		<title>Rep:JJ1516Ising</title>
		<link rel="alternate" type="text/html" href="https://chemwiki.ch.ic.ac.uk/index.php?title=Rep:JJ1516Ising&amp;diff=736977"/>
		<updated>2018-11-21T09:58:29Z</updated>

		<summary type="html">&lt;p&gt;Jj1516: /* Finding the Peak C Values for Each Lattice Size */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Ex Script Link:&lt;br /&gt;
https://wiki.ch.ic.ac.uk/wiki/index.php?title=Third_year_CMP_compulsory_experiment&lt;br /&gt;
&lt;br /&gt;
= Introduction to the Ising Model =&lt;br /&gt;
&lt;br /&gt;
== The Model ==&lt;br /&gt;
&lt;br /&gt;
=== Minimum Energy State ===&lt;br /&gt;
====Minimum Interaction Energy====&lt;br /&gt;
The interaction energy of an Ising lattice is given by:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;E = -\frac{1}{2}J\displaystyle\sum_{i}^{N} \displaystyle\sum_{j\;\in\;{neighbours}\;(i)} \!\!\!\!\!\!\!\!\!\!\!\!s_{i}s_{j}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In an Ising lattice with D dimensions and periodic boundary conditions, a given spin &amp;lt;math&amp;gt; s_i&amp;lt;/math&amp;gt; has 2D neighbours.&lt;br /&gt;
&lt;br /&gt;
The minimum interaction energy is achieved when all spins in the lattice are aligned (all ↑ or all ↓). As  such, any spin &amp;lt;math&amp;gt; s_i&amp;lt;/math&amp;gt; must be aligned with all 2D of its neighbours. That is, &amp;lt;math&amp;gt;s_{i}s_{j} = 1&amp;lt;/math&amp;gt; for all &amp;lt;math&amp;gt;j&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Therefore, for any &amp;lt;math&amp;gt; s_i&amp;lt;/math&amp;gt;, the sum of its interactions is &amp;lt;math&amp;gt;\displaystyle\sum_{j\;\in\;{neighbours}\;(i)} \!\!\!\!\!\!\!\!\!\!\!\!s_{i}s_{j} = 2D &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
As this is true for all N spins in the lattice, it follows that &amp;lt;math&amp;gt;\displaystyle\sum_{i}^{N} 2D = 2DN&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Thus the minimum interaction energy is given by:&lt;br /&gt;
&lt;br /&gt;
:&amp;lt;math&amp;gt;E_{min} = -\frac{1}{2}J\cdot2DN = - DNJ &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Entropy of the Minimum Energy State====&lt;br /&gt;
&lt;br /&gt;
The entropy of a state is given by:&lt;br /&gt;
&lt;br /&gt;
:&amp;lt;math&amp;gt;S = k\; ln\; \Omega &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Where &amp;lt;math&amp;gt; \Omega &amp;lt;/math&amp;gt; is the multiplicity of the state, the number of degenerate configurations of said state. The minimum energy state is achievable with all spins ↑ or with all spins ↓. In the absence of an external magnetic field, these configurations are degenerate and indistinguishable giving &amp;lt;math&amp;gt; \Omega = 2 &amp;lt;/math&amp;gt; for this state. Therefore,&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; S_{E_{min}}  = k_{B}\; ln\; 2 = 0.693k_{B} = 9.57 \times 10^{-24} J\!\cdot\!\! K^{-1}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Phase Transitions ==&lt;br /&gt;
&lt;br /&gt;
=== Changes to Minimum Energy Configuration ===&lt;br /&gt;
&lt;br /&gt;
====Energy Change ====&lt;br /&gt;
The energy change &amp;lt;math&amp;gt; \Delta E&amp;lt;/math&amp;gt; associated with a single spin &#039;flip&#039; from the lowest energy onfiguration may be calculated by considering the change in the interaction energy with the spin&#039;s neighbours.&lt;br /&gt;
&lt;br /&gt;
Let &amp;lt;math&amp;gt; D = 3, N = 1000 &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\Delta{E} = E_1 - E_0&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;E_1&amp;lt;/math&amp;gt; Interaction energy after one spin has been &#039;flipped&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;E_0&amp;lt;/math&amp;gt; Lowest energy configuration&lt;br /&gt;
&lt;br /&gt;
[[Image:Task 2 table.PNG]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\displaystyle\sum_{interactions} = -2D + 2D(2D-2) + 2D[N-(2D+1)] &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; = 2DN - 8D &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;E_1 = \displaystyle-\frac{1}{2}J\;\sum_{interactions} = 4DJ - DNJ&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\Delta{E} = E_1 - E_0 = 4DJ - DNJ + DNJ = +4DJ = +12J&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This energy change is independent of &amp;lt;math&amp;gt; N&amp;lt;/math&amp;gt; and depends only on the dimension size and the coupling constant &amp;lt;math&amp;gt; J &amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
In this calculation, the following assumption has been made.&lt;br /&gt;
&lt;br /&gt;
* The lattice dimensions are infinite relative to the size of each cell&lt;br /&gt;
&lt;br /&gt;
This allows &#039;&#039;&#039;any&#039;&#039;&#039; cell to be treated as the centre of the lattice. As every cell interacts with 2D neighbours, flipping any cell in the minimum energy configuration results in the same energy change. Alternatively, the periodic boundary conditions of the Ising model remove the necessity for such an assumption. As a consequence, the absence of &amp;lt;math&amp;gt; N &amp;lt;/math&amp;gt; from the resulting energy change is justified.&lt;br /&gt;
&lt;br /&gt;
====Entropy Change====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; S = k_{B}\; ln\; \Omega &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\Omega = \displaystyle\frac{N!}{{N_{\uparrow}!}{N_{\downarrow}!}}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Where &amp;lt;math&amp;gt;N_{x}!&amp;lt;/math&amp;gt; denotes the factorial of the number of spins in spin state &amp;lt;math&amp;gt;x&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\Delta{S} = k_{B}\;ln\;\left(\displaystyle\frac{\Omega_{2}}{\Omega_{1}}\right)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\Omega_{2} = \frac{1000!}{999!1!} = 1000&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \Omega_{1} = \frac{1000!}{1000!} = 1&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\Delta{S} = k_{B}\;ln\;1000 = 9.54 \times 10^{-23} JK^{-1}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\Delta{S_{mol}} = N_{A}k_{B}\;ln\;1000 = 57.4 \,JK^{-1}mol^{-1}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Magnetisation Values of 1D and 2D Lattices===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;M = \sum_i s_i&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====1D Lattice Magnetisation====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;M_{1D} =\;\;+1&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====2D Lattice Magnetisation====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;M_{2D} =\;\;+1&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Magnetisation at 0K====&lt;br /&gt;
&lt;br /&gt;
At 0K, no thermal energy is available to overcome the energetic barriers to spin flipping. Considering the Hemholtz free energy:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; A = E - TS &amp;lt;/math&amp;gt; &lt;br /&gt;
&lt;br /&gt;
A temperature of 0K nullifies the entropic contribution to the free energy. Thus the energetic driving force (which maximises parallel spin interactions) dominates the entropic driving force (which maximises multiplicity of lattice states). For an Ising Lattice with D =  3, N = 1000 at 0K, the alignment of all spins results in the minimum energy configuration  and an overall magnetisation of &amp;lt;math&amp;gt; M = \pm 1000 &amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
= Calculating the Energy and Magnetisation =&lt;br /&gt;
==Modifying the Files==&lt;br /&gt;
&lt;br /&gt;
===Energy and Magnetisation Functions===&lt;br /&gt;
&lt;br /&gt;
====Energy===&lt;br /&gt;
[[File:First_Ene_Method.PNG]]&lt;br /&gt;
&lt;br /&gt;
The above energy method segments a given lattice into lattice cells on the edges, corners or in the bulk of the lattice and calculates the energy interactions with its neighbours as appropriate.&lt;br /&gt;
&lt;br /&gt;
====Magnetisation====&lt;br /&gt;
[[File:First_Mag_Method.PNG]]&lt;br /&gt;
&lt;br /&gt;
The magnetisation method loops over all elements in the array representing the Ising lattice and adds the value of the spin to the magnetisation variable.&lt;br /&gt;
&lt;br /&gt;
==Testing the Files==&lt;br /&gt;
&lt;br /&gt;
===ILCheck.py===&lt;br /&gt;
&lt;br /&gt;
[[File:ILChecks.PNG]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Above, the results of the ILcheck.py script are presented.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= Introduction to the Monte Carlo Simulation =&lt;br /&gt;
==Average Energy and Magnetisation==&lt;br /&gt;
===Configurations of a 100 Spin System===&lt;br /&gt;
For a system of two spins, 4 configurations are possible (↑↑, ↓↓, ↑↓, ↓↑) i.e. &amp;lt;math&amp;gt;2^{2}&amp;lt;/math&amp;gt;. For a system of 100 spins, there are &amp;lt;math&amp;gt;2^{100}&amp;lt;/math&amp;gt; configurations. In the first example, the ↑↑ and ↓↓ are degenerate, as are the ↑↓ and ↓↑ configurations. Therefore, dividing the number of possible configurations by the multiplicity of each configuration (&amp;lt;math&amp;gt;2&amp;lt;/math&amp;gt;) gives the number of non-degenerate configurations. As previously stated, degenerate configurations are indistinguishable in the absence of an external magnetic field.&lt;br /&gt;
&lt;br /&gt;
For 100 spins, this gives &amp;lt;math&amp;gt;\displaystyle\frac{2^{100}}{2} = 6.338 \times 10^{29} &amp;lt;/math&amp;gt; distinguishable configurations.&lt;br /&gt;
&lt;br /&gt;
If processing speed permits &amp;lt;math&amp;gt; 1 \times 10^{9}&amp;lt;/math&amp;gt; calculations each second, the evaluation of a single value of &amp;lt;math&amp;gt;\left\langle M\right\rangle_T&amp;lt;/math&amp;gt; would last &amp;lt;math&amp;gt; 6.338 \times 10^{20} &amp;lt;/math&amp;gt; seconds or &amp;lt;math&amp;gt; 1458 &amp;lt;/math&amp;gt; times the age of the Universe!&lt;br /&gt;
&lt;br /&gt;
==Modifying IsingLattice.py==&lt;br /&gt;
&lt;br /&gt;
===Monte Carlo and Statistics Methods===&lt;br /&gt;
[[File:Monte_Carlo.PNG]]&lt;br /&gt;
&lt;br /&gt;
[[File:stats.PNG]]&lt;br /&gt;
&lt;br /&gt;
The Metropolis Monte Carlo (MMC) algorithm provides a computationally inexpensive path from random initial states to the minimum free energy states of the Ising lattices generated. First, a random 2D Ising lattice is generated. A single random spin within this lattice is &amp;quot;flipped&amp;quot; and the resulting (internal) energy change between these states is measured. Recalling the relationship between the Hemholtz free energy, internal energy and entropy, it follows that a decrease in internal energy also lowers the free energy of the system: thus the configuration change is accepted.&lt;br /&gt;
&lt;br /&gt;
In the case that the spin &amp;quot;flip&amp;quot; does not lower the internal energy, the MMC algorithm tests this configuration change against the Boltzman factor. In the canonical (NVT) ensemble, the free energy of the system is given by:&lt;br /&gt;
&lt;br /&gt;
:&amp;lt;math&amp;gt;A = -k_{B}T\,lnZ_{NVT} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
where Z is the canonical partition function which depends upon &amp;lt;math&amp;gt; e^{-\frac{\Delta E}{k_BT}} &amp;lt;/math&amp;gt;, the Boltzman factor. By choosing a random value in the interval [0,1)from a continuous uniformm probability distribution and rejecting any value of the Boltzman factor less than this value, ###&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Spontaneous Magnetisation===&lt;br /&gt;
&lt;br /&gt;
Below the Curie Temperature, &amp;lt;math&amp;gt; T_{C} &amp;lt;/math&amp;gt;, the energetic driving force dominates the entropic driving force, resulting in a highly ordered system and an overall magnetisation. The spins of the system align in order to maximise favourable coupling interactions rather than adopting a less ordered configuration of higher multiplicity. Therefore, when &amp;lt;math&amp;gt;T &amp;lt; T_C&amp;lt;/math&amp;gt;, the most probable configurations have an overall magnetisation resulting in &amp;lt;math&amp;gt;\left\langle M\right\rangle \neq 0&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
The plots of magnetisation per spin and energy per spin obtained from ILanim.py support this prediction. Below, the plots show that upon equilibration, the system adopts the minimum energy per spin: &amp;lt;math&amp;gt;E_{min_{spin}} = \frac{-NDJ}{N} = -DJ = -2&amp;lt;/math&amp;gt; and exhibits the maximum magnitude of magnetisation per spin: &amp;lt;math&amp;gt;|M_{spin}| = 1&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:2T=1.0.png]]&lt;br /&gt;
[[File:T=1.0.png]]&lt;br /&gt;
[[File:3T=1.0.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
An unknown system error prevented the statistics() function from printing the average values.&lt;br /&gt;
&lt;br /&gt;
=Accelerating the Code=&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Initial Method Speeds===&lt;br /&gt;
Taking 10 repeat measurements for the time taken to perform 2000 Monte Carlo steps resulted in&lt;br /&gt;
&lt;br /&gt;
* An average time of  &amp;lt;math&amp;gt;11.7s&amp;lt;/math&amp;gt; &lt;br /&gt;
* A standard error of &amp;lt;math&amp;gt;0.020s&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Updating Measurement===&lt;br /&gt;
&lt;br /&gt;
NOTE: ILtimetrial.py has been modified to:&lt;br /&gt;
* Perform a requested number of &#039;2000 Monte Carlo Step&#039; measurements&lt;br /&gt;
* Record these measurements in a CSV file&lt;br /&gt;
* Return the mean measuremd time and the Standard Error i.e.   &amp;lt;math&amp;gt; \frac{\sigma}{n} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:TimeTrialMethod.PNG]]&lt;br /&gt;
&lt;br /&gt;
===Updating Energy and Magnetisation Methods===&lt;br /&gt;
[[File:New_Mag_Method.PNG]]&lt;br /&gt;
[[File:New_Ene_Method.PNG]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Updated Method Speeds===&lt;br /&gt;
[[File:TimeTrial.PNG]]&lt;br /&gt;
&lt;br /&gt;
Taking 30 measurements of the time taken to perform 2000 Monte Carlo Steps resulted in:&lt;br /&gt;
&lt;br /&gt;
* An average time of &amp;lt;math&amp;gt;\displaystyle{0.87s}&amp;lt;/math&amp;gt;&lt;br /&gt;
* A standard error of &amp;lt;math&amp;gt;2.5 \times 10^{-3}s&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This represents a 93% decrease in the average computation time from the initial methods.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=The Effect of Temperature=&lt;br /&gt;
&lt;br /&gt;
==Correcting the Averaging  Code==&lt;br /&gt;
&lt;br /&gt;
===Finding a Delay Value===&lt;br /&gt;
To quickly find a value for &amp;lt;math&amp;gt; N_{d}&amp;lt;/math&amp;gt;, the minimum number of cycles typically needed for the equilibration of a system of within the lattice and temperature ranges of interest, it was assumed that:&lt;br /&gt;
&lt;br /&gt;
* Larger lattices would require more Monte Carlo steps to reach equilibrium from their initial, random configurations&lt;br /&gt;
&lt;br /&gt;
* Lattices at lower temperatures would require more Monte Carlo steps to reach equilibrium from their initial, random configurations.&lt;br /&gt;
&lt;br /&gt;
Therefore, an initial value for &amp;lt;math&amp;gt; N_{d}&amp;lt;/math&amp;gt; was found for a &amp;lt;math&amp;gt; 128\times128 &amp;lt;/math&amp;gt; lattice at a temperature of &amp;lt;math&amp;gt;0.5&amp;lt;/math&amp;gt; reduced temperature units.&lt;br /&gt;
*&amp;lt;math&amp;gt; N_{d} = 185000 &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
By this number of steps, all smaller lattices at all higher temperatures were found to have equilibrated also. Thus, this value of&amp;lt;math&amp;gt; N_{d}&amp;lt;/math&amp;gt; was accepted as an appropriate delay.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:AFinFrame 128 3e5 T= 0.5line.png|400px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
For the 128x128 lattices at T=0.5, equilibration was ensured from 185000 steps onwards.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Smaller lattices at the same temperature did indeed equilibrate more slowly, but all equilibrated within &amp;lt;math&amp;gt; N_{d}&amp;lt;/math&amp;gt; MC steps.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:AFinFrame 64 3e5 T= 0.5line.png|400px]]&lt;br /&gt;
[[File:AFinFrame 32 3e5 T= 0.5line2.png|400px]]&lt;br /&gt;
[[File:AFinFrame 16 3e5 T= 0.5line2.png|400px]]&lt;br /&gt;
[[File:AFinFrame 8 3e5 T= 0.5line.png|400px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The figure below shows the modifications made to IsingLattice.py to incorporate the &amp;lt;math&amp;gt; N_{d} &amp;lt;/math&amp;gt; step delay.&lt;br /&gt;
&lt;br /&gt;
==Running over a Range of Temperatures==&lt;br /&gt;
&lt;br /&gt;
To examine the effect of temperature on the average energy &amp;lt;math&amp;gt; \left\langle E\right\rangle &amp;lt;/math&amp;gt; and average magnetisation &amp;lt;math&amp;gt; \left\langle M\right\rangle &amp;lt;/math&amp;gt; of Ising lattices at equilibrium, the following parameters were used:&lt;br /&gt;
&lt;br /&gt;
* Temperature Range: &amp;lt;math&amp;gt;  0.5 - 5 &amp;lt;/math&amp;gt; reduced units&lt;br /&gt;
* Temperature Interval: &amp;lt;math&amp;gt;0.01&amp;lt;/math&amp;gt; reduced units (&amp;lt;math&amp;gt;450&amp;lt;/math&amp;gt; temperature values)&lt;br /&gt;
* Number of MMC Steps per Temperature value: &amp;lt;math&amp;gt; 2 \times 10^5 &amp;lt;/math&amp;gt; with the aforementioned value of &amp;lt;math&amp;gt; N_{d} = 1.85 \times 10^5 &amp;lt;/math&amp;gt; Monte Carlo steps&lt;br /&gt;
* Lattice Sizes:  &amp;lt;math&amp;gt; 2 \times 2 &amp;lt;/math&amp;gt;, &amp;lt;math&amp;gt; 4 \times 4 &amp;lt;/math&amp;gt; , &amp;lt;math&amp;gt; 8 \times 8 &amp;lt;/math&amp;gt; , &amp;lt;math&amp;gt; 16 \times 16 &amp;lt;/math&amp;gt; , &amp;lt;math&amp;gt; 32 \times 32 &amp;lt;/math&amp;gt; , &amp;lt;math&amp;gt; 64 \times 64 &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Plots of  &amp;lt;math&amp;gt; \left\langle E\right\rangle &amp;lt;/math&amp;gt; and  &amp;lt;math&amp;gt; \left\langle M\right\rangle &amp;lt;/math&amp;gt; per spin as versus temperature are presented below for each lattice size. Errorbars have been implemented to demonstrate how &#039;&#039;well-behaved&#039;&#039; lattice systems of each size are at each temperature, that is, how temperature and lattice size affect the size of the variations in the expected values. For the error calculations, the standard errors, &amp;lt;math&amp;gt; \sigma_\bar{X} &amp;lt;/math&amp;gt;,  in &amp;lt;math&amp;gt; \left\langle E\right\rangle &amp;lt;/math&amp;gt; and  &amp;lt;math&amp;gt; \left\langle M\right\rangle &amp;lt;/math&amp;gt; per spin have been used:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====8x8====&lt;br /&gt;
&lt;br /&gt;
[[File:8x8e+error.png]] [[File:8x8m+error.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
A Python script has been written to generate a plot of &amp;lt;math&amp;gt;\left\langle E\right\rangle&amp;lt;/math&amp;gt; or &amp;lt;math&amp;gt;\left\langle M\right\rangle&amp;lt;/math&amp;gt; against temperature based upon user input. A screenshot of this code has been inserted below.&lt;br /&gt;
&lt;br /&gt;
[[File:ExpectedvsTemp.PNG|200px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=The Effect of System Size=&lt;br /&gt;
&lt;br /&gt;
==Scaling the System Size==&lt;br /&gt;
&lt;br /&gt;
===More Lattice Sizes===&lt;br /&gt;
&lt;br /&gt;
====2x2====&lt;br /&gt;
[[File:2x2e+error.png]] [[File:2x2m+error.png]]&lt;br /&gt;
&lt;br /&gt;
====4x4====&lt;br /&gt;
[[File:4x4e+error.png]] [[File:4x4m+error.png]]&lt;br /&gt;
&lt;br /&gt;
====16x16====&lt;br /&gt;
[[File:16x16e+error.png]] [[File:16x16m+error.png]]&lt;br /&gt;
&lt;br /&gt;
====32x32====&lt;br /&gt;
[[File:32x32e+error.png]] [[File:32x32m+error.png]]&lt;br /&gt;
&lt;br /&gt;
====64x64====&lt;br /&gt;
[[File:64x64e+error.png]] [[File:64x64m+error.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Scrutiny of the plots of average energy per spin for each lattice size reveals an increase in the errorbar width with increasing lattice size. This is most notable in the low temperature region of the plots. Between the &amp;lt;math&amp;gt; 8\times8 &amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt; 16\times16 &amp;lt;/math&amp;gt; lattices, the long range fluctuations become suddenly prominent. The &amp;lt;math&amp;gt;16\times16&amp;lt;/math&amp;gt; lattice is the first (in the range of sizes tested)to clearly capture these fluctuations.&lt;br /&gt;
&lt;br /&gt;
=Determining the Heat Capacity=&lt;br /&gt;
&lt;br /&gt;
==Calculating the Heat Capacity==&lt;br /&gt;
&lt;br /&gt;
===Heat Capacity Derivation===&lt;br /&gt;
Working in the canonical ensemble (constant volume), the heat capacity &amp;lt;math&amp;gt; C_V &amp;lt;/math&amp;gt; is given by:&lt;br /&gt;
&lt;br /&gt;
:&amp;lt;math&amp;gt;C_V = \frac{\partial \left\langle E\right\rangle}{\partial T}_V&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
where &amp;lt;math&amp;gt;\left\langle E\right\rangle&amp;lt;/math&amp;gt; is the average total energy or expected value of the internal energy of the system.&lt;br /&gt;
&lt;br /&gt;
: &amp;lt;math&amp;gt; \left\langle E\right\rangle = - \frac{\partial ln Q}{\partial \beta} = -\frac{1}{Q}\frac{\partial Q}{\partial \beta} &amp;lt;/math&amp;gt;&lt;br /&gt;
where &amp;lt;math&amp;gt; Q&amp;lt;/math&amp;gt; is the partition function for the system of N interacting spins.&lt;br /&gt;
&lt;br /&gt;
By evaluating the second form of the partial derivative with respect to &amp;lt;math&amp;gt; \beta&amp;lt;/math&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \left\langle E\right\rangle = -\frac{1}{Q}\frac{\partial Q}{\partial \beta} = \frac{\Sigma \epsilon_{i} e^{-\beta \epsilon_{i}}}{\Sigma e^{-\beta \epsilon_{i}}} &amp;lt;/math&amp;gt; &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Applying the product rule enables the differentiation of this expression for &amp;lt;math&amp;gt;\left\langle E\right\rangle&amp;lt;/math&amp;gt; with respect to temperature, giving:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\frac{\partial \left\langle E\right\rangle}{\partial T} = \frac{\Sigma \epsilon_{i} \frac{\epsilon_i}{k_BT^2}e^{-\beta \epsilon_{i}}}{\Sigma e^{-\beta \epsilon_{i}}} - \frac{\Sigma \epsilon_i e^{-\beta \epsilon_i}\cdot \frac{\epsilon_i}{k_BT^2}e^{-\beta \epsilon_i}}{(\Sigma e^{-\beta \epsilon_{i}})^2}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\frac{\partial \left\langle E\right\rangle}{\partial T}  = \frac{1}{k_BT^2}\left[\frac{\Sigma \epsilon_i^2 e^{-\beta \epsilon_i}}{\Sigma e^{-\beta \epsilon_i}} - \left(\frac{\Sigma \epsilon_{i} e^{-\beta \epsilon_{i}}}{\Sigma e^{-\beta \epsilon_{i}}}\right)^2\right] &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\frac{\partial \left\langle E\right\rangle}{\partial T}  = \frac{1}{k_BT^2}\left[\left\langle E^2\right\rangle - \left\langle E\right\rangle^2 \right] &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Thus,&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\frac{\partial \left\langle E\right\rangle}{\partial T} = \frac{Var[E]}{k_BT^2} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Heat Capacity versus Temperature===&lt;br /&gt;
Below, a screenshot of the Python script written to produce plots of &amp;lt;math&amp;gt; C_V &amp;lt;/math&amp;gt; against &amp;lt;math&amp;gt; T &amp;lt;/math&amp;gt;, together with the output images of this script.&lt;br /&gt;
 &lt;br /&gt;
[[File:HeatCapScript.PNG]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====2x2====&lt;br /&gt;
[[File:HC2.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====4x4====&lt;br /&gt;
[[File:HC4.png]]&lt;br /&gt;
&lt;br /&gt;
====8x8====&lt;br /&gt;
[[File:HC8.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====16x16====&lt;br /&gt;
[[File:HC16.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====32x32====&lt;br /&gt;
[[File:HC32.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= Locating the Curie Temperature =&lt;br /&gt;
&lt;br /&gt;
===C++ Data Comparison===&lt;br /&gt;
Below a comparison of the &amp;lt;math&amp;gt; C_V &amp;lt;/math&amp;gt; against &amp;lt;math&amp;gt; T &amp;lt;/math&amp;gt; plot generated for the &amp;lt;math&amp;gt; 2 /times 2&amp;lt;/math&amp;gt; to the corresponding C++ data is offered.&lt;br /&gt;
 &lt;br /&gt;
[[File:CHC2.png]]&lt;br /&gt;
&lt;br /&gt;
The data generated by the ILtemperaturerange.py script is a faithful match to the C++ data. However, this is an exceptional case; the plots for all other lattice sizes were found to be very dissimilar, necessitating polynomial fitting.&lt;br /&gt;
&lt;br /&gt;
==Polyfitting of C++ Data==&lt;br /&gt;
&lt;br /&gt;
===Fitting a Polynomial to the Entire Range===&lt;br /&gt;
The following Python script was written to perform a polynomial fit to the entire range of the graph of &amp;lt;math&amp;gt; C_V &amp;lt;/math&amp;gt; against &amp;lt;math&amp;gt; T &amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:HeatCapPoly.PNG]]&lt;br /&gt;
&lt;br /&gt;
Below, the result of the polyfit to the &amp;lt;math&amp;gt; 2/times2&amp;lt;/math&amp;gt; lattice data is offered (for comparison to the previous, non-fitted example).&lt;br /&gt;
&lt;br /&gt;
[[File:15Polyc2x2.png]]&lt;br /&gt;
&lt;br /&gt;
Polynomials with 5 terms and above were found to match the data in the vicinity of the critical region considerably well. Below 7 terms, the &#039;&#039;tails&#039;&#039; of the plot were matched poorly. In the above example, a polynomial of 15 terms was fit to the data.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Fitting a Polynomial to the Critical Region===&lt;br /&gt;
&lt;br /&gt;
The following Python script was written to perform a polynomial fit to the region of interest (the &#039;&#039;critical&#039;&#039; region) of the plots of &amp;lt;math&amp;gt; C_V &amp;lt;/math&amp;gt; against &amp;lt;math&amp;gt; T &amp;lt;/math&amp;gt; to facilitate the discovery of &amp;lt;math&amp;gt; T_C &amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
[[File:CapPolyCrit.PNG]]&lt;br /&gt;
&lt;br /&gt;
An example of the result returned by the script is offered below for the C++ data for the &amp;lt;math&amp;gt; 16\times16&amp;lt;/math&amp;gt; lattice.&lt;br /&gt;
&lt;br /&gt;
[[File:HHCPC16,2.6-2.1,5.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Finding the Peak C Values for Each Lattice Size===&lt;br /&gt;
Below, a screenshot of the code used to obtain the temperatures at which the maximum values of C occured is presented for each lattice size. The temperatures themselves are also featured on the image.&lt;br /&gt;
&lt;br /&gt;
[[File:Tmaxes.PNG]]&lt;br /&gt;
&lt;br /&gt;
The range of lattice sizes and their associated &amp;lt;math&amp;gt;T_{C} &amp;lt;/math&amp;gt; values were exported to a [[Media:Tmax.txt|text file]], enabling a plot to be created.&lt;br /&gt;
&lt;br /&gt;
[[File:CritTempPlot2.png]]&lt;br /&gt;
&lt;br /&gt;
Subsequently, the scipy.optimize.curve_fit function was used to fit &amp;lt;math&amp;gt;T_{C, L} = \frac{A}{L} + T_{C,\infty}&amp;lt;/math&amp;gt; function to the data obtained. This enabled the estimation the constant &amp;lt;math&amp;gt; A &amp;lt;/math&amp;gt; and the value of &amp;lt;math&amp;gt;T_{C} &amp;lt;/math&amp;gt; at &amp;lt;math&amp;gt; \frac{A}{L} = 0&amp;lt;/math&amp;gt;, otherwise &amp;lt;math&amp;gt; T_{C,\infty}&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
[[File:FindingTc.PNG]]&lt;br /&gt;
&lt;br /&gt;
A value of &amp;lt;math&amp;gt; T_{C,\infty} = 2.2799 &amp;lt;/math&amp;gt; was obtained. A comparison to the literature[https://en.wikipedia.org/wiki/Square-lattice_Ising_model#Critical_temperature] value of &amp;lt;math&amp;gt;2.269&amp;lt;/math&amp;gt; reveals a percentage error value of only &amp;lt;math&amp;gt; 0.47% &amp;lt;/math&amp;gt;. Surprisingly, the investigation of lattices in the given size range was enough to capture the theoretical behaviour of an infinite lattice. As explained by Frenkel and Smit, the implementation of periodic boundary conditions enables the simulation of an infinite bulk (or infinite adjacent lattices) surrounding the single lattice under scrutiny. The agreement of the experimental and theoretical values for &amp;lt;math&amp;gt; T_{C,\infty} &amp;lt;/math&amp;gt; prove the effectiveness of this idea.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
A likely source of error arises from the polynomial fitting of the data. The peaks in &amp;lt;math&amp;gt; C_V &amp;lt;/math&amp;gt; against &amp;lt;math&amp;gt; T &amp;lt;/math&amp;gt; were far more sharp than the broad peaks of the polynomial functions used to fit them. In several cases, the polynomial peak was a slight, yet discernible overestimate of the true peak. This has resulted in an overestimation of the final &amp;lt;math&amp;gt; T_{C,\infty} &amp;lt;/math&amp;gt; value. Fitting a function with a sharper peak to the critical region could overcome this overestimation and provide a more faithful final value.&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
* Frenkel, Daan, et al. Understanding Molecular Simulation : From Algorithms to Applications, Elsevier Science &amp;amp; Technology, 2001&lt;br /&gt;
&lt;br /&gt;
* Krieger, M. Constitutions of matter : Mathematically modeling the most everyday of physical phenomena. Chicago ; London: University of Chicago Press, 1996&lt;br /&gt;
&lt;br /&gt;
* https://en.wikipedia.org/wiki/Square-lattice_Ising_model Accessed 13-11-18&lt;/div&gt;</summary>
		<author><name>Jj1516</name></author>
	</entry>
	<entry>
		<id>https://chemwiki.ch.ic.ac.uk/index.php?title=Rep:JJ1516Ising&amp;diff=736976</id>
		<title>Rep:JJ1516Ising</title>
		<link rel="alternate" type="text/html" href="https://chemwiki.ch.ic.ac.uk/index.php?title=Rep:JJ1516Ising&amp;diff=736976"/>
		<updated>2018-11-21T09:55:59Z</updated>

		<summary type="html">&lt;p&gt;Jj1516: /* Polyfitting of C++ Data */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Ex Script Link:&lt;br /&gt;
https://wiki.ch.ic.ac.uk/wiki/index.php?title=Third_year_CMP_compulsory_experiment&lt;br /&gt;
&lt;br /&gt;
= Introduction to the Ising Model =&lt;br /&gt;
&lt;br /&gt;
== The Model ==&lt;br /&gt;
&lt;br /&gt;
=== Minimum Energy State ===&lt;br /&gt;
====Minimum Interaction Energy====&lt;br /&gt;
The interaction energy of an Ising lattice is given by:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;E = -\frac{1}{2}J\displaystyle\sum_{i}^{N} \displaystyle\sum_{j\;\in\;{neighbours}\;(i)} \!\!\!\!\!\!\!\!\!\!\!\!s_{i}s_{j}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In an Ising lattice with D dimensions and periodic boundary conditions, a given spin &amp;lt;math&amp;gt; s_i&amp;lt;/math&amp;gt; has 2D neighbours.&lt;br /&gt;
&lt;br /&gt;
The minimum interaction energy is achieved when all spins in the lattice are aligned (all ↑ or all ↓). As  such, any spin &amp;lt;math&amp;gt; s_i&amp;lt;/math&amp;gt; must be aligned with all 2D of its neighbours. That is, &amp;lt;math&amp;gt;s_{i}s_{j} = 1&amp;lt;/math&amp;gt; for all &amp;lt;math&amp;gt;j&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Therefore, for any &amp;lt;math&amp;gt; s_i&amp;lt;/math&amp;gt;, the sum of its interactions is &amp;lt;math&amp;gt;\displaystyle\sum_{j\;\in\;{neighbours}\;(i)} \!\!\!\!\!\!\!\!\!\!\!\!s_{i}s_{j} = 2D &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
As this is true for all N spins in the lattice, it follows that &amp;lt;math&amp;gt;\displaystyle\sum_{i}^{N} 2D = 2DN&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Thus the minimum interaction energy is given by:&lt;br /&gt;
&lt;br /&gt;
:&amp;lt;math&amp;gt;E_{min} = -\frac{1}{2}J\cdot2DN = - DNJ &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Entropy of the Minimum Energy State====&lt;br /&gt;
&lt;br /&gt;
The entropy of a state is given by:&lt;br /&gt;
&lt;br /&gt;
:&amp;lt;math&amp;gt;S = k\; ln\; \Omega &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Where &amp;lt;math&amp;gt; \Omega &amp;lt;/math&amp;gt; is the multiplicity of the state, the number of degenerate configurations of said state. The minimum energy state is achievable with all spins ↑ or with all spins ↓. In the absence of an external magnetic field, these configurations are degenerate and indistinguishable giving &amp;lt;math&amp;gt; \Omega = 2 &amp;lt;/math&amp;gt; for this state. Therefore,&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; S_{E_{min}}  = k_{B}\; ln\; 2 = 0.693k_{B} = 9.57 \times 10^{-24} J\!\cdot\!\! K^{-1}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Phase Transitions ==&lt;br /&gt;
&lt;br /&gt;
=== Changes to Minimum Energy Configuration ===&lt;br /&gt;
&lt;br /&gt;
====Energy Change ====&lt;br /&gt;
The energy change &amp;lt;math&amp;gt; \Delta E&amp;lt;/math&amp;gt; associated with a single spin &#039;flip&#039; from the lowest energy onfiguration may be calculated by considering the change in the interaction energy with the spin&#039;s neighbours.&lt;br /&gt;
&lt;br /&gt;
Let &amp;lt;math&amp;gt; D = 3, N = 1000 &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\Delta{E} = E_1 - E_0&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;E_1&amp;lt;/math&amp;gt; Interaction energy after one spin has been &#039;flipped&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;E_0&amp;lt;/math&amp;gt; Lowest energy configuration&lt;br /&gt;
&lt;br /&gt;
[[Image:Task 2 table.PNG]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\displaystyle\sum_{interactions} = -2D + 2D(2D-2) + 2D[N-(2D+1)] &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; = 2DN - 8D &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;E_1 = \displaystyle-\frac{1}{2}J\;\sum_{interactions} = 4DJ - DNJ&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\Delta{E} = E_1 - E_0 = 4DJ - DNJ + DNJ = +4DJ = +12J&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This energy change is independent of &amp;lt;math&amp;gt; N&amp;lt;/math&amp;gt; and depends only on the dimension size and the coupling constant &amp;lt;math&amp;gt; J &amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
In this calculation, the following assumption has been made.&lt;br /&gt;
&lt;br /&gt;
* The lattice dimensions are infinite relative to the size of each cell&lt;br /&gt;
&lt;br /&gt;
This allows &#039;&#039;&#039;any&#039;&#039;&#039; cell to be treated as the centre of the lattice. As every cell interacts with 2D neighbours, flipping any cell in the minimum energy configuration results in the same energy change. Alternatively, the periodic boundary conditions of the Ising model remove the necessity for such an assumption. As a consequence, the absence of &amp;lt;math&amp;gt; N &amp;lt;/math&amp;gt; from the resulting energy change is justified.&lt;br /&gt;
&lt;br /&gt;
====Entropy Change====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; S = k_{B}\; ln\; \Omega &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\Omega = \displaystyle\frac{N!}{{N_{\uparrow}!}{N_{\downarrow}!}}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Where &amp;lt;math&amp;gt;N_{x}!&amp;lt;/math&amp;gt; denotes the factorial of the number of spins in spin state &amp;lt;math&amp;gt;x&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\Delta{S} = k_{B}\;ln\;\left(\displaystyle\frac{\Omega_{2}}{\Omega_{1}}\right)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\Omega_{2} = \frac{1000!}{999!1!} = 1000&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \Omega_{1} = \frac{1000!}{1000!} = 1&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\Delta{S} = k_{B}\;ln\;1000 = 9.54 \times 10^{-23} JK^{-1}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\Delta{S_{mol}} = N_{A}k_{B}\;ln\;1000 = 57.4 \,JK^{-1}mol^{-1}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Magnetisation Values of 1D and 2D Lattices===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;M = \sum_i s_i&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====1D Lattice Magnetisation====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;M_{1D} =\;\;+1&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====2D Lattice Magnetisation====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;M_{2D} =\;\;+1&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Magnetisation at 0K====&lt;br /&gt;
&lt;br /&gt;
At 0K, no thermal energy is available to overcome the energetic barriers to spin flipping. Considering the Hemholtz free energy:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; A = E - TS &amp;lt;/math&amp;gt; &lt;br /&gt;
&lt;br /&gt;
A temperature of 0K nullifies the entropic contribution to the free energy. Thus the energetic driving force (which maximises parallel spin interactions) dominates the entropic driving force (which maximises multiplicity of lattice states). For an Ising Lattice with D =  3, N = 1000 at 0K, the alignment of all spins results in the minimum energy configuration  and an overall magnetisation of &amp;lt;math&amp;gt; M = \pm 1000 &amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
= Calculating the Energy and Magnetisation =&lt;br /&gt;
==Modifying the Files==&lt;br /&gt;
&lt;br /&gt;
===Energy and Magnetisation Functions===&lt;br /&gt;
&lt;br /&gt;
====Energy===&lt;br /&gt;
[[File:First_Ene_Method.PNG]]&lt;br /&gt;
&lt;br /&gt;
The above energy method segments a given lattice into lattice cells on the edges, corners or in the bulk of the lattice and calculates the energy interactions with its neighbours as appropriate.&lt;br /&gt;
&lt;br /&gt;
====Magnetisation====&lt;br /&gt;
[[File:First_Mag_Method.PNG]]&lt;br /&gt;
&lt;br /&gt;
The magnetisation method loops over all elements in the array representing the Ising lattice and adds the value of the spin to the magnetisation variable.&lt;br /&gt;
&lt;br /&gt;
==Testing the Files==&lt;br /&gt;
&lt;br /&gt;
===ILCheck.py===&lt;br /&gt;
&lt;br /&gt;
[[File:ILChecks.PNG]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Above, the results of the ILcheck.py script are presented.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= Introduction to the Monte Carlo Simulation =&lt;br /&gt;
==Average Energy and Magnetisation==&lt;br /&gt;
===Configurations of a 100 Spin System===&lt;br /&gt;
For a system of two spins, 4 configurations are possible (↑↑, ↓↓, ↑↓, ↓↑) i.e. &amp;lt;math&amp;gt;2^{2}&amp;lt;/math&amp;gt;. For a system of 100 spins, there are &amp;lt;math&amp;gt;2^{100}&amp;lt;/math&amp;gt; configurations. In the first example, the ↑↑ and ↓↓ are degenerate, as are the ↑↓ and ↓↑ configurations. Therefore, dividing the number of possible configurations by the multiplicity of each configuration (&amp;lt;math&amp;gt;2&amp;lt;/math&amp;gt;) gives the number of non-degenerate configurations. As previously stated, degenerate configurations are indistinguishable in the absence of an external magnetic field.&lt;br /&gt;
&lt;br /&gt;
For 100 spins, this gives &amp;lt;math&amp;gt;\displaystyle\frac{2^{100}}{2} = 6.338 \times 10^{29} &amp;lt;/math&amp;gt; distinguishable configurations.&lt;br /&gt;
&lt;br /&gt;
If processing speed permits &amp;lt;math&amp;gt; 1 \times 10^{9}&amp;lt;/math&amp;gt; calculations each second, the evaluation of a single value of &amp;lt;math&amp;gt;\left\langle M\right\rangle_T&amp;lt;/math&amp;gt; would last &amp;lt;math&amp;gt; 6.338 \times 10^{20} &amp;lt;/math&amp;gt; seconds or &amp;lt;math&amp;gt; 1458 &amp;lt;/math&amp;gt; times the age of the Universe!&lt;br /&gt;
&lt;br /&gt;
==Modifying IsingLattice.py==&lt;br /&gt;
&lt;br /&gt;
===Monte Carlo and Statistics Methods===&lt;br /&gt;
[[File:Monte_Carlo.PNG]]&lt;br /&gt;
&lt;br /&gt;
[[File:stats.PNG]]&lt;br /&gt;
&lt;br /&gt;
The Metropolis Monte Carlo (MMC) algorithm provides a computationally inexpensive path from random initial states to the minimum free energy states of the Ising lattices generated. First, a random 2D Ising lattice is generated. A single random spin within this lattice is &amp;quot;flipped&amp;quot; and the resulting (internal) energy change between these states is measured. Recalling the relationship between the Hemholtz free energy, internal energy and entropy, it follows that a decrease in internal energy also lowers the free energy of the system: thus the configuration change is accepted.&lt;br /&gt;
&lt;br /&gt;
In the case that the spin &amp;quot;flip&amp;quot; does not lower the internal energy, the MMC algorithm tests this configuration change against the Boltzman factor. In the canonical (NVT) ensemble, the free energy of the system is given by:&lt;br /&gt;
&lt;br /&gt;
:&amp;lt;math&amp;gt;A = -k_{B}T\,lnZ_{NVT} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
where Z is the canonical partition function which depends upon &amp;lt;math&amp;gt; e^{-\frac{\Delta E}{k_BT}} &amp;lt;/math&amp;gt;, the Boltzman factor. By choosing a random value in the interval [0,1)from a continuous uniformm probability distribution and rejecting any value of the Boltzman factor less than this value, ###&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Spontaneous Magnetisation===&lt;br /&gt;
&lt;br /&gt;
Below the Curie Temperature, &amp;lt;math&amp;gt; T_{C} &amp;lt;/math&amp;gt;, the energetic driving force dominates the entropic driving force, resulting in a highly ordered system and an overall magnetisation. The spins of the system align in order to maximise favourable coupling interactions rather than adopting a less ordered configuration of higher multiplicity. Therefore, when &amp;lt;math&amp;gt;T &amp;lt; T_C&amp;lt;/math&amp;gt;, the most probable configurations have an overall magnetisation resulting in &amp;lt;math&amp;gt;\left\langle M\right\rangle \neq 0&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
The plots of magnetisation per spin and energy per spin obtained from ILanim.py support this prediction. Below, the plots show that upon equilibration, the system adopts the minimum energy per spin: &amp;lt;math&amp;gt;E_{min_{spin}} = \frac{-NDJ}{N} = -DJ = -2&amp;lt;/math&amp;gt; and exhibits the maximum magnitude of magnetisation per spin: &amp;lt;math&amp;gt;|M_{spin}| = 1&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:2T=1.0.png]]&lt;br /&gt;
[[File:T=1.0.png]]&lt;br /&gt;
[[File:3T=1.0.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
An unknown system error prevented the statistics() function from printing the average values.&lt;br /&gt;
&lt;br /&gt;
=Accelerating the Code=&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Initial Method Speeds===&lt;br /&gt;
Taking 10 repeat measurements for the time taken to perform 2000 Monte Carlo steps resulted in&lt;br /&gt;
&lt;br /&gt;
* An average time of  &amp;lt;math&amp;gt;11.7s&amp;lt;/math&amp;gt; &lt;br /&gt;
* A standard error of &amp;lt;math&amp;gt;0.020s&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Updating Measurement===&lt;br /&gt;
&lt;br /&gt;
NOTE: ILtimetrial.py has been modified to:&lt;br /&gt;
* Perform a requested number of &#039;2000 Monte Carlo Step&#039; measurements&lt;br /&gt;
* Record these measurements in a CSV file&lt;br /&gt;
* Return the mean measuremd time and the Standard Error i.e.   &amp;lt;math&amp;gt; \frac{\sigma}{n} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:TimeTrialMethod.PNG]]&lt;br /&gt;
&lt;br /&gt;
===Updating Energy and Magnetisation Methods===&lt;br /&gt;
[[File:New_Mag_Method.PNG]]&lt;br /&gt;
[[File:New_Ene_Method.PNG]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Updated Method Speeds===&lt;br /&gt;
[[File:TimeTrial.PNG]]&lt;br /&gt;
&lt;br /&gt;
Taking 30 measurements of the time taken to perform 2000 Monte Carlo Steps resulted in:&lt;br /&gt;
&lt;br /&gt;
* An average time of &amp;lt;math&amp;gt;\displaystyle{0.87s}&amp;lt;/math&amp;gt;&lt;br /&gt;
* A standard error of &amp;lt;math&amp;gt;2.5 \times 10^{-3}s&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This represents a 93% decrease in the average computation time from the initial methods.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=The Effect of Temperature=&lt;br /&gt;
&lt;br /&gt;
==Correcting the Averaging  Code==&lt;br /&gt;
&lt;br /&gt;
===Finding a Delay Value===&lt;br /&gt;
To quickly find a value for &amp;lt;math&amp;gt; N_{d}&amp;lt;/math&amp;gt;, the minimum number of cycles typically needed for the equilibration of a system of within the lattice and temperature ranges of interest, it was assumed that:&lt;br /&gt;
&lt;br /&gt;
* Larger lattices would require more Monte Carlo steps to reach equilibrium from their initial, random configurations&lt;br /&gt;
&lt;br /&gt;
* Lattices at lower temperatures would require more Monte Carlo steps to reach equilibrium from their initial, random configurations.&lt;br /&gt;
&lt;br /&gt;
Therefore, an initial value for &amp;lt;math&amp;gt; N_{d}&amp;lt;/math&amp;gt; was found for a &amp;lt;math&amp;gt; 128\times128 &amp;lt;/math&amp;gt; lattice at a temperature of &amp;lt;math&amp;gt;0.5&amp;lt;/math&amp;gt; reduced temperature units.&lt;br /&gt;
*&amp;lt;math&amp;gt; N_{d} = 185000 &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
By this number of steps, all smaller lattices at all higher temperatures were found to have equilibrated also. Thus, this value of&amp;lt;math&amp;gt; N_{d}&amp;lt;/math&amp;gt; was accepted as an appropriate delay.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:AFinFrame 128 3e5 T= 0.5line.png|400px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
For the 128x128 lattices at T=0.5, equilibration was ensured from 185000 steps onwards.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Smaller lattices at the same temperature did indeed equilibrate more slowly, but all equilibrated within &amp;lt;math&amp;gt; N_{d}&amp;lt;/math&amp;gt; MC steps.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:AFinFrame 64 3e5 T= 0.5line.png|400px]]&lt;br /&gt;
[[File:AFinFrame 32 3e5 T= 0.5line2.png|400px]]&lt;br /&gt;
[[File:AFinFrame 16 3e5 T= 0.5line2.png|400px]]&lt;br /&gt;
[[File:AFinFrame 8 3e5 T= 0.5line.png|400px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The figure below shows the modifications made to IsingLattice.py to incorporate the &amp;lt;math&amp;gt; N_{d} &amp;lt;/math&amp;gt; step delay.&lt;br /&gt;
&lt;br /&gt;
==Running over a Range of Temperatures==&lt;br /&gt;
&lt;br /&gt;
To examine the effect of temperature on the average energy &amp;lt;math&amp;gt; \left\langle E\right\rangle &amp;lt;/math&amp;gt; and average magnetisation &amp;lt;math&amp;gt; \left\langle M\right\rangle &amp;lt;/math&amp;gt; of Ising lattices at equilibrium, the following parameters were used:&lt;br /&gt;
&lt;br /&gt;
* Temperature Range: &amp;lt;math&amp;gt;  0.5 - 5 &amp;lt;/math&amp;gt; reduced units&lt;br /&gt;
* Temperature Interval: &amp;lt;math&amp;gt;0.01&amp;lt;/math&amp;gt; reduced units (&amp;lt;math&amp;gt;450&amp;lt;/math&amp;gt; temperature values)&lt;br /&gt;
* Number of MMC Steps per Temperature value: &amp;lt;math&amp;gt; 2 \times 10^5 &amp;lt;/math&amp;gt; with the aforementioned value of &amp;lt;math&amp;gt; N_{d} = 1.85 \times 10^5 &amp;lt;/math&amp;gt; Monte Carlo steps&lt;br /&gt;
* Lattice Sizes:  &amp;lt;math&amp;gt; 2 \times 2 &amp;lt;/math&amp;gt;, &amp;lt;math&amp;gt; 4 \times 4 &amp;lt;/math&amp;gt; , &amp;lt;math&amp;gt; 8 \times 8 &amp;lt;/math&amp;gt; , &amp;lt;math&amp;gt; 16 \times 16 &amp;lt;/math&amp;gt; , &amp;lt;math&amp;gt; 32 \times 32 &amp;lt;/math&amp;gt; , &amp;lt;math&amp;gt; 64 \times 64 &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Plots of  &amp;lt;math&amp;gt; \left\langle E\right\rangle &amp;lt;/math&amp;gt; and  &amp;lt;math&amp;gt; \left\langle M\right\rangle &amp;lt;/math&amp;gt; per spin as versus temperature are presented below for each lattice size. Errorbars have been implemented to demonstrate how &#039;&#039;well-behaved&#039;&#039; lattice systems of each size are at each temperature, that is, how temperature and lattice size affect the size of the variations in the expected values. For the error calculations, the standard errors, &amp;lt;math&amp;gt; \sigma_\bar{X} &amp;lt;/math&amp;gt;,  in &amp;lt;math&amp;gt; \left\langle E\right\rangle &amp;lt;/math&amp;gt; and  &amp;lt;math&amp;gt; \left\langle M\right\rangle &amp;lt;/math&amp;gt; per spin have been used:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====8x8====&lt;br /&gt;
&lt;br /&gt;
[[File:8x8e+error.png]] [[File:8x8m+error.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
A Python script has been written to generate a plot of &amp;lt;math&amp;gt;\left\langle E\right\rangle&amp;lt;/math&amp;gt; or &amp;lt;math&amp;gt;\left\langle M\right\rangle&amp;lt;/math&amp;gt; against temperature based upon user input. A screenshot of this code has been inserted below.&lt;br /&gt;
&lt;br /&gt;
[[File:ExpectedvsTemp.PNG|200px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=The Effect of System Size=&lt;br /&gt;
&lt;br /&gt;
==Scaling the System Size==&lt;br /&gt;
&lt;br /&gt;
===More Lattice Sizes===&lt;br /&gt;
&lt;br /&gt;
====2x2====&lt;br /&gt;
[[File:2x2e+error.png]] [[File:2x2m+error.png]]&lt;br /&gt;
&lt;br /&gt;
====4x4====&lt;br /&gt;
[[File:4x4e+error.png]] [[File:4x4m+error.png]]&lt;br /&gt;
&lt;br /&gt;
====16x16====&lt;br /&gt;
[[File:16x16e+error.png]] [[File:16x16m+error.png]]&lt;br /&gt;
&lt;br /&gt;
====32x32====&lt;br /&gt;
[[File:32x32e+error.png]] [[File:32x32m+error.png]]&lt;br /&gt;
&lt;br /&gt;
====64x64====&lt;br /&gt;
[[File:64x64e+error.png]] [[File:64x64m+error.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Scrutiny of the plots of average energy per spin for each lattice size reveals an increase in the errorbar width with increasing lattice size. This is most notable in the low temperature region of the plots. Between the &amp;lt;math&amp;gt; 8\times8 &amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt; 16\times16 &amp;lt;/math&amp;gt; lattices, the long range fluctuations become suddenly prominent. The &amp;lt;math&amp;gt;16\times16&amp;lt;/math&amp;gt; lattice is the first (in the range of sizes tested)to clearly capture these fluctuations.&lt;br /&gt;
&lt;br /&gt;
=Determining the Heat Capacity=&lt;br /&gt;
&lt;br /&gt;
==Calculating the Heat Capacity==&lt;br /&gt;
&lt;br /&gt;
===Heat Capacity Derivation===&lt;br /&gt;
Working in the canonical ensemble (constant volume), the heat capacity &amp;lt;math&amp;gt; C_V &amp;lt;/math&amp;gt; is given by:&lt;br /&gt;
&lt;br /&gt;
:&amp;lt;math&amp;gt;C_V = \frac{\partial \left\langle E\right\rangle}{\partial T}_V&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
where &amp;lt;math&amp;gt;\left\langle E\right\rangle&amp;lt;/math&amp;gt; is the average total energy or expected value of the internal energy of the system.&lt;br /&gt;
&lt;br /&gt;
: &amp;lt;math&amp;gt; \left\langle E\right\rangle = - \frac{\partial ln Q}{\partial \beta} = -\frac{1}{Q}\frac{\partial Q}{\partial \beta} &amp;lt;/math&amp;gt;&lt;br /&gt;
where &amp;lt;math&amp;gt; Q&amp;lt;/math&amp;gt; is the partition function for the system of N interacting spins.&lt;br /&gt;
&lt;br /&gt;
By evaluating the second form of the partial derivative with respect to &amp;lt;math&amp;gt; \beta&amp;lt;/math&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \left\langle E\right\rangle = -\frac{1}{Q}\frac{\partial Q}{\partial \beta} = \frac{\Sigma \epsilon_{i} e^{-\beta \epsilon_{i}}}{\Sigma e^{-\beta \epsilon_{i}}} &amp;lt;/math&amp;gt; &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Applying the product rule enables the differentiation of this expression for &amp;lt;math&amp;gt;\left\langle E\right\rangle&amp;lt;/math&amp;gt; with respect to temperature, giving:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\frac{\partial \left\langle E\right\rangle}{\partial T} = \frac{\Sigma \epsilon_{i} \frac{\epsilon_i}{k_BT^2}e^{-\beta \epsilon_{i}}}{\Sigma e^{-\beta \epsilon_{i}}} - \frac{\Sigma \epsilon_i e^{-\beta \epsilon_i}\cdot \frac{\epsilon_i}{k_BT^2}e^{-\beta \epsilon_i}}{(\Sigma e^{-\beta \epsilon_{i}})^2}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\frac{\partial \left\langle E\right\rangle}{\partial T}  = \frac{1}{k_BT^2}\left[\frac{\Sigma \epsilon_i^2 e^{-\beta \epsilon_i}}{\Sigma e^{-\beta \epsilon_i}} - \left(\frac{\Sigma \epsilon_{i} e^{-\beta \epsilon_{i}}}{\Sigma e^{-\beta \epsilon_{i}}}\right)^2\right] &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\frac{\partial \left\langle E\right\rangle}{\partial T}  = \frac{1}{k_BT^2}\left[\left\langle E^2\right\rangle - \left\langle E\right\rangle^2 \right] &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Thus,&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\frac{\partial \left\langle E\right\rangle}{\partial T} = \frac{Var[E]}{k_BT^2} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Heat Capacity versus Temperature===&lt;br /&gt;
Below, a screenshot of the Python script written to produce plots of &amp;lt;math&amp;gt; C_V &amp;lt;/math&amp;gt; against &amp;lt;math&amp;gt; T &amp;lt;/math&amp;gt;, together with the output images of this script.&lt;br /&gt;
 &lt;br /&gt;
[[File:HeatCapScript.PNG]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====2x2====&lt;br /&gt;
[[File:HC2.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====4x4====&lt;br /&gt;
[[File:HC4.png]]&lt;br /&gt;
&lt;br /&gt;
====8x8====&lt;br /&gt;
[[File:HC8.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====16x16====&lt;br /&gt;
[[File:HC16.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====32x32====&lt;br /&gt;
[[File:HC32.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= Locating the Curie Temperature =&lt;br /&gt;
&lt;br /&gt;
===C++ Data Comparison===&lt;br /&gt;
Below a comparison of the &amp;lt;math&amp;gt; C_V &amp;lt;/math&amp;gt; against &amp;lt;math&amp;gt; T &amp;lt;/math&amp;gt; plot generated for the &amp;lt;math&amp;gt; 2 /times 2&amp;lt;/math&amp;gt; to the corresponding C++ data is offered.&lt;br /&gt;
 &lt;br /&gt;
[[File:CHC2.png]]&lt;br /&gt;
&lt;br /&gt;
The data generated by the ILtemperaturerange.py script is a faithful match to the C++ data. However, this is an exceptional case; the plots for all other lattice sizes were found to be very dissimilar, necessitating polynomial fitting.&lt;br /&gt;
&lt;br /&gt;
==Polyfitting of C++ Data==&lt;br /&gt;
&lt;br /&gt;
===Fitting a Polynomial to the Entire Range===&lt;br /&gt;
The following Python script was written to perform a polynomial fit to the entire range of the graph of &amp;lt;math&amp;gt; C_V &amp;lt;/math&amp;gt; against &amp;lt;math&amp;gt; T &amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:HeatCapPoly.PNG]]&lt;br /&gt;
&lt;br /&gt;
Below, the result of the polyfit to the &amp;lt;math&amp;gt; 2/times2&amp;lt;/math&amp;gt; lattice data is offered (for comparison to the previous, non-fitted example).&lt;br /&gt;
&lt;br /&gt;
[[File:15Polyc2x2.png]]&lt;br /&gt;
&lt;br /&gt;
Polynomials with 5 terms and above were found to match the data in the vicinity of the critical region considerably well. Below 7 terms, the &#039;&#039;tails&#039;&#039; of the plot were matched poorly. In the above example, a polynomial of 15 terms was fit to the data.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Fitting a Polynomial to the Critical Region===&lt;br /&gt;
&lt;br /&gt;
The following Python script was written to perform a polynomial fit to the region of interest (the &#039;&#039;critical&#039;&#039; region) of the plots of &amp;lt;math&amp;gt; C_V &amp;lt;/math&amp;gt; against &amp;lt;math&amp;gt; T &amp;lt;/math&amp;gt; to facilitate the discovery of &amp;lt;math&amp;gt; T_C &amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
[[File:CapPolyCrit.PNG]]&lt;br /&gt;
&lt;br /&gt;
An example of the result returned by the script is offered below for the C++ data for the &amp;lt;math&amp;gt; 16\times16&amp;lt;/math&amp;gt; lattice.&lt;br /&gt;
&lt;br /&gt;
[[File:HHCPC16,2.6-2.1,5.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Finding the Peak C Values for Each Lattice Size===&lt;br /&gt;
Below, a screenshot of the code used to obtain the temperatures at which the maximum values of C occured is presented for each lattice size. The temperatures themselves are also featured on the image.&lt;br /&gt;
&lt;br /&gt;
[[File:Tmaxes.PNG]]&lt;br /&gt;
&lt;br /&gt;
The range of lattice sizes and their associated &amp;lt;math&amp;gt;T_{C} &amp;lt;/math&amp;gt; values were exported to a [[Media:Tmax.txt|text file]], enabling a plot to be created.&lt;br /&gt;
&lt;br /&gt;
[[File:CritTempPlot2.png]]&lt;br /&gt;
&lt;br /&gt;
Subsequently, the scipy.optimize.curve_fit function was used to fit &amp;lt;math&amp;gt;T_{C, L} = \frac{A}{L} + T_{C,\infty}&amp;lt;/math&amp;gt; function to the data obtained. This enabled the estimation the constant &amp;lt;math&amp;gt; A &amp;lt;/math&amp;gt; and the value of &amp;lt;math&amp;gt;T_{C} &amp;lt;/math&amp;gt; at &amp;lt;math&amp;gt; \frac{A}{L} = 0&amp;lt;/math&amp;gt;, otherwise &amp;lt;math&amp;gt; T_{C,\infty}&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
[[File:FindingTc.PNG]]&lt;br /&gt;
&lt;br /&gt;
A value of &amp;lt;math&amp;gt; T_{C,\infty} = 2.2799 &amp;lt;/math&amp;gt; was obtained. Comparing this to the [https://en.wikipedia.org/wiki/Square-lattice_Ising_model#Critical_temperature|literature] value of &amp;lt;math&amp;gt;2.269&amp;lt;/math&amp;gt;, reveals an error in the obtained value of only &amp;lt;math&amp;gt; 0.47% &amp;lt;/math&amp;gt;. Surprisingly, the investigation of lattices in the given size range was enough to capture the theoretical behaviour of an infinite lattice. As explained by Frenkel and Smit, the implementation of periodic boundary conditions enables the simulation of an infinite bulk (or infinite adjacent lattices) surrounding the single lattice under scrutiny. The agreement of the experimental and theoretical values for &amp;lt;math&amp;gt; T_{C,\infty} &amp;lt;/math&amp;gt; prove the effectiveness of this idea.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
A likely source of error arises from the polynomial fitting of the data. The peaks in &amp;lt;math&amp;gt; C_V &amp;lt;/math&amp;gt; against &amp;lt;math&amp;gt; T &amp;lt;/math&amp;gt; were far more sharp than the broad peaks of the polynomial functions used to fit them. In several cases, the polynomial peak was a slight, yet discernible overestimate of the true peak. This has resulted in an overestimation of the final &amp;lt;math&amp;gt; T_{C,\infty} &amp;lt;/math&amp;gt; value. Fitting a function with a sharper peak to the critical region could overcome this overestimation and provide a more faithful final value.&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
* Frenkel, Daan, et al. Understanding Molecular Simulation : From Algorithms to Applications, Elsevier Science &amp;amp; Technology, 2001&lt;br /&gt;
&lt;br /&gt;
* Krieger, M. Constitutions of matter : Mathematically modeling the most everyday of physical phenomena. Chicago ; London: University of Chicago Press, 1996&lt;br /&gt;
&lt;br /&gt;
* https://en.wikipedia.org/wiki/Square-lattice_Ising_model Accessed 13-11-18&lt;/div&gt;</summary>
		<author><name>Jj1516</name></author>
	</entry>
	<entry>
		<id>https://chemwiki.ch.ic.ac.uk/index.php?title=File:CritTempPlot2.png&amp;diff=736973</id>
		<title>File:CritTempPlot2.png</title>
		<link rel="alternate" type="text/html" href="https://chemwiki.ch.ic.ac.uk/index.php?title=File:CritTempPlot2.png&amp;diff=736973"/>
		<updated>2018-11-21T09:54:55Z</updated>

		<summary type="html">&lt;p&gt;Jj1516: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Jj1516</name></author>
	</entry>
	<entry>
		<id>https://chemwiki.ch.ic.ac.uk/index.php?title=Rep:JJ1516Ising&amp;diff=736969</id>
		<title>Rep:JJ1516Ising</title>
		<link rel="alternate" type="text/html" href="https://chemwiki.ch.ic.ac.uk/index.php?title=Rep:JJ1516Ising&amp;diff=736969"/>
		<updated>2018-11-21T09:53:39Z</updated>

		<summary type="html">&lt;p&gt;Jj1516: /* Finding the Peak C Values for Each Lattice Size */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Ex Script Link:&lt;br /&gt;
https://wiki.ch.ic.ac.uk/wiki/index.php?title=Third_year_CMP_compulsory_experiment&lt;br /&gt;
&lt;br /&gt;
= Introduction to the Ising Model =&lt;br /&gt;
&lt;br /&gt;
== The Model ==&lt;br /&gt;
&lt;br /&gt;
=== Minimum Energy State ===&lt;br /&gt;
====Minimum Interaction Energy====&lt;br /&gt;
The interaction energy of an Ising lattice is given by:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;E = -\frac{1}{2}J\displaystyle\sum_{i}^{N} \displaystyle\sum_{j\;\in\;{neighbours}\;(i)} \!\!\!\!\!\!\!\!\!\!\!\!s_{i}s_{j}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In an Ising lattice with D dimensions and periodic boundary conditions, a given spin &amp;lt;math&amp;gt; s_i&amp;lt;/math&amp;gt; has 2D neighbours.&lt;br /&gt;
&lt;br /&gt;
The minimum interaction energy is achieved when all spins in the lattice are aligned (all ↑ or all ↓). As  such, any spin &amp;lt;math&amp;gt; s_i&amp;lt;/math&amp;gt; must be aligned with all 2D of its neighbours. That is, &amp;lt;math&amp;gt;s_{i}s_{j} = 1&amp;lt;/math&amp;gt; for all &amp;lt;math&amp;gt;j&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Therefore, for any &amp;lt;math&amp;gt; s_i&amp;lt;/math&amp;gt;, the sum of its interactions is &amp;lt;math&amp;gt;\displaystyle\sum_{j\;\in\;{neighbours}\;(i)} \!\!\!\!\!\!\!\!\!\!\!\!s_{i}s_{j} = 2D &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
As this is true for all N spins in the lattice, it follows that &amp;lt;math&amp;gt;\displaystyle\sum_{i}^{N} 2D = 2DN&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Thus the minimum interaction energy is given by:&lt;br /&gt;
&lt;br /&gt;
:&amp;lt;math&amp;gt;E_{min} = -\frac{1}{2}J\cdot2DN = - DNJ &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Entropy of the Minimum Energy State====&lt;br /&gt;
&lt;br /&gt;
The entropy of a state is given by:&lt;br /&gt;
&lt;br /&gt;
:&amp;lt;math&amp;gt;S = k\; ln\; \Omega &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Where &amp;lt;math&amp;gt; \Omega &amp;lt;/math&amp;gt; is the multiplicity of the state, the number of degenerate configurations of said state. The minimum energy state is achievable with all spins ↑ or with all spins ↓. In the absence of an external magnetic field, these configurations are degenerate and indistinguishable giving &amp;lt;math&amp;gt; \Omega = 2 &amp;lt;/math&amp;gt; for this state. Therefore,&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; S_{E_{min}}  = k_{B}\; ln\; 2 = 0.693k_{B} = 9.57 \times 10^{-24} J\!\cdot\!\! K^{-1}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Phase Transitions ==&lt;br /&gt;
&lt;br /&gt;
=== Changes to Minimum Energy Configuration ===&lt;br /&gt;
&lt;br /&gt;
====Energy Change ====&lt;br /&gt;
The energy change &amp;lt;math&amp;gt; \Delta E&amp;lt;/math&amp;gt; associated with a single spin &#039;flip&#039; from the lowest energy onfiguration may be calculated by considering the change in the interaction energy with the spin&#039;s neighbours.&lt;br /&gt;
&lt;br /&gt;
Let &amp;lt;math&amp;gt; D = 3, N = 1000 &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\Delta{E} = E_1 - E_0&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;E_1&amp;lt;/math&amp;gt; Interaction energy after one spin has been &#039;flipped&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;E_0&amp;lt;/math&amp;gt; Lowest energy configuration&lt;br /&gt;
&lt;br /&gt;
[[Image:Task 2 table.PNG]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\displaystyle\sum_{interactions} = -2D + 2D(2D-2) + 2D[N-(2D+1)] &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; = 2DN - 8D &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;E_1 = \displaystyle-\frac{1}{2}J\;\sum_{interactions} = 4DJ - DNJ&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\Delta{E} = E_1 - E_0 = 4DJ - DNJ + DNJ = +4DJ = +12J&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This energy change is independent of &amp;lt;math&amp;gt; N&amp;lt;/math&amp;gt; and depends only on the dimension size and the coupling constant &amp;lt;math&amp;gt; J &amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
In this calculation, the following assumption has been made.&lt;br /&gt;
&lt;br /&gt;
* The lattice dimensions are infinite relative to the size of each cell&lt;br /&gt;
&lt;br /&gt;
This allows &#039;&#039;&#039;any&#039;&#039;&#039; cell to be treated as the centre of the lattice. As every cell interacts with 2D neighbours, flipping any cell in the minimum energy configuration results in the same energy change. Alternatively, the periodic boundary conditions of the Ising model remove the necessity for such an assumption. As a consequence, the absence of &amp;lt;math&amp;gt; N &amp;lt;/math&amp;gt; from the resulting energy change is justified.&lt;br /&gt;
&lt;br /&gt;
====Entropy Change====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; S = k_{B}\; ln\; \Omega &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\Omega = \displaystyle\frac{N!}{{N_{\uparrow}!}{N_{\downarrow}!}}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Where &amp;lt;math&amp;gt;N_{x}!&amp;lt;/math&amp;gt; denotes the factorial of the number of spins in spin state &amp;lt;math&amp;gt;x&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\Delta{S} = k_{B}\;ln\;\left(\displaystyle\frac{\Omega_{2}}{\Omega_{1}}\right)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\Omega_{2} = \frac{1000!}{999!1!} = 1000&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \Omega_{1} = \frac{1000!}{1000!} = 1&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\Delta{S} = k_{B}\;ln\;1000 = 9.54 \times 10^{-23} JK^{-1}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\Delta{S_{mol}} = N_{A}k_{B}\;ln\;1000 = 57.4 \,JK^{-1}mol^{-1}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Magnetisation Values of 1D and 2D Lattices===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;M = \sum_i s_i&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====1D Lattice Magnetisation====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;M_{1D} =\;\;+1&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====2D Lattice Magnetisation====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;M_{2D} =\;\;+1&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Magnetisation at 0K====&lt;br /&gt;
&lt;br /&gt;
At 0K, no thermal energy is available to overcome the energetic barriers to spin flipping. Considering the Hemholtz free energy:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; A = E - TS &amp;lt;/math&amp;gt; &lt;br /&gt;
&lt;br /&gt;
A temperature of 0K nullifies the entropic contribution to the free energy. Thus the energetic driving force (which maximises parallel spin interactions) dominates the entropic driving force (which maximises multiplicity of lattice states). For an Ising Lattice with D =  3, N = 1000 at 0K, the alignment of all spins results in the minimum energy configuration  and an overall magnetisation of &amp;lt;math&amp;gt; M = \pm 1000 &amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
= Calculating the Energy and Magnetisation =&lt;br /&gt;
==Modifying the Files==&lt;br /&gt;
&lt;br /&gt;
===Energy and Magnetisation Functions===&lt;br /&gt;
&lt;br /&gt;
====Energy===&lt;br /&gt;
[[File:First_Ene_Method.PNG]]&lt;br /&gt;
&lt;br /&gt;
The above energy method segments a given lattice into lattice cells on the edges, corners or in the bulk of the lattice and calculates the energy interactions with its neighbours as appropriate.&lt;br /&gt;
&lt;br /&gt;
====Magnetisation====&lt;br /&gt;
[[File:First_Mag_Method.PNG]]&lt;br /&gt;
&lt;br /&gt;
The magnetisation method loops over all elements in the array representing the Ising lattice and adds the value of the spin to the magnetisation variable.&lt;br /&gt;
&lt;br /&gt;
==Testing the Files==&lt;br /&gt;
&lt;br /&gt;
===ILCheck.py===&lt;br /&gt;
&lt;br /&gt;
[[File:ILChecks.PNG]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Above, the results of the ILcheck.py script are presented.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= Introduction to the Monte Carlo Simulation =&lt;br /&gt;
==Average Energy and Magnetisation==&lt;br /&gt;
===Configurations of a 100 Spin System===&lt;br /&gt;
For a system of two spins, 4 configurations are possible (↑↑, ↓↓, ↑↓, ↓↑) i.e. &amp;lt;math&amp;gt;2^{2}&amp;lt;/math&amp;gt;. For a system of 100 spins, there are &amp;lt;math&amp;gt;2^{100}&amp;lt;/math&amp;gt; configurations. In the first example, the ↑↑ and ↓↓ are degenerate, as are the ↑↓ and ↓↑ configurations. Therefore, dividing the number of possible configurations by the multiplicity of each configuration (&amp;lt;math&amp;gt;2&amp;lt;/math&amp;gt;) gives the number of non-degenerate configurations. As previously stated, degenerate configurations are indistinguishable in the absence of an external magnetic field.&lt;br /&gt;
&lt;br /&gt;
For 100 spins, this gives &amp;lt;math&amp;gt;\displaystyle\frac{2^{100}}{2} = 6.338 \times 10^{29} &amp;lt;/math&amp;gt; distinguishable configurations.&lt;br /&gt;
&lt;br /&gt;
If processing speed permits &amp;lt;math&amp;gt; 1 \times 10^{9}&amp;lt;/math&amp;gt; calculations each second, the evaluation of a single value of &amp;lt;math&amp;gt;\left\langle M\right\rangle_T&amp;lt;/math&amp;gt; would last &amp;lt;math&amp;gt; 6.338 \times 10^{20} &amp;lt;/math&amp;gt; seconds or &amp;lt;math&amp;gt; 1458 &amp;lt;/math&amp;gt; times the age of the Universe!&lt;br /&gt;
&lt;br /&gt;
==Modifying IsingLattice.py==&lt;br /&gt;
&lt;br /&gt;
===Monte Carlo and Statistics Methods===&lt;br /&gt;
[[File:Monte_Carlo.PNG]]&lt;br /&gt;
&lt;br /&gt;
[[File:stats.PNG]]&lt;br /&gt;
&lt;br /&gt;
The Metropolis Monte Carlo (MMC) algorithm provides a computationally inexpensive path from random initial states to the minimum free energy states of the Ising lattices generated. First, a random 2D Ising lattice is generated. A single random spin within this lattice is &amp;quot;flipped&amp;quot; and the resulting (internal) energy change between these states is measured. Recalling the relationship between the Hemholtz free energy, internal energy and entropy, it follows that a decrease in internal energy also lowers the free energy of the system: thus the configuration change is accepted.&lt;br /&gt;
&lt;br /&gt;
In the case that the spin &amp;quot;flip&amp;quot; does not lower the internal energy, the MMC algorithm tests this configuration change against the Boltzman factor. In the canonical (NVT) ensemble, the free energy of the system is given by:&lt;br /&gt;
&lt;br /&gt;
:&amp;lt;math&amp;gt;A = -k_{B}T\,lnZ_{NVT} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
where Z is the canonical partition function which depends upon &amp;lt;math&amp;gt; e^{-\frac{\Delta E}{k_BT}} &amp;lt;/math&amp;gt;, the Boltzman factor. By choosing a random value in the interval [0,1)from a continuous uniformm probability distribution and rejecting any value of the Boltzman factor less than this value, ###&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Spontaneous Magnetisation===&lt;br /&gt;
&lt;br /&gt;
Below the Curie Temperature, &amp;lt;math&amp;gt; T_{C} &amp;lt;/math&amp;gt;, the energetic driving force dominates the entropic driving force, resulting in a highly ordered system and an overall magnetisation. The spins of the system align in order to maximise favourable coupling interactions rather than adopting a less ordered configuration of higher multiplicity. Therefore, when &amp;lt;math&amp;gt;T &amp;lt; T_C&amp;lt;/math&amp;gt;, the most probable configurations have an overall magnetisation resulting in &amp;lt;math&amp;gt;\left\langle M\right\rangle \neq 0&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
The plots of magnetisation per spin and energy per spin obtained from ILanim.py support this prediction. Below, the plots show that upon equilibration, the system adopts the minimum energy per spin: &amp;lt;math&amp;gt;E_{min_{spin}} = \frac{-NDJ}{N} = -DJ = -2&amp;lt;/math&amp;gt; and exhibits the maximum magnitude of magnetisation per spin: &amp;lt;math&amp;gt;|M_{spin}| = 1&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:2T=1.0.png]]&lt;br /&gt;
[[File:T=1.0.png]]&lt;br /&gt;
[[File:3T=1.0.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
An unknown system error prevented the statistics() function from printing the average values.&lt;br /&gt;
&lt;br /&gt;
=Accelerating the Code=&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Initial Method Speeds===&lt;br /&gt;
Taking 10 repeat measurements for the time taken to perform 2000 Monte Carlo steps resulted in&lt;br /&gt;
&lt;br /&gt;
* An average time of  &amp;lt;math&amp;gt;11.7s&amp;lt;/math&amp;gt; &lt;br /&gt;
* A standard error of &amp;lt;math&amp;gt;0.020s&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Updating Measurement===&lt;br /&gt;
&lt;br /&gt;
NOTE: ILtimetrial.py has been modified to:&lt;br /&gt;
* Perform a requested number of &#039;2000 Monte Carlo Step&#039; measurements&lt;br /&gt;
* Record these measurements in a CSV file&lt;br /&gt;
* Return the mean measuremd time and the Standard Error i.e.   &amp;lt;math&amp;gt; \frac{\sigma}{n} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:TimeTrialMethod.PNG]]&lt;br /&gt;
&lt;br /&gt;
===Updating Energy and Magnetisation Methods===&lt;br /&gt;
[[File:New_Mag_Method.PNG]]&lt;br /&gt;
[[File:New_Ene_Method.PNG]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Updated Method Speeds===&lt;br /&gt;
[[File:TimeTrial.PNG]]&lt;br /&gt;
&lt;br /&gt;
Taking 30 measurements of the time taken to perform 2000 Monte Carlo Steps resulted in:&lt;br /&gt;
&lt;br /&gt;
* An average time of &amp;lt;math&amp;gt;\displaystyle{0.87s}&amp;lt;/math&amp;gt;&lt;br /&gt;
* A standard error of &amp;lt;math&amp;gt;2.5 \times 10^{-3}s&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This represents a 93% decrease in the average computation time from the initial methods.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=The Effect of Temperature=&lt;br /&gt;
&lt;br /&gt;
==Correcting the Averaging  Code==&lt;br /&gt;
&lt;br /&gt;
===Finding a Delay Value===&lt;br /&gt;
To quickly find a value for &amp;lt;math&amp;gt; N_{d}&amp;lt;/math&amp;gt;, the minimum number of cycles typically needed for the equilibration of a system of within the lattice and temperature ranges of interest, it was assumed that:&lt;br /&gt;
&lt;br /&gt;
* Larger lattices would require more Monte Carlo steps to reach equilibrium from their initial, random configurations&lt;br /&gt;
&lt;br /&gt;
* Lattices at lower temperatures would require more Monte Carlo steps to reach equilibrium from their initial, random configurations.&lt;br /&gt;
&lt;br /&gt;
Therefore, an initial value for &amp;lt;math&amp;gt; N_{d}&amp;lt;/math&amp;gt; was found for a &amp;lt;math&amp;gt; 128\times128 &amp;lt;/math&amp;gt; lattice at a temperature of &amp;lt;math&amp;gt;0.5&amp;lt;/math&amp;gt; reduced temperature units.&lt;br /&gt;
*&amp;lt;math&amp;gt; N_{d} = 185000 &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
By this number of steps, all smaller lattices at all higher temperatures were found to have equilibrated also. Thus, this value of&amp;lt;math&amp;gt; N_{d}&amp;lt;/math&amp;gt; was accepted as an appropriate delay.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:AFinFrame 128 3e5 T= 0.5line.png|400px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
For the 128x128 lattices at T=0.5, equilibration was ensured from 185000 steps onwards.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Smaller lattices at the same temperature did indeed equilibrate more slowly, but all equilibrated within &amp;lt;math&amp;gt; N_{d}&amp;lt;/math&amp;gt; MC steps.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:AFinFrame 64 3e5 T= 0.5line.png|400px]]&lt;br /&gt;
[[File:AFinFrame 32 3e5 T= 0.5line2.png|400px]]&lt;br /&gt;
[[File:AFinFrame 16 3e5 T= 0.5line2.png|400px]]&lt;br /&gt;
[[File:AFinFrame 8 3e5 T= 0.5line.png|400px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The figure below shows the modifications made to IsingLattice.py to incorporate the &amp;lt;math&amp;gt; N_{d} &amp;lt;/math&amp;gt; step delay.&lt;br /&gt;
&lt;br /&gt;
==Running over a Range of Temperatures==&lt;br /&gt;
&lt;br /&gt;
To examine the effect of temperature on the average energy &amp;lt;math&amp;gt; \left\langle E\right\rangle &amp;lt;/math&amp;gt; and average magnetisation &amp;lt;math&amp;gt; \left\langle M\right\rangle &amp;lt;/math&amp;gt; of Ising lattices at equilibrium, the following parameters were used:&lt;br /&gt;
&lt;br /&gt;
* Temperature Range: &amp;lt;math&amp;gt;  0.5 - 5 &amp;lt;/math&amp;gt; reduced units&lt;br /&gt;
* Temperature Interval: &amp;lt;math&amp;gt;0.01&amp;lt;/math&amp;gt; reduced units (&amp;lt;math&amp;gt;450&amp;lt;/math&amp;gt; temperature values)&lt;br /&gt;
* Number of MMC Steps per Temperature value: &amp;lt;math&amp;gt; 2 \times 10^5 &amp;lt;/math&amp;gt; with the aforementioned value of &amp;lt;math&amp;gt; N_{d} = 1.85 \times 10^5 &amp;lt;/math&amp;gt; Monte Carlo steps&lt;br /&gt;
* Lattice Sizes:  &amp;lt;math&amp;gt; 2 \times 2 &amp;lt;/math&amp;gt;, &amp;lt;math&amp;gt; 4 \times 4 &amp;lt;/math&amp;gt; , &amp;lt;math&amp;gt; 8 \times 8 &amp;lt;/math&amp;gt; , &amp;lt;math&amp;gt; 16 \times 16 &amp;lt;/math&amp;gt; , &amp;lt;math&amp;gt; 32 \times 32 &amp;lt;/math&amp;gt; , &amp;lt;math&amp;gt; 64 \times 64 &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Plots of  &amp;lt;math&amp;gt; \left\langle E\right\rangle &amp;lt;/math&amp;gt; and  &amp;lt;math&amp;gt; \left\langle M\right\rangle &amp;lt;/math&amp;gt; per spin as versus temperature are presented below for each lattice size. Errorbars have been implemented to demonstrate how &#039;&#039;well-behaved&#039;&#039; lattice systems of each size are at each temperature, that is, how temperature and lattice size affect the size of the variations in the expected values. For the error calculations, the standard errors, &amp;lt;math&amp;gt; \sigma_\bar{X} &amp;lt;/math&amp;gt;,  in &amp;lt;math&amp;gt; \left\langle E\right\rangle &amp;lt;/math&amp;gt; and  &amp;lt;math&amp;gt; \left\langle M\right\rangle &amp;lt;/math&amp;gt; per spin have been used:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====8x8====&lt;br /&gt;
&lt;br /&gt;
[[File:8x8e+error.png]] [[File:8x8m+error.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
A Python script has been written to generate a plot of &amp;lt;math&amp;gt;\left\langle E\right\rangle&amp;lt;/math&amp;gt; or &amp;lt;math&amp;gt;\left\langle M\right\rangle&amp;lt;/math&amp;gt; against temperature based upon user input. A screenshot of this code has been inserted below.&lt;br /&gt;
&lt;br /&gt;
[[File:ExpectedvsTemp.PNG|200px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=The Effect of System Size=&lt;br /&gt;
&lt;br /&gt;
==Scaling the System Size==&lt;br /&gt;
&lt;br /&gt;
===More Lattice Sizes===&lt;br /&gt;
&lt;br /&gt;
====2x2====&lt;br /&gt;
[[File:2x2e+error.png]] [[File:2x2m+error.png]]&lt;br /&gt;
&lt;br /&gt;
====4x4====&lt;br /&gt;
[[File:4x4e+error.png]] [[File:4x4m+error.png]]&lt;br /&gt;
&lt;br /&gt;
====16x16====&lt;br /&gt;
[[File:16x16e+error.png]] [[File:16x16m+error.png]]&lt;br /&gt;
&lt;br /&gt;
====32x32====&lt;br /&gt;
[[File:32x32e+error.png]] [[File:32x32m+error.png]]&lt;br /&gt;
&lt;br /&gt;
====64x64====&lt;br /&gt;
[[File:64x64e+error.png]] [[File:64x64m+error.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Scrutiny of the plots of average energy per spin for each lattice size reveals an increase in the errorbar width with increasing lattice size. This is most notable in the low temperature region of the plots. Between the &amp;lt;math&amp;gt; 8\times8 &amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt; 16\times16 &amp;lt;/math&amp;gt; lattices, the long range fluctuations become suddenly prominent. The &amp;lt;math&amp;gt;16\times16&amp;lt;/math&amp;gt; lattice is the first (in the range of sizes tested)to clearly capture these fluctuations.&lt;br /&gt;
&lt;br /&gt;
=Determining the Heat Capacity=&lt;br /&gt;
&lt;br /&gt;
==Calculating the Heat Capacity==&lt;br /&gt;
&lt;br /&gt;
===Heat Capacity Derivation===&lt;br /&gt;
Working in the canonical ensemble (constant volume), the heat capacity &amp;lt;math&amp;gt; C_V &amp;lt;/math&amp;gt; is given by:&lt;br /&gt;
&lt;br /&gt;
:&amp;lt;math&amp;gt;C_V = \frac{\partial \left\langle E\right\rangle}{\partial T}_V&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
where &amp;lt;math&amp;gt;\left\langle E\right\rangle&amp;lt;/math&amp;gt; is the average total energy or expected value of the internal energy of the system.&lt;br /&gt;
&lt;br /&gt;
: &amp;lt;math&amp;gt; \left\langle E\right\rangle = - \frac{\partial ln Q}{\partial \beta} = -\frac{1}{Q}\frac{\partial Q}{\partial \beta} &amp;lt;/math&amp;gt;&lt;br /&gt;
where &amp;lt;math&amp;gt; Q&amp;lt;/math&amp;gt; is the partition function for the system of N interacting spins.&lt;br /&gt;
&lt;br /&gt;
By evaluating the second form of the partial derivative with respect to &amp;lt;math&amp;gt; \beta&amp;lt;/math&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \left\langle E\right\rangle = -\frac{1}{Q}\frac{\partial Q}{\partial \beta} = \frac{\Sigma \epsilon_{i} e^{-\beta \epsilon_{i}}}{\Sigma e^{-\beta \epsilon_{i}}} &amp;lt;/math&amp;gt; &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Applying the product rule enables the differentiation of this expression for &amp;lt;math&amp;gt;\left\langle E\right\rangle&amp;lt;/math&amp;gt; with respect to temperature, giving:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\frac{\partial \left\langle E\right\rangle}{\partial T} = \frac{\Sigma \epsilon_{i} \frac{\epsilon_i}{k_BT^2}e^{-\beta \epsilon_{i}}}{\Sigma e^{-\beta \epsilon_{i}}} - \frac{\Sigma \epsilon_i e^{-\beta \epsilon_i}\cdot \frac{\epsilon_i}{k_BT^2}e^{-\beta \epsilon_i}}{(\Sigma e^{-\beta \epsilon_{i}})^2}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\frac{\partial \left\langle E\right\rangle}{\partial T}  = \frac{1}{k_BT^2}\left[\frac{\Sigma \epsilon_i^2 e^{-\beta \epsilon_i}}{\Sigma e^{-\beta \epsilon_i}} - \left(\frac{\Sigma \epsilon_{i} e^{-\beta \epsilon_{i}}}{\Sigma e^{-\beta \epsilon_{i}}}\right)^2\right] &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\frac{\partial \left\langle E\right\rangle}{\partial T}  = \frac{1}{k_BT^2}\left[\left\langle E^2\right\rangle - \left\langle E\right\rangle^2 \right] &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Thus,&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\frac{\partial \left\langle E\right\rangle}{\partial T} = \frac{Var[E]}{k_BT^2} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Heat Capacity versus Temperature===&lt;br /&gt;
Below, a screenshot of the Python script written to produce plots of &amp;lt;math&amp;gt; C_V &amp;lt;/math&amp;gt; against &amp;lt;math&amp;gt; T &amp;lt;/math&amp;gt;, together with the output images of this script.&lt;br /&gt;
 &lt;br /&gt;
[[File:HeatCapScript.PNG]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====2x2====&lt;br /&gt;
[[File:HC2.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====4x4====&lt;br /&gt;
[[File:HC4.png]]&lt;br /&gt;
&lt;br /&gt;
====8x8====&lt;br /&gt;
[[File:HC8.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====16x16====&lt;br /&gt;
[[File:HC16.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====32x32====&lt;br /&gt;
[[File:HC32.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= Locating the Curie Temperature =&lt;br /&gt;
&lt;br /&gt;
===C++ Data Comparison===&lt;br /&gt;
Below a comparison of the &amp;lt;math&amp;gt; C_V &amp;lt;/math&amp;gt; against &amp;lt;math&amp;gt; T &amp;lt;/math&amp;gt; plot generated for the &amp;lt;math&amp;gt; 2 /times 2&amp;lt;/math&amp;gt; to the corresponding C++ data is offered.&lt;br /&gt;
 &lt;br /&gt;
[[File:CHC2.png]]&lt;br /&gt;
&lt;br /&gt;
The data generated by the ILtemperaturerange.py script is a faithful match to the C++ data. However, this is an exceptional case; the plots for all other lattice sizes were found to be very dissimilar, necessitating polynomial fitting.&lt;br /&gt;
&lt;br /&gt;
==Polyfitting of C++ Data==&lt;br /&gt;
&lt;br /&gt;
===Fitting a Polynomial to the Entire Range===&lt;br /&gt;
The following Python script was written to perform a polynomial fit to the entire range of the graph of &amp;lt;math&amp;gt; C_V &amp;lt;/math&amp;gt; against &amp;lt;math&amp;gt; T &amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:HeatCapPoly.PNG]]&lt;br /&gt;
&lt;br /&gt;
Below, the result of the polyfit to the &amp;lt;math&amp;gt; 2/times2&amp;lt;/math&amp;gt; lattice data is offered (for comparison to the previous, non-fitted example).&lt;br /&gt;
&lt;br /&gt;
[[File:15Polyc2x2.png]]&lt;br /&gt;
&lt;br /&gt;
Polynomials with 5 terms and above were found to match the data in the vicinity of the critical region considerably well. Below 7 terms, the &#039;&#039;tails&#039;&#039; of the plot were matched poorly. In the above example, a polynomial of 15 terms was fit to the data.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Fitting a Polynomial to the Critical Region===&lt;br /&gt;
&lt;br /&gt;
The following Python script was written to perform a polynomial fit to the region of interest (the &#039;&#039;critical&#039;&#039; region) of the plots of &amp;lt;math&amp;gt; C_V &amp;lt;/math&amp;gt; against &amp;lt;math&amp;gt; T &amp;lt;/math&amp;gt; to facilitate the discovery of &amp;lt;math&amp;gt; T_C &amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
[[File:CapPolyCrit.PNG]]&lt;br /&gt;
&lt;br /&gt;
An example of the result returned by the script is offered below for the C++ data for the &amp;lt;math&amp;gt; 16\times16&amp;lt;/math&amp;gt; lattice.&lt;br /&gt;
&lt;br /&gt;
[[File:HHCPC16,2.6-2.1,5.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Finding the Peak C Values for Each Lattice Size===&lt;br /&gt;
Below, a screenshot of the code used to obtain the temperatures at which the maximum values of C occured is presented for each lattice size. The temperatures themselves are also featured on the image.&lt;br /&gt;
&lt;br /&gt;
[[File:Tmaxes.PNG]]&lt;br /&gt;
&lt;br /&gt;
The range of lattice sizes and their associated &amp;lt;math&amp;gt;T_{C} &amp;lt;/math&amp;gt; values were exported to a [[Media:Tmax.txt|text file]], enabling a plot to be created.&lt;br /&gt;
&lt;br /&gt;
[[File:CritTempPlot.png]]&lt;br /&gt;
&lt;br /&gt;
Subsequently, the scipy.optimize.curve_fit function was used to fit &amp;lt;math&amp;gt;T_{C, L} = \frac{A}{L} + T_{C,\infty}&amp;lt;/math&amp;gt; function to the data obtained. This enabled the estimation the constant &amp;lt;math&amp;gt; A &amp;lt;/math&amp;gt; and the value of &amp;lt;math&amp;gt;T_{C} &amp;lt;/math&amp;gt; at &amp;lt;math&amp;gt; \frac{A}{L} = 0&amp;lt;/math&amp;gt;, otherwise &amp;lt;math&amp;gt; T_{C,\infty}&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
[[File:FindingTc.PNG]]&lt;br /&gt;
&lt;br /&gt;
A value of &amp;lt;math&amp;gt; T_{C,\infty} = 2.2799 &amp;lt;/math&amp;gt; was obtained. Comparing this to the [https://en.wikipedia.org/wiki/Square-lattice_Ising_model#Critical_temperature|literature] value of &amp;lt;math&amp;gt;2.269&amp;lt;/math&amp;gt;, reveals an error in the obtained value of only &amp;lt;math&amp;gt; 0.47% &amp;lt;/math&amp;gt;. Surprisingly, the investigation of lattices in the given size range was enough to capture the theoretical behaviour of an infinite lattice. As explained by Frenkel and Smit, the implementation of periodic boundary conditions enables the simulation of an infinite bulk (or infinite adjacent lattices) surrounding the single lattice under scrutiny. The agreement of the experimental and theoretical values for &amp;lt;math&amp;gt; T_{C,\infty} &amp;lt;/math&amp;gt; prove the effectiveness of this idea.&lt;br /&gt;
A likely source of error arises from the polynomial fitting of the data. The peaks in &amp;lt;math&amp;gt; C_V &amp;lt;/math&amp;gt; against &amp;lt;math&amp;gt; T &amp;lt;/math&amp;gt; were far more sharp than the broad peaks of the polynomial functions used to fit them. In several cases, the polynomial peak was a slight, yet discernible overestimate of the true peak. This has resulted in an overestimation of the final &amp;lt;math&amp;gt; T_{C,\infty} &amp;lt;/math&amp;gt; value. Fitting a function with a sharper peak to the critical region could overcome this overestimation and provide a more faithful final value.&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
* Frenkel, Daan, et al. Understanding Molecular Simulation : From Algorithms to Applications, Elsevier Science &amp;amp; Technology, 2001&lt;br /&gt;
&lt;br /&gt;
* Krieger, M. Constitutions of matter : Mathematically modeling the most everyday of physical phenomena. Chicago ; London: University of Chicago Press, 1996&lt;br /&gt;
&lt;br /&gt;
* https://en.wikipedia.org/wiki/Square-lattice_Ising_model Accessed 13-11-18&lt;/div&gt;</summary>
		<author><name>Jj1516</name></author>
	</entry>
	<entry>
		<id>https://chemwiki.ch.ic.ac.uk/index.php?title=Rep:JJ1516Ising&amp;diff=736960</id>
		<title>Rep:JJ1516Ising</title>
		<link rel="alternate" type="text/html" href="https://chemwiki.ch.ic.ac.uk/index.php?title=Rep:JJ1516Ising&amp;diff=736960"/>
		<updated>2018-11-21T09:52:22Z</updated>

		<summary type="html">&lt;p&gt;Jj1516: /* Locating the Curie Temperature */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Ex Script Link:&lt;br /&gt;
https://wiki.ch.ic.ac.uk/wiki/index.php?title=Third_year_CMP_compulsory_experiment&lt;br /&gt;
&lt;br /&gt;
= Introduction to the Ising Model =&lt;br /&gt;
&lt;br /&gt;
== The Model ==&lt;br /&gt;
&lt;br /&gt;
=== Minimum Energy State ===&lt;br /&gt;
====Minimum Interaction Energy====&lt;br /&gt;
The interaction energy of an Ising lattice is given by:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;E = -\frac{1}{2}J\displaystyle\sum_{i}^{N} \displaystyle\sum_{j\;\in\;{neighbours}\;(i)} \!\!\!\!\!\!\!\!\!\!\!\!s_{i}s_{j}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In an Ising lattice with D dimensions and periodic boundary conditions, a given spin &amp;lt;math&amp;gt; s_i&amp;lt;/math&amp;gt; has 2D neighbours.&lt;br /&gt;
&lt;br /&gt;
The minimum interaction energy is achieved when all spins in the lattice are aligned (all ↑ or all ↓). As  such, any spin &amp;lt;math&amp;gt; s_i&amp;lt;/math&amp;gt; must be aligned with all 2D of its neighbours. That is, &amp;lt;math&amp;gt;s_{i}s_{j} = 1&amp;lt;/math&amp;gt; for all &amp;lt;math&amp;gt;j&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Therefore, for any &amp;lt;math&amp;gt; s_i&amp;lt;/math&amp;gt;, the sum of its interactions is &amp;lt;math&amp;gt;\displaystyle\sum_{j\;\in\;{neighbours}\;(i)} \!\!\!\!\!\!\!\!\!\!\!\!s_{i}s_{j} = 2D &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
As this is true for all N spins in the lattice, it follows that &amp;lt;math&amp;gt;\displaystyle\sum_{i}^{N} 2D = 2DN&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Thus the minimum interaction energy is given by:&lt;br /&gt;
&lt;br /&gt;
:&amp;lt;math&amp;gt;E_{min} = -\frac{1}{2}J\cdot2DN = - DNJ &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Entropy of the Minimum Energy State====&lt;br /&gt;
&lt;br /&gt;
The entropy of a state is given by:&lt;br /&gt;
&lt;br /&gt;
:&amp;lt;math&amp;gt;S = k\; ln\; \Omega &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Where &amp;lt;math&amp;gt; \Omega &amp;lt;/math&amp;gt; is the multiplicity of the state, the number of degenerate configurations of said state. The minimum energy state is achievable with all spins ↑ or with all spins ↓. In the absence of an external magnetic field, these configurations are degenerate and indistinguishable giving &amp;lt;math&amp;gt; \Omega = 2 &amp;lt;/math&amp;gt; for this state. Therefore,&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; S_{E_{min}}  = k_{B}\; ln\; 2 = 0.693k_{B} = 9.57 \times 10^{-24} J\!\cdot\!\! K^{-1}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Phase Transitions ==&lt;br /&gt;
&lt;br /&gt;
=== Changes to Minimum Energy Configuration ===&lt;br /&gt;
&lt;br /&gt;
====Energy Change ====&lt;br /&gt;
The energy change &amp;lt;math&amp;gt; \Delta E&amp;lt;/math&amp;gt; associated with a single spin &#039;flip&#039; from the lowest energy onfiguration may be calculated by considering the change in the interaction energy with the spin&#039;s neighbours.&lt;br /&gt;
&lt;br /&gt;
Let &amp;lt;math&amp;gt; D = 3, N = 1000 &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\Delta{E} = E_1 - E_0&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;E_1&amp;lt;/math&amp;gt; Interaction energy after one spin has been &#039;flipped&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;E_0&amp;lt;/math&amp;gt; Lowest energy configuration&lt;br /&gt;
&lt;br /&gt;
[[Image:Task 2 table.PNG]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\displaystyle\sum_{interactions} = -2D + 2D(2D-2) + 2D[N-(2D+1)] &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; = 2DN - 8D &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;E_1 = \displaystyle-\frac{1}{2}J\;\sum_{interactions} = 4DJ - DNJ&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\Delta{E} = E_1 - E_0 = 4DJ - DNJ + DNJ = +4DJ = +12J&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This energy change is independent of &amp;lt;math&amp;gt; N&amp;lt;/math&amp;gt; and depends only on the dimension size and the coupling constant &amp;lt;math&amp;gt; J &amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
In this calculation, the following assumption has been made.&lt;br /&gt;
&lt;br /&gt;
* The lattice dimensions are infinite relative to the size of each cell&lt;br /&gt;
&lt;br /&gt;
This allows &#039;&#039;&#039;any&#039;&#039;&#039; cell to be treated as the centre of the lattice. As every cell interacts with 2D neighbours, flipping any cell in the minimum energy configuration results in the same energy change. Alternatively, the periodic boundary conditions of the Ising model remove the necessity for such an assumption. As a consequence, the absence of &amp;lt;math&amp;gt; N &amp;lt;/math&amp;gt; from the resulting energy change is justified.&lt;br /&gt;
&lt;br /&gt;
====Entropy Change====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; S = k_{B}\; ln\; \Omega &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\Omega = \displaystyle\frac{N!}{{N_{\uparrow}!}{N_{\downarrow}!}}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Where &amp;lt;math&amp;gt;N_{x}!&amp;lt;/math&amp;gt; denotes the factorial of the number of spins in spin state &amp;lt;math&amp;gt;x&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\Delta{S} = k_{B}\;ln\;\left(\displaystyle\frac{\Omega_{2}}{\Omega_{1}}\right)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\Omega_{2} = \frac{1000!}{999!1!} = 1000&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \Omega_{1} = \frac{1000!}{1000!} = 1&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\Delta{S} = k_{B}\;ln\;1000 = 9.54 \times 10^{-23} JK^{-1}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\Delta{S_{mol}} = N_{A}k_{B}\;ln\;1000 = 57.4 \,JK^{-1}mol^{-1}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Magnetisation Values of 1D and 2D Lattices===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;M = \sum_i s_i&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====1D Lattice Magnetisation====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;M_{1D} =\;\;+1&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====2D Lattice Magnetisation====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;M_{2D} =\;\;+1&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Magnetisation at 0K====&lt;br /&gt;
&lt;br /&gt;
At 0K, no thermal energy is available to overcome the energetic barriers to spin flipping. Considering the Hemholtz free energy:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; A = E - TS &amp;lt;/math&amp;gt; &lt;br /&gt;
&lt;br /&gt;
A temperature of 0K nullifies the entropic contribution to the free energy. Thus the energetic driving force (which maximises parallel spin interactions) dominates the entropic driving force (which maximises multiplicity of lattice states). For an Ising Lattice with D =  3, N = 1000 at 0K, the alignment of all spins results in the minimum energy configuration  and an overall magnetisation of &amp;lt;math&amp;gt; M = \pm 1000 &amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
= Calculating the Energy and Magnetisation =&lt;br /&gt;
==Modifying the Files==&lt;br /&gt;
&lt;br /&gt;
===Energy and Magnetisation Functions===&lt;br /&gt;
&lt;br /&gt;
====Energy===&lt;br /&gt;
[[File:First_Ene_Method.PNG]]&lt;br /&gt;
&lt;br /&gt;
The above energy method segments a given lattice into lattice cells on the edges, corners or in the bulk of the lattice and calculates the energy interactions with its neighbours as appropriate.&lt;br /&gt;
&lt;br /&gt;
====Magnetisation====&lt;br /&gt;
[[File:First_Mag_Method.PNG]]&lt;br /&gt;
&lt;br /&gt;
The magnetisation method loops over all elements in the array representing the Ising lattice and adds the value of the spin to the magnetisation variable.&lt;br /&gt;
&lt;br /&gt;
==Testing the Files==&lt;br /&gt;
&lt;br /&gt;
===ILCheck.py===&lt;br /&gt;
&lt;br /&gt;
[[File:ILChecks.PNG]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Above, the results of the ILcheck.py script are presented.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= Introduction to the Monte Carlo Simulation =&lt;br /&gt;
==Average Energy and Magnetisation==&lt;br /&gt;
===Configurations of a 100 Spin System===&lt;br /&gt;
For a system of two spins, 4 configurations are possible (↑↑, ↓↓, ↑↓, ↓↑) i.e. &amp;lt;math&amp;gt;2^{2}&amp;lt;/math&amp;gt;. For a system of 100 spins, there are &amp;lt;math&amp;gt;2^{100}&amp;lt;/math&amp;gt; configurations. In the first example, the ↑↑ and ↓↓ are degenerate, as are the ↑↓ and ↓↑ configurations. Therefore, dividing the number of possible configurations by the multiplicity of each configuration (&amp;lt;math&amp;gt;2&amp;lt;/math&amp;gt;) gives the number of non-degenerate configurations. As previously stated, degenerate configurations are indistinguishable in the absence of an external magnetic field.&lt;br /&gt;
&lt;br /&gt;
For 100 spins, this gives &amp;lt;math&amp;gt;\displaystyle\frac{2^{100}}{2} = 6.338 \times 10^{29} &amp;lt;/math&amp;gt; distinguishable configurations.&lt;br /&gt;
&lt;br /&gt;
If processing speed permits &amp;lt;math&amp;gt; 1 \times 10^{9}&amp;lt;/math&amp;gt; calculations each second, the evaluation of a single value of &amp;lt;math&amp;gt;\left\langle M\right\rangle_T&amp;lt;/math&amp;gt; would last &amp;lt;math&amp;gt; 6.338 \times 10^{20} &amp;lt;/math&amp;gt; seconds or &amp;lt;math&amp;gt; 1458 &amp;lt;/math&amp;gt; times the age of the Universe!&lt;br /&gt;
&lt;br /&gt;
==Modifying IsingLattice.py==&lt;br /&gt;
&lt;br /&gt;
===Monte Carlo and Statistics Methods===&lt;br /&gt;
[[File:Monte_Carlo.PNG]]&lt;br /&gt;
&lt;br /&gt;
[[File:stats.PNG]]&lt;br /&gt;
&lt;br /&gt;
The Metropolis Monte Carlo (MMC) algorithm provides a computationally inexpensive path from random initial states to the minimum free energy states of the Ising lattices generated. First, a random 2D Ising lattice is generated. A single random spin within this lattice is &amp;quot;flipped&amp;quot; and the resulting (internal) energy change between these states is measured. Recalling the relationship between the Hemholtz free energy, internal energy and entropy, it follows that a decrease in internal energy also lowers the free energy of the system: thus the configuration change is accepted.&lt;br /&gt;
&lt;br /&gt;
In the case that the spin &amp;quot;flip&amp;quot; does not lower the internal energy, the MMC algorithm tests this configuration change against the Boltzman factor. In the canonical (NVT) ensemble, the free energy of the system is given by:&lt;br /&gt;
&lt;br /&gt;
:&amp;lt;math&amp;gt;A = -k_{B}T\,lnZ_{NVT} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
where Z is the canonical partition function which depends upon &amp;lt;math&amp;gt; e^{-\frac{\Delta E}{k_BT}} &amp;lt;/math&amp;gt;, the Boltzman factor. By choosing a random value in the interval [0,1)from a continuous uniformm probability distribution and rejecting any value of the Boltzman factor less than this value, ###&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Spontaneous Magnetisation===&lt;br /&gt;
&lt;br /&gt;
Below the Curie Temperature, &amp;lt;math&amp;gt; T_{C} &amp;lt;/math&amp;gt;, the energetic driving force dominates the entropic driving force, resulting in a highly ordered system and an overall magnetisation. The spins of the system align in order to maximise favourable coupling interactions rather than adopting a less ordered configuration of higher multiplicity. Therefore, when &amp;lt;math&amp;gt;T &amp;lt; T_C&amp;lt;/math&amp;gt;, the most probable configurations have an overall magnetisation resulting in &amp;lt;math&amp;gt;\left\langle M\right\rangle \neq 0&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
The plots of magnetisation per spin and energy per spin obtained from ILanim.py support this prediction. Below, the plots show that upon equilibration, the system adopts the minimum energy per spin: &amp;lt;math&amp;gt;E_{min_{spin}} = \frac{-NDJ}{N} = -DJ = -2&amp;lt;/math&amp;gt; and exhibits the maximum magnitude of magnetisation per spin: &amp;lt;math&amp;gt;|M_{spin}| = 1&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:2T=1.0.png]]&lt;br /&gt;
[[File:T=1.0.png]]&lt;br /&gt;
[[File:3T=1.0.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
An unknown system error prevented the statistics() function from printing the average values.&lt;br /&gt;
&lt;br /&gt;
=Accelerating the Code=&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Initial Method Speeds===&lt;br /&gt;
Taking 10 repeat measurements for the time taken to perform 2000 Monte Carlo steps resulted in&lt;br /&gt;
&lt;br /&gt;
* An average time of  &amp;lt;math&amp;gt;11.7s&amp;lt;/math&amp;gt; &lt;br /&gt;
* A standard error of &amp;lt;math&amp;gt;0.020s&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Updating Measurement===&lt;br /&gt;
&lt;br /&gt;
NOTE: ILtimetrial.py has been modified to:&lt;br /&gt;
* Perform a requested number of &#039;2000 Monte Carlo Step&#039; measurements&lt;br /&gt;
* Record these measurements in a CSV file&lt;br /&gt;
* Return the mean measuremd time and the Standard Error i.e.   &amp;lt;math&amp;gt; \frac{\sigma}{n} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:TimeTrialMethod.PNG]]&lt;br /&gt;
&lt;br /&gt;
===Updating Energy and Magnetisation Methods===&lt;br /&gt;
[[File:New_Mag_Method.PNG]]&lt;br /&gt;
[[File:New_Ene_Method.PNG]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Updated Method Speeds===&lt;br /&gt;
[[File:TimeTrial.PNG]]&lt;br /&gt;
&lt;br /&gt;
Taking 30 measurements of the time taken to perform 2000 Monte Carlo Steps resulted in:&lt;br /&gt;
&lt;br /&gt;
* An average time of &amp;lt;math&amp;gt;\displaystyle{0.87s}&amp;lt;/math&amp;gt;&lt;br /&gt;
* A standard error of &amp;lt;math&amp;gt;2.5 \times 10^{-3}s&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This represents a 93% decrease in the average computation time from the initial methods.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=The Effect of Temperature=&lt;br /&gt;
&lt;br /&gt;
==Correcting the Averaging  Code==&lt;br /&gt;
&lt;br /&gt;
===Finding a Delay Value===&lt;br /&gt;
To quickly find a value for &amp;lt;math&amp;gt; N_{d}&amp;lt;/math&amp;gt;, the minimum number of cycles typically needed for the equilibration of a system of within the lattice and temperature ranges of interest, it was assumed that:&lt;br /&gt;
&lt;br /&gt;
* Larger lattices would require more Monte Carlo steps to reach equilibrium from their initial, random configurations&lt;br /&gt;
&lt;br /&gt;
* Lattices at lower temperatures would require more Monte Carlo steps to reach equilibrium from their initial, random configurations.&lt;br /&gt;
&lt;br /&gt;
Therefore, an initial value for &amp;lt;math&amp;gt; N_{d}&amp;lt;/math&amp;gt; was found for a &amp;lt;math&amp;gt; 128\times128 &amp;lt;/math&amp;gt; lattice at a temperature of &amp;lt;math&amp;gt;0.5&amp;lt;/math&amp;gt; reduced temperature units.&lt;br /&gt;
*&amp;lt;math&amp;gt; N_{d} = 185000 &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
By this number of steps, all smaller lattices at all higher temperatures were found to have equilibrated also. Thus, this value of&amp;lt;math&amp;gt; N_{d}&amp;lt;/math&amp;gt; was accepted as an appropriate delay.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:AFinFrame 128 3e5 T= 0.5line.png|400px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
For the 128x128 lattices at T=0.5, equilibration was ensured from 185000 steps onwards.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Smaller lattices at the same temperature did indeed equilibrate more slowly, but all equilibrated within &amp;lt;math&amp;gt; N_{d}&amp;lt;/math&amp;gt; MC steps.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:AFinFrame 64 3e5 T= 0.5line.png|400px]]&lt;br /&gt;
[[File:AFinFrame 32 3e5 T= 0.5line2.png|400px]]&lt;br /&gt;
[[File:AFinFrame 16 3e5 T= 0.5line2.png|400px]]&lt;br /&gt;
[[File:AFinFrame 8 3e5 T= 0.5line.png|400px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The figure below shows the modifications made to IsingLattice.py to incorporate the &amp;lt;math&amp;gt; N_{d} &amp;lt;/math&amp;gt; step delay.&lt;br /&gt;
&lt;br /&gt;
==Running over a Range of Temperatures==&lt;br /&gt;
&lt;br /&gt;
To examine the effect of temperature on the average energy &amp;lt;math&amp;gt; \left\langle E\right\rangle &amp;lt;/math&amp;gt; and average magnetisation &amp;lt;math&amp;gt; \left\langle M\right\rangle &amp;lt;/math&amp;gt; of Ising lattices at equilibrium, the following parameters were used:&lt;br /&gt;
&lt;br /&gt;
* Temperature Range: &amp;lt;math&amp;gt;  0.5 - 5 &amp;lt;/math&amp;gt; reduced units&lt;br /&gt;
* Temperature Interval: &amp;lt;math&amp;gt;0.01&amp;lt;/math&amp;gt; reduced units (&amp;lt;math&amp;gt;450&amp;lt;/math&amp;gt; temperature values)&lt;br /&gt;
* Number of MMC Steps per Temperature value: &amp;lt;math&amp;gt; 2 \times 10^5 &amp;lt;/math&amp;gt; with the aforementioned value of &amp;lt;math&amp;gt; N_{d} = 1.85 \times 10^5 &amp;lt;/math&amp;gt; Monte Carlo steps&lt;br /&gt;
* Lattice Sizes:  &amp;lt;math&amp;gt; 2 \times 2 &amp;lt;/math&amp;gt;, &amp;lt;math&amp;gt; 4 \times 4 &amp;lt;/math&amp;gt; , &amp;lt;math&amp;gt; 8 \times 8 &amp;lt;/math&amp;gt; , &amp;lt;math&amp;gt; 16 \times 16 &amp;lt;/math&amp;gt; , &amp;lt;math&amp;gt; 32 \times 32 &amp;lt;/math&amp;gt; , &amp;lt;math&amp;gt; 64 \times 64 &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Plots of  &amp;lt;math&amp;gt; \left\langle E\right\rangle &amp;lt;/math&amp;gt; and  &amp;lt;math&amp;gt; \left\langle M\right\rangle &amp;lt;/math&amp;gt; per spin as versus temperature are presented below for each lattice size. Errorbars have been implemented to demonstrate how &#039;&#039;well-behaved&#039;&#039; lattice systems of each size are at each temperature, that is, how temperature and lattice size affect the size of the variations in the expected values. For the error calculations, the standard errors, &amp;lt;math&amp;gt; \sigma_\bar{X} &amp;lt;/math&amp;gt;,  in &amp;lt;math&amp;gt; \left\langle E\right\rangle &amp;lt;/math&amp;gt; and  &amp;lt;math&amp;gt; \left\langle M\right\rangle &amp;lt;/math&amp;gt; per spin have been used:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====8x8====&lt;br /&gt;
&lt;br /&gt;
[[File:8x8e+error.png]] [[File:8x8m+error.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
A Python script has been written to generate a plot of &amp;lt;math&amp;gt;\left\langle E\right\rangle&amp;lt;/math&amp;gt; or &amp;lt;math&amp;gt;\left\langle M\right\rangle&amp;lt;/math&amp;gt; against temperature based upon user input. A screenshot of this code has been inserted below.&lt;br /&gt;
&lt;br /&gt;
[[File:ExpectedvsTemp.PNG|200px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=The Effect of System Size=&lt;br /&gt;
&lt;br /&gt;
==Scaling the System Size==&lt;br /&gt;
&lt;br /&gt;
===More Lattice Sizes===&lt;br /&gt;
&lt;br /&gt;
====2x2====&lt;br /&gt;
[[File:2x2e+error.png]] [[File:2x2m+error.png]]&lt;br /&gt;
&lt;br /&gt;
====4x4====&lt;br /&gt;
[[File:4x4e+error.png]] [[File:4x4m+error.png]]&lt;br /&gt;
&lt;br /&gt;
====16x16====&lt;br /&gt;
[[File:16x16e+error.png]] [[File:16x16m+error.png]]&lt;br /&gt;
&lt;br /&gt;
====32x32====&lt;br /&gt;
[[File:32x32e+error.png]] [[File:32x32m+error.png]]&lt;br /&gt;
&lt;br /&gt;
====64x64====&lt;br /&gt;
[[File:64x64e+error.png]] [[File:64x64m+error.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Scrutiny of the plots of average energy per spin for each lattice size reveals an increase in the errorbar width with increasing lattice size. This is most notable in the low temperature region of the plots. Between the &amp;lt;math&amp;gt; 8\times8 &amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt; 16\times16 &amp;lt;/math&amp;gt; lattices, the long range fluctuations become suddenly prominent. The &amp;lt;math&amp;gt;16\times16&amp;lt;/math&amp;gt; lattice is the first (in the range of sizes tested)to clearly capture these fluctuations.&lt;br /&gt;
&lt;br /&gt;
=Determining the Heat Capacity=&lt;br /&gt;
&lt;br /&gt;
==Calculating the Heat Capacity==&lt;br /&gt;
&lt;br /&gt;
===Heat Capacity Derivation===&lt;br /&gt;
Working in the canonical ensemble (constant volume), the heat capacity &amp;lt;math&amp;gt; C_V &amp;lt;/math&amp;gt; is given by:&lt;br /&gt;
&lt;br /&gt;
:&amp;lt;math&amp;gt;C_V = \frac{\partial \left\langle E\right\rangle}{\partial T}_V&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
where &amp;lt;math&amp;gt;\left\langle E\right\rangle&amp;lt;/math&amp;gt; is the average total energy or expected value of the internal energy of the system.&lt;br /&gt;
&lt;br /&gt;
: &amp;lt;math&amp;gt; \left\langle E\right\rangle = - \frac{\partial ln Q}{\partial \beta} = -\frac{1}{Q}\frac{\partial Q}{\partial \beta} &amp;lt;/math&amp;gt;&lt;br /&gt;
where &amp;lt;math&amp;gt; Q&amp;lt;/math&amp;gt; is the partition function for the system of N interacting spins.&lt;br /&gt;
&lt;br /&gt;
By evaluating the second form of the partial derivative with respect to &amp;lt;math&amp;gt; \beta&amp;lt;/math&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \left\langle E\right\rangle = -\frac{1}{Q}\frac{\partial Q}{\partial \beta} = \frac{\Sigma \epsilon_{i} e^{-\beta \epsilon_{i}}}{\Sigma e^{-\beta \epsilon_{i}}} &amp;lt;/math&amp;gt; &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Applying the product rule enables the differentiation of this expression for &amp;lt;math&amp;gt;\left\langle E\right\rangle&amp;lt;/math&amp;gt; with respect to temperature, giving:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\frac{\partial \left\langle E\right\rangle}{\partial T} = \frac{\Sigma \epsilon_{i} \frac{\epsilon_i}{k_BT^2}e^{-\beta \epsilon_{i}}}{\Sigma e^{-\beta \epsilon_{i}}} - \frac{\Sigma \epsilon_i e^{-\beta \epsilon_i}\cdot \frac{\epsilon_i}{k_BT^2}e^{-\beta \epsilon_i}}{(\Sigma e^{-\beta \epsilon_{i}})^2}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\frac{\partial \left\langle E\right\rangle}{\partial T}  = \frac{1}{k_BT^2}\left[\frac{\Sigma \epsilon_i^2 e^{-\beta \epsilon_i}}{\Sigma e^{-\beta \epsilon_i}} - \left(\frac{\Sigma \epsilon_{i} e^{-\beta \epsilon_{i}}}{\Sigma e^{-\beta \epsilon_{i}}}\right)^2\right] &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\frac{\partial \left\langle E\right\rangle}{\partial T}  = \frac{1}{k_BT^2}\left[\left\langle E^2\right\rangle - \left\langle E\right\rangle^2 \right] &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Thus,&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\frac{\partial \left\langle E\right\rangle}{\partial T} = \frac{Var[E]}{k_BT^2} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Heat Capacity versus Temperature===&lt;br /&gt;
Below, a screenshot of the Python script written to produce plots of &amp;lt;math&amp;gt; C_V &amp;lt;/math&amp;gt; against &amp;lt;math&amp;gt; T &amp;lt;/math&amp;gt;, together with the output images of this script.&lt;br /&gt;
 &lt;br /&gt;
[[File:HeatCapScript.PNG]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====2x2====&lt;br /&gt;
[[File:HC2.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====4x4====&lt;br /&gt;
[[File:HC4.png]]&lt;br /&gt;
&lt;br /&gt;
====8x8====&lt;br /&gt;
[[File:HC8.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====16x16====&lt;br /&gt;
[[File:HC16.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====32x32====&lt;br /&gt;
[[File:HC32.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= Locating the Curie Temperature =&lt;br /&gt;
&lt;br /&gt;
===C++ Data Comparison===&lt;br /&gt;
Below a comparison of the &amp;lt;math&amp;gt; C_V &amp;lt;/math&amp;gt; against &amp;lt;math&amp;gt; T &amp;lt;/math&amp;gt; plot generated for the &amp;lt;math&amp;gt; 2 /times 2&amp;lt;/math&amp;gt; to the corresponding C++ data is offered.&lt;br /&gt;
 &lt;br /&gt;
[[File:CHC2.png]]&lt;br /&gt;
&lt;br /&gt;
The data generated by the ILtemperaturerange.py script is a faithful match to the C++ data. However, this is an exceptional case; the plots for all other lattice sizes were found to be very dissimilar, necessitating polynomial fitting.&lt;br /&gt;
&lt;br /&gt;
==Polyfitting of C++ Data==&lt;br /&gt;
&lt;br /&gt;
===Fitting a Polynomial to the Entire Range===&lt;br /&gt;
The following Python script was written to perform a polynomial fit to the entire range of the graph of &amp;lt;math&amp;gt; C_V &amp;lt;/math&amp;gt; against &amp;lt;math&amp;gt; T &amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:HeatCapPoly.PNG]]&lt;br /&gt;
&lt;br /&gt;
Below, the result of the polyfit to the &amp;lt;math&amp;gt; 2/times2&amp;lt;/math&amp;gt; lattice data is offered (for comparison to the previous, non-fitted example).&lt;br /&gt;
&lt;br /&gt;
[[File:15Polyc2x2.png]]&lt;br /&gt;
&lt;br /&gt;
Polynomials with 5 terms and above were found to match the data in the vicinity of the critical region considerably well. Below 7 terms, the &#039;&#039;tails&#039;&#039; of the plot were matched poorly. In the above example, a polynomial of 15 terms was fit to the data.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Fitting a Polynomial to the Critical Region===&lt;br /&gt;
&lt;br /&gt;
The following Python script was written to perform a polynomial fit to the region of interest (the &#039;&#039;critical&#039;&#039; region) of the plots of &amp;lt;math&amp;gt; C_V &amp;lt;/math&amp;gt; against &amp;lt;math&amp;gt; T &amp;lt;/math&amp;gt; to facilitate the discovery of &amp;lt;math&amp;gt; T_C &amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
[[File:CapPolyCrit.PNG]]&lt;br /&gt;
&lt;br /&gt;
An example of the result returned by the script is offered below for the C++ data for the &amp;lt;math&amp;gt; 16\times16&amp;lt;/math&amp;gt; lattice.&lt;br /&gt;
&lt;br /&gt;
[[File:HHCPC16,2.6-2.1,5.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Finding the Peak C Values for Each Lattice Size===&lt;br /&gt;
Below, a screenshot of the code used to obtain the temperatures at which the maximum values of C occured is presented for each lattice size. The temperatures themselves are also featured on the image.&lt;br /&gt;
&lt;br /&gt;
[[File:Tmaxes.PNG]]&lt;br /&gt;
&lt;br /&gt;
The range of lattice sizes and their associated &amp;lt;math&amp;gt;T_{C} &amp;lt;/math&amp;gt; values were exported to a [[Media:Tmax.txt|text file]], enabling a plot to be created.&lt;br /&gt;
&lt;br /&gt;
[[CritTempPlot.png]]&lt;br /&gt;
&lt;br /&gt;
Subsequently, the scipy.optimize.curve_fit function was used to fit &amp;lt;math&amp;gt;T_{C, L} = \frac{A}{L} + T_{C,\infty}&amp;lt;/math&amp;gt; function to the data obtained. This enabled the estimation the constant &amp;lt;math&amp;gt; A &amp;lt;/math&amp;gt; and the value of &amp;lt;math&amp;gt;T_{C} &amp;lt;/math&amp;gt; at &amp;lt;math&amp;gt; \frac{A}{L} = 0&amp;lt;/math&amp;gt;, otherwise &amp;lt;math&amp;gt; T_{C,\infty}&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
[[FindingTc.PNG]]&lt;br /&gt;
&lt;br /&gt;
A value of &amp;lt;math&amp;gt; T_{C,\infty} = 2.2799 &amp;lt;/math&amp;gt; was obtained. Comparing this to the [https://en.wikipedia.org/wiki/Square-lattice_Ising_model#Critical_temperature|literature] value of &amp;lt;math&amp;gt;2.269&amp;lt;/math&amp;gt;, reveals an error in the obtained value of only &amp;lt;math&amp;gt; 0.47% &amp;lt;/math&amp;gt;. Surprisingly, the investigation of lattices in the given size range was enough to capture the theoretical behaviour of an infinite lattice. As explained by Frenkel and Smit, the implementation of periodic boundary conditions enables the simulation of an infinite bulk (or infinite adjacent lattices) surrounding the single lattice under scrutiny. The agreement of the experimental and theoretical values for &amp;lt;math&amp;gt; T_{C,\infty} &amp;lt;/math&amp;gt; prove the effectiveness of this idea.&lt;br /&gt;
A likely source of error arises from the polynomial fitting of the data. The peaks in &amp;lt;math&amp;gt; C_V &amp;lt;/math&amp;gt; against &amp;lt;math&amp;gt; T &amp;lt;/math&amp;gt; were far more sharp than the broad peaks of the polynomial functions used to fit them. In several cases, the polynomial peak was a slight, yet discernible overestimate of the true peak. This has resulted in an overestimation of the final &amp;lt;math&amp;gt; T_{C,\infty} &amp;lt;/math&amp;gt; value. Fitting a function with a sharper peak to the critical region could overcome this overestimation and provide a more faithful final value.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
* Frenkel, Daan, et al. Understanding Molecular Simulation : From Algorithms to Applications, Elsevier Science &amp;amp; Technology, 2001&lt;br /&gt;
&lt;br /&gt;
* Krieger, M. Constitutions of matter : Mathematically modeling the most everyday of physical phenomena. Chicago ; London: University of Chicago Press, 1996&lt;br /&gt;
&lt;br /&gt;
* https://en.wikipedia.org/wiki/Square-lattice_Ising_model Accessed 13-11-18&lt;/div&gt;</summary>
		<author><name>Jj1516</name></author>
	</entry>
	<entry>
		<id>https://chemwiki.ch.ic.ac.uk/index.php?title=File:FindingTc.PNG&amp;diff=736923</id>
		<title>File:FindingTc.PNG</title>
		<link rel="alternate" type="text/html" href="https://chemwiki.ch.ic.ac.uk/index.php?title=File:FindingTc.PNG&amp;diff=736923"/>
		<updated>2018-11-21T09:20:45Z</updated>

		<summary type="html">&lt;p&gt;Jj1516: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Jj1516</name></author>
	</entry>
	<entry>
		<id>https://chemwiki.ch.ic.ac.uk/index.php?title=File:CritTempPlot.png&amp;diff=736919</id>
		<title>File:CritTempPlot.png</title>
		<link rel="alternate" type="text/html" href="https://chemwiki.ch.ic.ac.uk/index.php?title=File:CritTempPlot.png&amp;diff=736919"/>
		<updated>2018-11-21T09:16:27Z</updated>

		<summary type="html">&lt;p&gt;Jj1516: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Jj1516</name></author>
	</entry>
	<entry>
		<id>https://chemwiki.ch.ic.ac.uk/index.php?title=File:Tmax.txt&amp;diff=736906</id>
		<title>File:Tmax.txt</title>
		<link rel="alternate" type="text/html" href="https://chemwiki.ch.ic.ac.uk/index.php?title=File:Tmax.txt&amp;diff=736906"/>
		<updated>2018-11-21T09:03:36Z</updated>

		<summary type="html">&lt;p&gt;Jj1516: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Jj1516</name></author>
	</entry>
	<entry>
		<id>https://chemwiki.ch.ic.ac.uk/index.php?title=File:Tmaxes.PNG&amp;diff=736893</id>
		<title>File:Tmaxes.PNG</title>
		<link rel="alternate" type="text/html" href="https://chemwiki.ch.ic.ac.uk/index.php?title=File:Tmaxes.PNG&amp;diff=736893"/>
		<updated>2018-11-21T08:55:57Z</updated>

		<summary type="html">&lt;p&gt;Jj1516: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Jj1516</name></author>
	</entry>
	<entry>
		<id>https://chemwiki.ch.ic.ac.uk/index.php?title=Rep:JJ1516Ising&amp;diff=736580</id>
		<title>Rep:JJ1516Ising</title>
		<link rel="alternate" type="text/html" href="https://chemwiki.ch.ic.ac.uk/index.php?title=Rep:JJ1516Ising&amp;diff=736580"/>
		<updated>2018-11-20T22:42:00Z</updated>

		<summary type="html">&lt;p&gt;Jj1516: /* Fitting a Polynomial to the Critical Region */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Ex Script Link:&lt;br /&gt;
https://wiki.ch.ic.ac.uk/wiki/index.php?title=Third_year_CMP_compulsory_experiment&lt;br /&gt;
&lt;br /&gt;
= Introduction to the Ising Model =&lt;br /&gt;
&lt;br /&gt;
== The Model ==&lt;br /&gt;
&lt;br /&gt;
=== Minimum Energy State ===&lt;br /&gt;
====Minimum Interaction Energy====&lt;br /&gt;
The interaction energy of an Ising lattice is given by:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;E = -\frac{1}{2}J\displaystyle\sum_{i}^{N} \displaystyle\sum_{j\;\in\;{neighbours}\;(i)} \!\!\!\!\!\!\!\!\!\!\!\!s_{i}s_{j}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In an Ising lattice with D dimensions and periodic boundary conditions, a given spin &amp;lt;math&amp;gt; s_i&amp;lt;/math&amp;gt; has 2D neighbours.&lt;br /&gt;
&lt;br /&gt;
The minimum interaction energy is achieved when all spins in the lattice are aligned (all ↑ or all ↓). As  such, any spin &amp;lt;math&amp;gt; s_i&amp;lt;/math&amp;gt; must be aligned with all 2D of its neighbours. That is, &amp;lt;math&amp;gt;s_{i}s_{j} = 1&amp;lt;/math&amp;gt; for all &amp;lt;math&amp;gt;j&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Therefore, for any &amp;lt;math&amp;gt; s_i&amp;lt;/math&amp;gt;, the sum of its interactions is &amp;lt;math&amp;gt;\displaystyle\sum_{j\;\in\;{neighbours}\;(i)} \!\!\!\!\!\!\!\!\!\!\!\!s_{i}s_{j} = 2D &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
As this is true for all N spins in the lattice, it follows that &amp;lt;math&amp;gt;\displaystyle\sum_{i}^{N} 2D = 2DN&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Thus the minimum interaction energy is given by:&lt;br /&gt;
&lt;br /&gt;
:&amp;lt;math&amp;gt;E_{min} = -\frac{1}{2}J\cdot2DN = - DNJ &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Entropy of the Minimum Energy State====&lt;br /&gt;
&lt;br /&gt;
The entropy of a state is given by:&lt;br /&gt;
&lt;br /&gt;
:&amp;lt;math&amp;gt;S = k\; ln\; \Omega &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Where &amp;lt;math&amp;gt; \Omega &amp;lt;/math&amp;gt; is the multiplicity of the state, the number of degenerate configurations of said state. The minimum energy state is achievable with all spins ↑ or with all spins ↓. In the absence of an external magnetic field, these configurations are degenerate and indistinguishable giving &amp;lt;math&amp;gt; \Omega = 2 &amp;lt;/math&amp;gt; for this state. Therefore,&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; S_{E_{min}}  = k_{B}\; ln\; 2 = 0.693k_{B} = 9.57 \times 10^{-24} J\!\cdot\!\! K^{-1}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Phase Transitions ==&lt;br /&gt;
&lt;br /&gt;
=== Changes to Minimum Energy Configuration ===&lt;br /&gt;
&lt;br /&gt;
====Energy Change ====&lt;br /&gt;
The energy change &amp;lt;math&amp;gt; \Delta E&amp;lt;/math&amp;gt; associated with a single spin &#039;flip&#039; from the lowest energy onfiguration may be calculated by considering the change in the interaction energy with the spin&#039;s neighbours.&lt;br /&gt;
&lt;br /&gt;
Let &amp;lt;math&amp;gt; D = 3, N = 1000 &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\Delta{E} = E_1 - E_0&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;E_1&amp;lt;/math&amp;gt; Interaction energy after one spin has been &#039;flipped&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;E_0&amp;lt;/math&amp;gt; Lowest energy configuration&lt;br /&gt;
&lt;br /&gt;
[[Image:Task 2 table.PNG]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\displaystyle\sum_{interactions} = -2D + 2D(2D-2) + 2D[N-(2D+1)] &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; = 2DN - 8D &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;E_1 = \displaystyle-\frac{1}{2}J\;\sum_{interactions} = 4DJ - DNJ&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\Delta{E} = E_1 - E_0 = 4DJ - DNJ + DNJ = +4DJ = +12J&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This energy change is independent of &amp;lt;math&amp;gt; N&amp;lt;/math&amp;gt; and depends only on the dimension size and the coupling constant &amp;lt;math&amp;gt; J &amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
In this calculation, the following assumption has been made.&lt;br /&gt;
&lt;br /&gt;
* The lattice dimensions are infinite relative to the size of each cell&lt;br /&gt;
&lt;br /&gt;
This allows &#039;&#039;&#039;any&#039;&#039;&#039; cell to be treated as the centre of the lattice. As every cell interacts with 2D neighbours, flipping any cell in the minimum energy configuration results in the same energy change. Alternatively, the periodic boundary conditions of the Ising model remove the necessity for such an assumption. As a consequence, the absence of &amp;lt;math&amp;gt; N &amp;lt;/math&amp;gt; from the resulting energy change is justified.&lt;br /&gt;
&lt;br /&gt;
====Entropy Change====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; S = k_{B}\; ln\; \Omega &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\Omega = \displaystyle\frac{N!}{{N_{\uparrow}!}{N_{\downarrow}!}}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Where &amp;lt;math&amp;gt;N_{x}!&amp;lt;/math&amp;gt; denotes the factorial of the number of spins in spin state &amp;lt;math&amp;gt;x&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\Delta{S} = k_{B}\;ln\;\left(\displaystyle\frac{\Omega_{2}}{\Omega_{1}}\right)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\Omega_{2} = \frac{1000!}{999!1!} = 1000&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \Omega_{1} = \frac{1000!}{1000!} = 1&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\Delta{S} = k_{B}\;ln\;1000 = 9.54 \times 10^{-23} JK^{-1}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\Delta{S_{mol}} = N_{A}k_{B}\;ln\;1000 = 57.4 \,JK^{-1}mol^{-1}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Magnetisation Values of 1D and 2D Lattices===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;M = \sum_i s_i&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====1D Lattice Magnetisation====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;M_{1D} =\;\;+1&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====2D Lattice Magnetisation====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;M_{2D} =\;\;+1&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Magnetisation at 0K====&lt;br /&gt;
&lt;br /&gt;
At 0K, no thermal energy is available to overcome the energetic barriers to spin flipping. Considering the Hemholtz free energy:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; A = E - TS &amp;lt;/math&amp;gt; &lt;br /&gt;
&lt;br /&gt;
A temperature of 0K nullifies the entropic contribution to the free energy. Thus the energetic driving force (which maximises parallel spin interactions) dominates the entropic driving force (which maximises multiplicity of lattice states). For an Ising Lattice with D =  3, N = 1000 at 0K, the alignment of all spins results in the minimum energy configuration  and an overall magnetisation of &amp;lt;math&amp;gt; M = \pm 1000 &amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
= Calculating the Energy and Magnetisation =&lt;br /&gt;
==Modifying the Files==&lt;br /&gt;
&lt;br /&gt;
===Energy and Magnetisation Functions===&lt;br /&gt;
&lt;br /&gt;
====Energy===&lt;br /&gt;
[[File:First_Ene_Method.PNG]]&lt;br /&gt;
&lt;br /&gt;
The above energy method segments a given lattice into lattice cells on the edges, corners or in the bulk of the lattice and calculates the energy interactions with its neighbours as appropriate.&lt;br /&gt;
&lt;br /&gt;
====Magnetisation====&lt;br /&gt;
[[File:First_Mag_Method.PNG]]&lt;br /&gt;
&lt;br /&gt;
The magnetisation method loops over all elements in the array representing the Ising lattice and adds the value of the spin to the magnetisation variable.&lt;br /&gt;
&lt;br /&gt;
==Testing the Files==&lt;br /&gt;
&lt;br /&gt;
===ILCheck.py===&lt;br /&gt;
&lt;br /&gt;
[[File:ILChecks.PNG]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Above, the results of the ILcheck.py script are presented.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= Introduction to the Monte Carlo Simulation =&lt;br /&gt;
==Average Energy and Magnetisation==&lt;br /&gt;
===Configurations of a 100 Spin System===&lt;br /&gt;
For a system of two spins, 4 configurations are possible (↑↑, ↓↓, ↑↓, ↓↑) i.e. &amp;lt;math&amp;gt;2^{2}&amp;lt;/math&amp;gt;. For a system of 100 spins, there are &amp;lt;math&amp;gt;2^{100}&amp;lt;/math&amp;gt; configurations. In the first example, the ↑↑ and ↓↓ are degenerate, as are the ↑↓ and ↓↑ configurations. Therefore, dividing the number of possible configurations by the multiplicity of each configuration (&amp;lt;math&amp;gt;2&amp;lt;/math&amp;gt;) gives the number of non-degenerate configurations. As previously stated, degenerate configurations are indistinguishable in the absence of an external magnetic field.&lt;br /&gt;
&lt;br /&gt;
For 100 spins, this gives &amp;lt;math&amp;gt;\displaystyle\frac{2^{100}}{2} = 6.338 \times 10^{29} &amp;lt;/math&amp;gt; distinguishable configurations.&lt;br /&gt;
&lt;br /&gt;
If processing speed permits &amp;lt;math&amp;gt; 1 \times 10^{9}&amp;lt;/math&amp;gt; calculations each second, the evaluation of a single value of &amp;lt;math&amp;gt;\left\langle M\right\rangle_T&amp;lt;/math&amp;gt; would last &amp;lt;math&amp;gt; 6.338 \times 10^{20} &amp;lt;/math&amp;gt; seconds or &amp;lt;math&amp;gt; 1458 &amp;lt;/math&amp;gt; times the age of the Universe!&lt;br /&gt;
&lt;br /&gt;
==Modifying IsingLattice.py==&lt;br /&gt;
&lt;br /&gt;
===Monte Carlo and Statistics Methods===&lt;br /&gt;
[[File:Monte_Carlo.PNG]]&lt;br /&gt;
&lt;br /&gt;
[[File:stats.PNG]]&lt;br /&gt;
&lt;br /&gt;
The Metropolis Monte Carlo (MMC) algorithm provides a computationally inexpensive path from random initial states to the minimum free energy states of the Ising lattices generated. First, a random 2D Ising lattice is generated. A single random spin within this lattice is &amp;quot;flipped&amp;quot; and the resulting (internal) energy change between these states is measured. Recalling the relationship between the Hemholtz free energy, internal energy and entropy, it follows that a decrease in internal energy also lowers the free energy of the system: thus the configuration change is accepted.&lt;br /&gt;
&lt;br /&gt;
In the case that the spin &amp;quot;flip&amp;quot; does not lower the internal energy, the MMC algorithm tests this configuration change against the Boltzman factor. In the canonical (NVT) ensemble, the free energy of the system is given by:&lt;br /&gt;
&lt;br /&gt;
:&amp;lt;math&amp;gt;A = -k_{B}T\,lnZ_{NVT} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
where Z is the canonical partition function which depends upon &amp;lt;math&amp;gt; e^{-\frac{\Delta E}{k_BT}} &amp;lt;/math&amp;gt;, the Boltzman factor. By choosing a random value in the interval [0,1)from a continuous uniformm probability distribution and rejecting any value of the Boltzman factor less than this value, ###&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Spontaneous Magnetisation===&lt;br /&gt;
&lt;br /&gt;
Below the Curie Temperature, &amp;lt;math&amp;gt; T_{C} &amp;lt;/math&amp;gt;, the energetic driving force dominates the entropic driving force, resulting in a highly ordered system and an overall magnetisation. The spins of the system align in order to maximise favourable coupling interactions rather than adopting a less ordered configuration of higher multiplicity. Therefore, when &amp;lt;math&amp;gt;T &amp;lt; T_C&amp;lt;/math&amp;gt;, the most probable configurations have an overall magnetisation resulting in &amp;lt;math&amp;gt;\left\langle M\right\rangle \neq 0&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
The plots of magnetisation per spin and energy per spin obtained from ILanim.py support this prediction. Below, the plots show that upon equilibration, the system adopts the minimum energy per spin: &amp;lt;math&amp;gt;E_{min_{spin}} = \frac{-NDJ}{N} = -DJ = -2&amp;lt;/math&amp;gt; and exhibits the maximum magnitude of magnetisation per spin: &amp;lt;math&amp;gt;|M_{spin}| = 1&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:2T=1.0.png]]&lt;br /&gt;
[[File:T=1.0.png]]&lt;br /&gt;
[[File:3T=1.0.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
An unknown system error prevented the statistics() function from printing the average values.&lt;br /&gt;
&lt;br /&gt;
=Accelerating the Code=&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Initial Method Speeds===&lt;br /&gt;
Taking 10 repeat measurements for the time taken to perform 2000 Monte Carlo steps resulted in&lt;br /&gt;
&lt;br /&gt;
* An average time of  &amp;lt;math&amp;gt;11.7s&amp;lt;/math&amp;gt; &lt;br /&gt;
* A standard error of &amp;lt;math&amp;gt;0.020s&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Updating Measurement===&lt;br /&gt;
&lt;br /&gt;
NOTE: ILtimetrial.py has been modified to:&lt;br /&gt;
* Perform a requested number of &#039;2000 Monte Carlo Step&#039; measurements&lt;br /&gt;
* Record these measurements in a CSV file&lt;br /&gt;
* Return the mean measuremd time and the Standard Error i.e.   &amp;lt;math&amp;gt; \frac{\sigma}{n} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:TimeTrialMethod.PNG]]&lt;br /&gt;
&lt;br /&gt;
===Updating Energy and Magnetisation Methods===&lt;br /&gt;
[[File:New_Mag_Method.PNG]]&lt;br /&gt;
[[File:New_Ene_Method.PNG]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Updated Method Speeds===&lt;br /&gt;
[[File:TimeTrial.PNG]]&lt;br /&gt;
&lt;br /&gt;
Taking 30 measurements of the time taken to perform 2000 Monte Carlo Steps resulted in:&lt;br /&gt;
&lt;br /&gt;
* An average time of &amp;lt;math&amp;gt;\displaystyle{0.87s}&amp;lt;/math&amp;gt;&lt;br /&gt;
* A standard error of &amp;lt;math&amp;gt;2.5 \times 10^{-3}s&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This represents a 93% decrease in the average computation time from the initial methods.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=The Effect of Temperature=&lt;br /&gt;
&lt;br /&gt;
==Correcting the Averaging  Code==&lt;br /&gt;
&lt;br /&gt;
===Finding a Delay Value===&lt;br /&gt;
To quickly find a value for &amp;lt;math&amp;gt; N_{d}&amp;lt;/math&amp;gt;, the minimum number of cycles typically needed for the equilibration of a system of within the lattice and temperature ranges of interest, it was assumed that:&lt;br /&gt;
&lt;br /&gt;
* Larger lattices would require more Monte Carlo steps to reach equilibrium from their initial, random configurations&lt;br /&gt;
&lt;br /&gt;
* Lattices at lower temperatures would require more Monte Carlo steps to reach equilibrium from their initial, random configurations.&lt;br /&gt;
&lt;br /&gt;
Therefore, an initial value for &amp;lt;math&amp;gt; N_{d}&amp;lt;/math&amp;gt; was found for a &amp;lt;math&amp;gt; 128\times128 &amp;lt;/math&amp;gt; lattice at a temperature of &amp;lt;math&amp;gt;0.5&amp;lt;/math&amp;gt; reduced temperature units.&lt;br /&gt;
*&amp;lt;math&amp;gt; N_{d} = 185000 &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
By this number of steps, all smaller lattices at all higher temperatures were found to have equilibrated also. Thus, this value of&amp;lt;math&amp;gt; N_{d}&amp;lt;/math&amp;gt; was accepted as an appropriate delay.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:AFinFrame 128 3e5 T= 0.5line.png|400px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
For the 128x128 lattices at T=0.5, equilibration was ensured from 185000 steps onwards.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Smaller lattices at the same temperature did indeed equilibrate more slowly, but all equilibrated within &amp;lt;math&amp;gt; N_{d}&amp;lt;/math&amp;gt; MC steps.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:AFinFrame 64 3e5 T= 0.5line.png|400px]]&lt;br /&gt;
[[File:AFinFrame 32 3e5 T= 0.5line2.png|400px]]&lt;br /&gt;
[[File:AFinFrame 16 3e5 T= 0.5line2.png|400px]]&lt;br /&gt;
[[File:AFinFrame 8 3e5 T= 0.5line.png|400px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The figure below shows the modifications made to IsingLattice.py to incorporate the &amp;lt;math&amp;gt; N_{d} &amp;lt;/math&amp;gt; step delay.&lt;br /&gt;
&lt;br /&gt;
==Running over a Range of Temperatures==&lt;br /&gt;
&lt;br /&gt;
To examine the effect of temperature on the average energy &amp;lt;math&amp;gt; \left\langle E\right\rangle &amp;lt;/math&amp;gt; and average magnetisation &amp;lt;math&amp;gt; \left\langle M\right\rangle &amp;lt;/math&amp;gt; of Ising lattices at equilibrium, the following parameters were used:&lt;br /&gt;
&lt;br /&gt;
* Temperature Range: &amp;lt;math&amp;gt;  0.5 - 5 &amp;lt;/math&amp;gt; reduced units&lt;br /&gt;
* Temperature Interval: &amp;lt;math&amp;gt;0.01&amp;lt;/math&amp;gt; reduced units (&amp;lt;math&amp;gt;450&amp;lt;/math&amp;gt; temperature values)&lt;br /&gt;
* Number of MMC Steps per Temperature value: &amp;lt;math&amp;gt; 2 \times 10^5 &amp;lt;/math&amp;gt; with the aforementioned value of &amp;lt;math&amp;gt; N_{d} = 1.85 \times 10^5 &amp;lt;/math&amp;gt; Monte Carlo steps&lt;br /&gt;
* Lattice Sizes:  &amp;lt;math&amp;gt; 2 \times 2 &amp;lt;/math&amp;gt;, &amp;lt;math&amp;gt; 4 \times 4 &amp;lt;/math&amp;gt; , &amp;lt;math&amp;gt; 8 \times 8 &amp;lt;/math&amp;gt; , &amp;lt;math&amp;gt; 16 \times 16 &amp;lt;/math&amp;gt; , &amp;lt;math&amp;gt; 32 \times 32 &amp;lt;/math&amp;gt; , &amp;lt;math&amp;gt; 64 \times 64 &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Plots of  &amp;lt;math&amp;gt; \left\langle E\right\rangle &amp;lt;/math&amp;gt; and  &amp;lt;math&amp;gt; \left\langle M\right\rangle &amp;lt;/math&amp;gt; per spin as versus temperature are presented below for each lattice size. Errorbars have been implemented to demonstrate how &#039;&#039;well-behaved&#039;&#039; lattice systems of each size are at each temperature, that is, how temperature and lattice size affect the size of the variations in the expected values. For the error calculations, the standard errors, &amp;lt;math&amp;gt; \sigma_\bar{X} &amp;lt;/math&amp;gt;,  in &amp;lt;math&amp;gt; \left\langle E\right\rangle &amp;lt;/math&amp;gt; and  &amp;lt;math&amp;gt; \left\langle M\right\rangle &amp;lt;/math&amp;gt; per spin have been used:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====8x8====&lt;br /&gt;
&lt;br /&gt;
[[File:8x8e+error.png]] [[File:8x8m+error.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
A Python script has been written to generate a plot of &amp;lt;math&amp;gt;\left\langle E\right\rangle&amp;lt;/math&amp;gt; or &amp;lt;math&amp;gt;\left\langle M\right\rangle&amp;lt;/math&amp;gt; against temperature based upon user input. A screenshot of this code has been inserted below.&lt;br /&gt;
&lt;br /&gt;
[[File:ExpectedvsTemp.PNG|200px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=The Effect of System Size=&lt;br /&gt;
&lt;br /&gt;
==Scaling the System Size==&lt;br /&gt;
&lt;br /&gt;
===More Lattice Sizes===&lt;br /&gt;
&lt;br /&gt;
====2x2====&lt;br /&gt;
[[File:2x2e+error.png]] [[File:2x2m+error.png]]&lt;br /&gt;
&lt;br /&gt;
====4x4====&lt;br /&gt;
[[File:4x4e+error.png]] [[File:4x4m+error.png]]&lt;br /&gt;
&lt;br /&gt;
====16x16====&lt;br /&gt;
[[File:16x16e+error.png]] [[File:16x16m+error.png]]&lt;br /&gt;
&lt;br /&gt;
====32x32====&lt;br /&gt;
[[File:32x32e+error.png]] [[File:32x32m+error.png]]&lt;br /&gt;
&lt;br /&gt;
====64x64====&lt;br /&gt;
[[File:64x64e+error.png]] [[File:64x64m+error.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Scrutiny of the plots of average energy per spin for each lattice size reveals an increase in the errorbar width with increasing lattice size. This is most notable in the low temperature region of the plots. Between the &amp;lt;math&amp;gt; 8\times8 &amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt; 16\times16 &amp;lt;/math&amp;gt; lattices, the long range fluctuations become suddenly prominent. The &amp;lt;math&amp;gt;16\times16&amp;lt;/math&amp;gt; lattice is the first (in the range of sizes tested)to clearly capture these fluctuations.&lt;br /&gt;
&lt;br /&gt;
=Determining the Heat Capacity=&lt;br /&gt;
&lt;br /&gt;
==Calculating the Heat Capacity==&lt;br /&gt;
&lt;br /&gt;
===Heat Capacity Derivation===&lt;br /&gt;
Working in the canonical ensemble (constant volume), the heat capacity &amp;lt;math&amp;gt; C_V &amp;lt;/math&amp;gt; is given by:&lt;br /&gt;
&lt;br /&gt;
:&amp;lt;math&amp;gt;C_V = \frac{\partial \left\langle E\right\rangle}{\partial T}_V&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
where &amp;lt;math&amp;gt;\left\langle E\right\rangle&amp;lt;/math&amp;gt; is the average total energy or expected value of the internal energy of the system.&lt;br /&gt;
&lt;br /&gt;
: &amp;lt;math&amp;gt; \left\langle E\right\rangle = - \frac{\partial ln Q}{\partial \beta} = -\frac{1}{Q}\frac{\partial Q}{\partial \beta} &amp;lt;/math&amp;gt;&lt;br /&gt;
where &amp;lt;math&amp;gt; Q&amp;lt;/math&amp;gt; is the partition function for the system of N interacting spins.&lt;br /&gt;
&lt;br /&gt;
By evaluating the second form of the partial derivative with respect to &amp;lt;math&amp;gt; \beta&amp;lt;/math&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \left\langle E\right\rangle = -\frac{1}{Q}\frac{\partial Q}{\partial \beta} = \frac{\Sigma \epsilon_{i} e^{-\beta \epsilon_{i}}}{\Sigma e^{-\beta \epsilon_{i}}} &amp;lt;/math&amp;gt; &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Applying the product rule enables the differentiation of this expression for &amp;lt;math&amp;gt;\left\langle E\right\rangle&amp;lt;/math&amp;gt; with respect to temperature, giving:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\frac{\partial \left\langle E\right\rangle}{\partial T} = \frac{\Sigma \epsilon_{i} \frac{\epsilon_i}{k_BT^2}e^{-\beta \epsilon_{i}}}{\Sigma e^{-\beta \epsilon_{i}}} - \frac{\Sigma \epsilon_i e^{-\beta \epsilon_i}\cdot \frac{\epsilon_i}{k_BT^2}e^{-\beta \epsilon_i}}{(\Sigma e^{-\beta \epsilon_{i}})^2}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\frac{\partial \left\langle E\right\rangle}{\partial T}  = \frac{1}{k_BT^2}\left[\frac{\Sigma \epsilon_i^2 e^{-\beta \epsilon_i}}{\Sigma e^{-\beta \epsilon_i}} - \left(\frac{\Sigma \epsilon_{i} e^{-\beta \epsilon_{i}}}{\Sigma e^{-\beta \epsilon_{i}}}\right)^2\right] &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\frac{\partial \left\langle E\right\rangle}{\partial T}  = \frac{1}{k_BT^2}\left[\left\langle E^2\right\rangle - \left\langle E\right\rangle^2 \right] &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Thus,&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\frac{\partial \left\langle E\right\rangle}{\partial T} = \frac{Var[E]}{k_BT^2} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Heat Capacity versus Temperature===&lt;br /&gt;
Below, a screenshot of the Python script written to produce plots of &amp;lt;math&amp;gt; C_V &amp;lt;/math&amp;gt; against &amp;lt;math&amp;gt; T &amp;lt;/math&amp;gt;, together with the output images of this script.&lt;br /&gt;
 &lt;br /&gt;
[[File:HeatCapScript.PNG]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====2x2====&lt;br /&gt;
[[File:HC2.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====4x4====&lt;br /&gt;
[[File:HC4.png]]&lt;br /&gt;
&lt;br /&gt;
====8x8====&lt;br /&gt;
[[File:HC8.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====16x16====&lt;br /&gt;
[[File:HC16.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====32x32====&lt;br /&gt;
[[File:HC32.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= Locating the Curie Temperature =&lt;br /&gt;
&lt;br /&gt;
===C++ Data Comparison===&lt;br /&gt;
Below a comparison of the &amp;lt;math&amp;gt; C_V &amp;lt;/math&amp;gt; against &amp;lt;math&amp;gt; T &amp;lt;/math&amp;gt; plot generated for the &amp;lt;math&amp;gt; 2 /times 2&amp;lt;/math&amp;gt; to the corresponding C++ data is offered.&lt;br /&gt;
 &lt;br /&gt;
[[File:CHC2.png]]&lt;br /&gt;
&lt;br /&gt;
The data generated by the ILtemperaturerange.py script is a faithful match to the C++ data. However, this is an exceptional case; the plots for all other lattice sizes were found to be very dissimilar, necessitating polynomial fitting.&lt;br /&gt;
&lt;br /&gt;
==Polyfitting of C++ Data==&lt;br /&gt;
&lt;br /&gt;
===Fitting a Polynomial to the Entire Range===&lt;br /&gt;
The following Python script was written to perform a polynomial fit to the entire range of the graph of &amp;lt;math&amp;gt; C_V &amp;lt;/math&amp;gt; against &amp;lt;math&amp;gt; T &amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:HeatCapPoly.PNG]]&lt;br /&gt;
&lt;br /&gt;
Below, the result of the polyfit to the &amp;lt;math&amp;gt; 2/times2&amp;lt;/math&amp;gt; lattice data is offered (for comparison to the previous, non-fitted example).&lt;br /&gt;
&lt;br /&gt;
[[File:15Polyc2x2.png]]&lt;br /&gt;
&lt;br /&gt;
Polynomials with 5 terms and above were found to match the data in the vicinity of the critical region considerably well. Below 7 terms, the &#039;&#039;tails&#039;&#039; of the plot were matched poorly. In the above example, a polynomial of 15 terms was fit to the data.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Fitting a Polynomial to the Critical Region===&lt;br /&gt;
&lt;br /&gt;
The following Python script was written to perform a polynomial fit to the region of interest (the &#039;&#039;critical&#039;&#039; region) of the plots of &amp;lt;math&amp;gt; C_V &amp;lt;/math&amp;gt; against &amp;lt;math&amp;gt; T &amp;lt;/math&amp;gt; to facilitate the discovery of &amp;lt;math&amp;gt; T_C &amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
[[File:CapPolyCrit.PNG]]&lt;br /&gt;
&lt;br /&gt;
An example of the result returned by the script is offered below for the C++ data for the &amp;lt;math&amp;gt; 16\times16&amp;lt;/math&amp;gt; lattice.&lt;br /&gt;
&lt;br /&gt;
[[File:HHCPC16,2.6-2.1,5.png]]&lt;br /&gt;
&lt;br /&gt;
=== Python Scripts ===&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
* Frenkel, Daan, et al. Understanding Molecular Simulation : From Algorithms to Applications, Elsevier Science &amp;amp; Technology, 2001&lt;/div&gt;</summary>
		<author><name>Jj1516</name></author>
	</entry>
	<entry>
		<id>https://chemwiki.ch.ic.ac.uk/index.php?title=File:CapPolyCrit.PNG&amp;diff=736579</id>
		<title>File:CapPolyCrit.PNG</title>
		<link rel="alternate" type="text/html" href="https://chemwiki.ch.ic.ac.uk/index.php?title=File:CapPolyCrit.PNG&amp;diff=736579"/>
		<updated>2018-11-20T22:41:44Z</updated>

		<summary type="html">&lt;p&gt;Jj1516: New edition&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;New edition&lt;/div&gt;</summary>
		<author><name>Jj1516</name></author>
	</entry>
	<entry>
		<id>https://chemwiki.ch.ic.ac.uk/index.php?title=Rep:JJ1516Ising&amp;diff=736578</id>
		<title>Rep:JJ1516Ising</title>
		<link rel="alternate" type="text/html" href="https://chemwiki.ch.ic.ac.uk/index.php?title=Rep:JJ1516Ising&amp;diff=736578"/>
		<updated>2018-11-20T22:39:59Z</updated>

		<summary type="html">&lt;p&gt;Jj1516: /* Fitting a Polynomial to the Critical Region */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Ex Script Link:&lt;br /&gt;
https://wiki.ch.ic.ac.uk/wiki/index.php?title=Third_year_CMP_compulsory_experiment&lt;br /&gt;
&lt;br /&gt;
= Introduction to the Ising Model =&lt;br /&gt;
&lt;br /&gt;
== The Model ==&lt;br /&gt;
&lt;br /&gt;
=== Minimum Energy State ===&lt;br /&gt;
====Minimum Interaction Energy====&lt;br /&gt;
The interaction energy of an Ising lattice is given by:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;E = -\frac{1}{2}J\displaystyle\sum_{i}^{N} \displaystyle\sum_{j\;\in\;{neighbours}\;(i)} \!\!\!\!\!\!\!\!\!\!\!\!s_{i}s_{j}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In an Ising lattice with D dimensions and periodic boundary conditions, a given spin &amp;lt;math&amp;gt; s_i&amp;lt;/math&amp;gt; has 2D neighbours.&lt;br /&gt;
&lt;br /&gt;
The minimum interaction energy is achieved when all spins in the lattice are aligned (all ↑ or all ↓). As  such, any spin &amp;lt;math&amp;gt; s_i&amp;lt;/math&amp;gt; must be aligned with all 2D of its neighbours. That is, &amp;lt;math&amp;gt;s_{i}s_{j} = 1&amp;lt;/math&amp;gt; for all &amp;lt;math&amp;gt;j&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Therefore, for any &amp;lt;math&amp;gt; s_i&amp;lt;/math&amp;gt;, the sum of its interactions is &amp;lt;math&amp;gt;\displaystyle\sum_{j\;\in\;{neighbours}\;(i)} \!\!\!\!\!\!\!\!\!\!\!\!s_{i}s_{j} = 2D &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
As this is true for all N spins in the lattice, it follows that &amp;lt;math&amp;gt;\displaystyle\sum_{i}^{N} 2D = 2DN&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Thus the minimum interaction energy is given by:&lt;br /&gt;
&lt;br /&gt;
:&amp;lt;math&amp;gt;E_{min} = -\frac{1}{2}J\cdot2DN = - DNJ &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Entropy of the Minimum Energy State====&lt;br /&gt;
&lt;br /&gt;
The entropy of a state is given by:&lt;br /&gt;
&lt;br /&gt;
:&amp;lt;math&amp;gt;S = k\; ln\; \Omega &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Where &amp;lt;math&amp;gt; \Omega &amp;lt;/math&amp;gt; is the multiplicity of the state, the number of degenerate configurations of said state. The minimum energy state is achievable with all spins ↑ or with all spins ↓. In the absence of an external magnetic field, these configurations are degenerate and indistinguishable giving &amp;lt;math&amp;gt; \Omega = 2 &amp;lt;/math&amp;gt; for this state. Therefore,&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; S_{E_{min}}  = k_{B}\; ln\; 2 = 0.693k_{B} = 9.57 \times 10^{-24} J\!\cdot\!\! K^{-1}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Phase Transitions ==&lt;br /&gt;
&lt;br /&gt;
=== Changes to Minimum Energy Configuration ===&lt;br /&gt;
&lt;br /&gt;
====Energy Change ====&lt;br /&gt;
The energy change &amp;lt;math&amp;gt; \Delta E&amp;lt;/math&amp;gt; associated with a single spin &#039;flip&#039; from the lowest energy onfiguration may be calculated by considering the change in the interaction energy with the spin&#039;s neighbours.&lt;br /&gt;
&lt;br /&gt;
Let &amp;lt;math&amp;gt; D = 3, N = 1000 &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\Delta{E} = E_1 - E_0&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;E_1&amp;lt;/math&amp;gt; Interaction energy after one spin has been &#039;flipped&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;E_0&amp;lt;/math&amp;gt; Lowest energy configuration&lt;br /&gt;
&lt;br /&gt;
[[Image:Task 2 table.PNG]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\displaystyle\sum_{interactions} = -2D + 2D(2D-2) + 2D[N-(2D+1)] &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; = 2DN - 8D &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;E_1 = \displaystyle-\frac{1}{2}J\;\sum_{interactions} = 4DJ - DNJ&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\Delta{E} = E_1 - E_0 = 4DJ - DNJ + DNJ = +4DJ = +12J&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This energy change is independent of &amp;lt;math&amp;gt; N&amp;lt;/math&amp;gt; and depends only on the dimension size and the coupling constant &amp;lt;math&amp;gt; J &amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
In this calculation, the following assumption has been made.&lt;br /&gt;
&lt;br /&gt;
* The lattice dimensions are infinite relative to the size of each cell&lt;br /&gt;
&lt;br /&gt;
This allows &#039;&#039;&#039;any&#039;&#039;&#039; cell to be treated as the centre of the lattice. As every cell interacts with 2D neighbours, flipping any cell in the minimum energy configuration results in the same energy change. Alternatively, the periodic boundary conditions of the Ising model remove the necessity for such an assumption. As a consequence, the absence of &amp;lt;math&amp;gt; N &amp;lt;/math&amp;gt; from the resulting energy change is justified.&lt;br /&gt;
&lt;br /&gt;
====Entropy Change====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; S = k_{B}\; ln\; \Omega &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\Omega = \displaystyle\frac{N!}{{N_{\uparrow}!}{N_{\downarrow}!}}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Where &amp;lt;math&amp;gt;N_{x}!&amp;lt;/math&amp;gt; denotes the factorial of the number of spins in spin state &amp;lt;math&amp;gt;x&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\Delta{S} = k_{B}\;ln\;\left(\displaystyle\frac{\Omega_{2}}{\Omega_{1}}\right)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\Omega_{2} = \frac{1000!}{999!1!} = 1000&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \Omega_{1} = \frac{1000!}{1000!} = 1&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\Delta{S} = k_{B}\;ln\;1000 = 9.54 \times 10^{-23} JK^{-1}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\Delta{S_{mol}} = N_{A}k_{B}\;ln\;1000 = 57.4 \,JK^{-1}mol^{-1}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Magnetisation Values of 1D and 2D Lattices===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;M = \sum_i s_i&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====1D Lattice Magnetisation====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;M_{1D} =\;\;+1&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====2D Lattice Magnetisation====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;M_{2D} =\;\;+1&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Magnetisation at 0K====&lt;br /&gt;
&lt;br /&gt;
At 0K, no thermal energy is available to overcome the energetic barriers to spin flipping. Considering the Hemholtz free energy:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; A = E - TS &amp;lt;/math&amp;gt; &lt;br /&gt;
&lt;br /&gt;
A temperature of 0K nullifies the entropic contribution to the free energy. Thus the energetic driving force (which maximises parallel spin interactions) dominates the entropic driving force (which maximises multiplicity of lattice states). For an Ising Lattice with D =  3, N = 1000 at 0K, the alignment of all spins results in the minimum energy configuration  and an overall magnetisation of &amp;lt;math&amp;gt; M = \pm 1000 &amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
= Calculating the Energy and Magnetisation =&lt;br /&gt;
==Modifying the Files==&lt;br /&gt;
&lt;br /&gt;
===Energy and Magnetisation Functions===&lt;br /&gt;
&lt;br /&gt;
====Energy===&lt;br /&gt;
[[File:First_Ene_Method.PNG]]&lt;br /&gt;
&lt;br /&gt;
The above energy method segments a given lattice into lattice cells on the edges, corners or in the bulk of the lattice and calculates the energy interactions with its neighbours as appropriate.&lt;br /&gt;
&lt;br /&gt;
====Magnetisation====&lt;br /&gt;
[[File:First_Mag_Method.PNG]]&lt;br /&gt;
&lt;br /&gt;
The magnetisation method loops over all elements in the array representing the Ising lattice and adds the value of the spin to the magnetisation variable.&lt;br /&gt;
&lt;br /&gt;
==Testing the Files==&lt;br /&gt;
&lt;br /&gt;
===ILCheck.py===&lt;br /&gt;
&lt;br /&gt;
[[File:ILChecks.PNG]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Above, the results of the ILcheck.py script are presented.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= Introduction to the Monte Carlo Simulation =&lt;br /&gt;
==Average Energy and Magnetisation==&lt;br /&gt;
===Configurations of a 100 Spin System===&lt;br /&gt;
For a system of two spins, 4 configurations are possible (↑↑, ↓↓, ↑↓, ↓↑) i.e. &amp;lt;math&amp;gt;2^{2}&amp;lt;/math&amp;gt;. For a system of 100 spins, there are &amp;lt;math&amp;gt;2^{100}&amp;lt;/math&amp;gt; configurations. In the first example, the ↑↑ and ↓↓ are degenerate, as are the ↑↓ and ↓↑ configurations. Therefore, dividing the number of possible configurations by the multiplicity of each configuration (&amp;lt;math&amp;gt;2&amp;lt;/math&amp;gt;) gives the number of non-degenerate configurations. As previously stated, degenerate configurations are indistinguishable in the absence of an external magnetic field.&lt;br /&gt;
&lt;br /&gt;
For 100 spins, this gives &amp;lt;math&amp;gt;\displaystyle\frac{2^{100}}{2} = 6.338 \times 10^{29} &amp;lt;/math&amp;gt; distinguishable configurations.&lt;br /&gt;
&lt;br /&gt;
If processing speed permits &amp;lt;math&amp;gt; 1 \times 10^{9}&amp;lt;/math&amp;gt; calculations each second, the evaluation of a single value of &amp;lt;math&amp;gt;\left\langle M\right\rangle_T&amp;lt;/math&amp;gt; would last &amp;lt;math&amp;gt; 6.338 \times 10^{20} &amp;lt;/math&amp;gt; seconds or &amp;lt;math&amp;gt; 1458 &amp;lt;/math&amp;gt; times the age of the Universe!&lt;br /&gt;
&lt;br /&gt;
==Modifying IsingLattice.py==&lt;br /&gt;
&lt;br /&gt;
===Monte Carlo and Statistics Methods===&lt;br /&gt;
[[File:Monte_Carlo.PNG]]&lt;br /&gt;
&lt;br /&gt;
[[File:stats.PNG]]&lt;br /&gt;
&lt;br /&gt;
The Metropolis Monte Carlo (MMC) algorithm provides a computationally inexpensive path from random initial states to the minimum free energy states of the Ising lattices generated. First, a random 2D Ising lattice is generated. A single random spin within this lattice is &amp;quot;flipped&amp;quot; and the resulting (internal) energy change between these states is measured. Recalling the relationship between the Hemholtz free energy, internal energy and entropy, it follows that a decrease in internal energy also lowers the free energy of the system: thus the configuration change is accepted.&lt;br /&gt;
&lt;br /&gt;
In the case that the spin &amp;quot;flip&amp;quot; does not lower the internal energy, the MMC algorithm tests this configuration change against the Boltzman factor. In the canonical (NVT) ensemble, the free energy of the system is given by:&lt;br /&gt;
&lt;br /&gt;
:&amp;lt;math&amp;gt;A = -k_{B}T\,lnZ_{NVT} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
where Z is the canonical partition function which depends upon &amp;lt;math&amp;gt; e^{-\frac{\Delta E}{k_BT}} &amp;lt;/math&amp;gt;, the Boltzman factor. By choosing a random value in the interval [0,1)from a continuous uniformm probability distribution and rejecting any value of the Boltzman factor less than this value, ###&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Spontaneous Magnetisation===&lt;br /&gt;
&lt;br /&gt;
Below the Curie Temperature, &amp;lt;math&amp;gt; T_{C} &amp;lt;/math&amp;gt;, the energetic driving force dominates the entropic driving force, resulting in a highly ordered system and an overall magnetisation. The spins of the system align in order to maximise favourable coupling interactions rather than adopting a less ordered configuration of higher multiplicity. Therefore, when &amp;lt;math&amp;gt;T &amp;lt; T_C&amp;lt;/math&amp;gt;, the most probable configurations have an overall magnetisation resulting in &amp;lt;math&amp;gt;\left\langle M\right\rangle \neq 0&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
The plots of magnetisation per spin and energy per spin obtained from ILanim.py support this prediction. Below, the plots show that upon equilibration, the system adopts the minimum energy per spin: &amp;lt;math&amp;gt;E_{min_{spin}} = \frac{-NDJ}{N} = -DJ = -2&amp;lt;/math&amp;gt; and exhibits the maximum magnitude of magnetisation per spin: &amp;lt;math&amp;gt;|M_{spin}| = 1&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:2T=1.0.png]]&lt;br /&gt;
[[File:T=1.0.png]]&lt;br /&gt;
[[File:3T=1.0.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
An unknown system error prevented the statistics() function from printing the average values.&lt;br /&gt;
&lt;br /&gt;
=Accelerating the Code=&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Initial Method Speeds===&lt;br /&gt;
Taking 10 repeat measurements for the time taken to perform 2000 Monte Carlo steps resulted in&lt;br /&gt;
&lt;br /&gt;
* An average time of  &amp;lt;math&amp;gt;11.7s&amp;lt;/math&amp;gt; &lt;br /&gt;
* A standard error of &amp;lt;math&amp;gt;0.020s&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Updating Measurement===&lt;br /&gt;
&lt;br /&gt;
NOTE: ILtimetrial.py has been modified to:&lt;br /&gt;
* Perform a requested number of &#039;2000 Monte Carlo Step&#039; measurements&lt;br /&gt;
* Record these measurements in a CSV file&lt;br /&gt;
* Return the mean measuremd time and the Standard Error i.e.   &amp;lt;math&amp;gt; \frac{\sigma}{n} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:TimeTrialMethod.PNG]]&lt;br /&gt;
&lt;br /&gt;
===Updating Energy and Magnetisation Methods===&lt;br /&gt;
[[File:New_Mag_Method.PNG]]&lt;br /&gt;
[[File:New_Ene_Method.PNG]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Updated Method Speeds===&lt;br /&gt;
[[File:TimeTrial.PNG]]&lt;br /&gt;
&lt;br /&gt;
Taking 30 measurements of the time taken to perform 2000 Monte Carlo Steps resulted in:&lt;br /&gt;
&lt;br /&gt;
* An average time of &amp;lt;math&amp;gt;\displaystyle{0.87s}&amp;lt;/math&amp;gt;&lt;br /&gt;
* A standard error of &amp;lt;math&amp;gt;2.5 \times 10^{-3}s&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This represents a 93% decrease in the average computation time from the initial methods.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=The Effect of Temperature=&lt;br /&gt;
&lt;br /&gt;
==Correcting the Averaging  Code==&lt;br /&gt;
&lt;br /&gt;
===Finding a Delay Value===&lt;br /&gt;
To quickly find a value for &amp;lt;math&amp;gt; N_{d}&amp;lt;/math&amp;gt;, the minimum number of cycles typically needed for the equilibration of a system of within the lattice and temperature ranges of interest, it was assumed that:&lt;br /&gt;
&lt;br /&gt;
* Larger lattices would require more Monte Carlo steps to reach equilibrium from their initial, random configurations&lt;br /&gt;
&lt;br /&gt;
* Lattices at lower temperatures would require more Monte Carlo steps to reach equilibrium from their initial, random configurations.&lt;br /&gt;
&lt;br /&gt;
Therefore, an initial value for &amp;lt;math&amp;gt; N_{d}&amp;lt;/math&amp;gt; was found for a &amp;lt;math&amp;gt; 128\times128 &amp;lt;/math&amp;gt; lattice at a temperature of &amp;lt;math&amp;gt;0.5&amp;lt;/math&amp;gt; reduced temperature units.&lt;br /&gt;
*&amp;lt;math&amp;gt; N_{d} = 185000 &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
By this number of steps, all smaller lattices at all higher temperatures were found to have equilibrated also. Thus, this value of&amp;lt;math&amp;gt; N_{d}&amp;lt;/math&amp;gt; was accepted as an appropriate delay.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:AFinFrame 128 3e5 T= 0.5line.png|400px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
For the 128x128 lattices at T=0.5, equilibration was ensured from 185000 steps onwards.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Smaller lattices at the same temperature did indeed equilibrate more slowly, but all equilibrated within &amp;lt;math&amp;gt; N_{d}&amp;lt;/math&amp;gt; MC steps.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:AFinFrame 64 3e5 T= 0.5line.png|400px]]&lt;br /&gt;
[[File:AFinFrame 32 3e5 T= 0.5line2.png|400px]]&lt;br /&gt;
[[File:AFinFrame 16 3e5 T= 0.5line2.png|400px]]&lt;br /&gt;
[[File:AFinFrame 8 3e5 T= 0.5line.png|400px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The figure below shows the modifications made to IsingLattice.py to incorporate the &amp;lt;math&amp;gt; N_{d} &amp;lt;/math&amp;gt; step delay.&lt;br /&gt;
&lt;br /&gt;
==Running over a Range of Temperatures==&lt;br /&gt;
&lt;br /&gt;
To examine the effect of temperature on the average energy &amp;lt;math&amp;gt; \left\langle E\right\rangle &amp;lt;/math&amp;gt; and average magnetisation &amp;lt;math&amp;gt; \left\langle M\right\rangle &amp;lt;/math&amp;gt; of Ising lattices at equilibrium, the following parameters were used:&lt;br /&gt;
&lt;br /&gt;
* Temperature Range: &amp;lt;math&amp;gt;  0.5 - 5 &amp;lt;/math&amp;gt; reduced units&lt;br /&gt;
* Temperature Interval: &amp;lt;math&amp;gt;0.01&amp;lt;/math&amp;gt; reduced units (&amp;lt;math&amp;gt;450&amp;lt;/math&amp;gt; temperature values)&lt;br /&gt;
* Number of MMC Steps per Temperature value: &amp;lt;math&amp;gt; 2 \times 10^5 &amp;lt;/math&amp;gt; with the aforementioned value of &amp;lt;math&amp;gt; N_{d} = 1.85 \times 10^5 &amp;lt;/math&amp;gt; Monte Carlo steps&lt;br /&gt;
* Lattice Sizes:  &amp;lt;math&amp;gt; 2 \times 2 &amp;lt;/math&amp;gt;, &amp;lt;math&amp;gt; 4 \times 4 &amp;lt;/math&amp;gt; , &amp;lt;math&amp;gt; 8 \times 8 &amp;lt;/math&amp;gt; , &amp;lt;math&amp;gt; 16 \times 16 &amp;lt;/math&amp;gt; , &amp;lt;math&amp;gt; 32 \times 32 &amp;lt;/math&amp;gt; , &amp;lt;math&amp;gt; 64 \times 64 &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Plots of  &amp;lt;math&amp;gt; \left\langle E\right\rangle &amp;lt;/math&amp;gt; and  &amp;lt;math&amp;gt; \left\langle M\right\rangle &amp;lt;/math&amp;gt; per spin as versus temperature are presented below for each lattice size. Errorbars have been implemented to demonstrate how &#039;&#039;well-behaved&#039;&#039; lattice systems of each size are at each temperature, that is, how temperature and lattice size affect the size of the variations in the expected values. For the error calculations, the standard errors, &amp;lt;math&amp;gt; \sigma_\bar{X} &amp;lt;/math&amp;gt;,  in &amp;lt;math&amp;gt; \left\langle E\right\rangle &amp;lt;/math&amp;gt; and  &amp;lt;math&amp;gt; \left\langle M\right\rangle &amp;lt;/math&amp;gt; per spin have been used:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====8x8====&lt;br /&gt;
&lt;br /&gt;
[[File:8x8e+error.png]] [[File:8x8m+error.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
A Python script has been written to generate a plot of &amp;lt;math&amp;gt;\left\langle E\right\rangle&amp;lt;/math&amp;gt; or &amp;lt;math&amp;gt;\left\langle M\right\rangle&amp;lt;/math&amp;gt; against temperature based upon user input. A screenshot of this code has been inserted below.&lt;br /&gt;
&lt;br /&gt;
[[File:ExpectedvsTemp.PNG|200px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=The Effect of System Size=&lt;br /&gt;
&lt;br /&gt;
==Scaling the System Size==&lt;br /&gt;
&lt;br /&gt;
===More Lattice Sizes===&lt;br /&gt;
&lt;br /&gt;
====2x2====&lt;br /&gt;
[[File:2x2e+error.png]] [[File:2x2m+error.png]]&lt;br /&gt;
&lt;br /&gt;
====4x4====&lt;br /&gt;
[[File:4x4e+error.png]] [[File:4x4m+error.png]]&lt;br /&gt;
&lt;br /&gt;
====16x16====&lt;br /&gt;
[[File:16x16e+error.png]] [[File:16x16m+error.png]]&lt;br /&gt;
&lt;br /&gt;
====32x32====&lt;br /&gt;
[[File:32x32e+error.png]] [[File:32x32m+error.png]]&lt;br /&gt;
&lt;br /&gt;
====64x64====&lt;br /&gt;
[[File:64x64e+error.png]] [[File:64x64m+error.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Scrutiny of the plots of average energy per spin for each lattice size reveals an increase in the errorbar width with increasing lattice size. This is most notable in the low temperature region of the plots. Between the &amp;lt;math&amp;gt; 8\times8 &amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt; 16\times16 &amp;lt;/math&amp;gt; lattices, the long range fluctuations become suddenly prominent. The &amp;lt;math&amp;gt;16\times16&amp;lt;/math&amp;gt; lattice is the first (in the range of sizes tested)to clearly capture these fluctuations.&lt;br /&gt;
&lt;br /&gt;
=Determining the Heat Capacity=&lt;br /&gt;
&lt;br /&gt;
==Calculating the Heat Capacity==&lt;br /&gt;
&lt;br /&gt;
===Heat Capacity Derivation===&lt;br /&gt;
Working in the canonical ensemble (constant volume), the heat capacity &amp;lt;math&amp;gt; C_V &amp;lt;/math&amp;gt; is given by:&lt;br /&gt;
&lt;br /&gt;
:&amp;lt;math&amp;gt;C_V = \frac{\partial \left\langle E\right\rangle}{\partial T}_V&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
where &amp;lt;math&amp;gt;\left\langle E\right\rangle&amp;lt;/math&amp;gt; is the average total energy or expected value of the internal energy of the system.&lt;br /&gt;
&lt;br /&gt;
: &amp;lt;math&amp;gt; \left\langle E\right\rangle = - \frac{\partial ln Q}{\partial \beta} = -\frac{1}{Q}\frac{\partial Q}{\partial \beta} &amp;lt;/math&amp;gt;&lt;br /&gt;
where &amp;lt;math&amp;gt; Q&amp;lt;/math&amp;gt; is the partition function for the system of N interacting spins.&lt;br /&gt;
&lt;br /&gt;
By evaluating the second form of the partial derivative with respect to &amp;lt;math&amp;gt; \beta&amp;lt;/math&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \left\langle E\right\rangle = -\frac{1}{Q}\frac{\partial Q}{\partial \beta} = \frac{\Sigma \epsilon_{i} e^{-\beta \epsilon_{i}}}{\Sigma e^{-\beta \epsilon_{i}}} &amp;lt;/math&amp;gt; &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Applying the product rule enables the differentiation of this expression for &amp;lt;math&amp;gt;\left\langle E\right\rangle&amp;lt;/math&amp;gt; with respect to temperature, giving:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\frac{\partial \left\langle E\right\rangle}{\partial T} = \frac{\Sigma \epsilon_{i} \frac{\epsilon_i}{k_BT^2}e^{-\beta \epsilon_{i}}}{\Sigma e^{-\beta \epsilon_{i}}} - \frac{\Sigma \epsilon_i e^{-\beta \epsilon_i}\cdot \frac{\epsilon_i}{k_BT^2}e^{-\beta \epsilon_i}}{(\Sigma e^{-\beta \epsilon_{i}})^2}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\frac{\partial \left\langle E\right\rangle}{\partial T}  = \frac{1}{k_BT^2}\left[\frac{\Sigma \epsilon_i^2 e^{-\beta \epsilon_i}}{\Sigma e^{-\beta \epsilon_i}} - \left(\frac{\Sigma \epsilon_{i} e^{-\beta \epsilon_{i}}}{\Sigma e^{-\beta \epsilon_{i}}}\right)^2\right] &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\frac{\partial \left\langle E\right\rangle}{\partial T}  = \frac{1}{k_BT^2}\left[\left\langle E^2\right\rangle - \left\langle E\right\rangle^2 \right] &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Thus,&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\frac{\partial \left\langle E\right\rangle}{\partial T} = \frac{Var[E]}{k_BT^2} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Heat Capacity versus Temperature===&lt;br /&gt;
Below, a screenshot of the Python script written to produce plots of &amp;lt;math&amp;gt; C_V &amp;lt;/math&amp;gt; against &amp;lt;math&amp;gt; T &amp;lt;/math&amp;gt;, together with the output images of this script.&lt;br /&gt;
 &lt;br /&gt;
[[File:HeatCapScript.PNG]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====2x2====&lt;br /&gt;
[[File:HC2.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====4x4====&lt;br /&gt;
[[File:HC4.png]]&lt;br /&gt;
&lt;br /&gt;
====8x8====&lt;br /&gt;
[[File:HC8.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====16x16====&lt;br /&gt;
[[File:HC16.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====32x32====&lt;br /&gt;
[[File:HC32.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= Locating the Curie Temperature =&lt;br /&gt;
&lt;br /&gt;
===C++ Data Comparison===&lt;br /&gt;
Below a comparison of the &amp;lt;math&amp;gt; C_V &amp;lt;/math&amp;gt; against &amp;lt;math&amp;gt; T &amp;lt;/math&amp;gt; plot generated for the &amp;lt;math&amp;gt; 2 /times 2&amp;lt;/math&amp;gt; to the corresponding C++ data is offered.&lt;br /&gt;
 &lt;br /&gt;
[[File:CHC2.png]]&lt;br /&gt;
&lt;br /&gt;
The data generated by the ILtemperaturerange.py script is a faithful match to the C++ data. However, this is an exceptional case; the plots for all other lattice sizes were found to be very dissimilar, necessitating polynomial fitting.&lt;br /&gt;
&lt;br /&gt;
==Polyfitting of C++ Data==&lt;br /&gt;
&lt;br /&gt;
===Fitting a Polynomial to the Entire Range===&lt;br /&gt;
The following Python script was written to perform a polynomial fit to the entire range of the graph of &amp;lt;math&amp;gt; C_V &amp;lt;/math&amp;gt; against &amp;lt;math&amp;gt; T &amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:HeatCapPoly.PNG]]&lt;br /&gt;
&lt;br /&gt;
Below, the result of the polyfit to the &amp;lt;math&amp;gt; 2/times2&amp;lt;/math&amp;gt; lattice data is offered (for comparison to the previous, non-fitted example).&lt;br /&gt;
&lt;br /&gt;
[[File:15Polyc2x2.png]]&lt;br /&gt;
&lt;br /&gt;
Polynomials with 5 terms and above were found to match the data in the vicinity of the critical region considerably well. Below 7 terms, the &#039;&#039;tails&#039;&#039; of the plot were matched poorly. In the above example, a polynomial of 15 terms was fit to the data.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Fitting a Polynomial to the Critical Region===&lt;br /&gt;
&lt;br /&gt;
The following Python script was written to perform a polynomial fit to the region of interest (the &#039;&#039;critical&#039;&#039; region) of the plots of &amp;lt;math&amp;gt; C_V &amp;lt;/math&amp;gt; against &amp;lt;math&amp;gt; T &amp;lt;/math&amp;gt; to facilitate the discovery of &amp;lt;math&amp;gt; T_C &amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
[[File:HeatCapPolyCrit.PNG]]&lt;br /&gt;
&lt;br /&gt;
An example of the result returned by the script is offered below for the C++ data for the &amp;lt;math&amp;gt; 16\times16&amp;lt;/math&amp;gt; lattice.&lt;br /&gt;
&lt;br /&gt;
[[File:HHCPC16,2.6-2.1,5.png]]&lt;br /&gt;
&lt;br /&gt;
=== Python Scripts ===&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
* Frenkel, Daan, et al. Understanding Molecular Simulation : From Algorithms to Applications, Elsevier Science &amp;amp; Technology, 2001&lt;/div&gt;</summary>
		<author><name>Jj1516</name></author>
	</entry>
	<entry>
		<id>https://chemwiki.ch.ic.ac.uk/index.php?title=File:HHCPC16,2.6-2.1,5.png&amp;diff=736577</id>
		<title>File:HHCPC16,2.6-2.1,5.png</title>
		<link rel="alternate" type="text/html" href="https://chemwiki.ch.ic.ac.uk/index.php?title=File:HHCPC16,2.6-2.1,5.png&amp;diff=736577"/>
		<updated>2018-11-20T22:39:43Z</updated>

		<summary type="html">&lt;p&gt;Jj1516: New edition&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;New edition&lt;/div&gt;</summary>
		<author><name>Jj1516</name></author>
	</entry>
	<entry>
		<id>https://chemwiki.ch.ic.ac.uk/index.php?title=Rep:JJ1516Ising&amp;diff=736576</id>
		<title>Rep:JJ1516Ising</title>
		<link rel="alternate" type="text/html" href="https://chemwiki.ch.ic.ac.uk/index.php?title=Rep:JJ1516Ising&amp;diff=736576"/>
		<updated>2018-11-20T22:38:32Z</updated>

		<summary type="html">&lt;p&gt;Jj1516: /* Fitting a Polynomial to the Critical Region */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Ex Script Link:&lt;br /&gt;
https://wiki.ch.ic.ac.uk/wiki/index.php?title=Third_year_CMP_compulsory_experiment&lt;br /&gt;
&lt;br /&gt;
= Introduction to the Ising Model =&lt;br /&gt;
&lt;br /&gt;
== The Model ==&lt;br /&gt;
&lt;br /&gt;
=== Minimum Energy State ===&lt;br /&gt;
====Minimum Interaction Energy====&lt;br /&gt;
The interaction energy of an Ising lattice is given by:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;E = -\frac{1}{2}J\displaystyle\sum_{i}^{N} \displaystyle\sum_{j\;\in\;{neighbours}\;(i)} \!\!\!\!\!\!\!\!\!\!\!\!s_{i}s_{j}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In an Ising lattice with D dimensions and periodic boundary conditions, a given spin &amp;lt;math&amp;gt; s_i&amp;lt;/math&amp;gt; has 2D neighbours.&lt;br /&gt;
&lt;br /&gt;
The minimum interaction energy is achieved when all spins in the lattice are aligned (all ↑ or all ↓). As  such, any spin &amp;lt;math&amp;gt; s_i&amp;lt;/math&amp;gt; must be aligned with all 2D of its neighbours. That is, &amp;lt;math&amp;gt;s_{i}s_{j} = 1&amp;lt;/math&amp;gt; for all &amp;lt;math&amp;gt;j&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Therefore, for any &amp;lt;math&amp;gt; s_i&amp;lt;/math&amp;gt;, the sum of its interactions is &amp;lt;math&amp;gt;\displaystyle\sum_{j\;\in\;{neighbours}\;(i)} \!\!\!\!\!\!\!\!\!\!\!\!s_{i}s_{j} = 2D &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
As this is true for all N spins in the lattice, it follows that &amp;lt;math&amp;gt;\displaystyle\sum_{i}^{N} 2D = 2DN&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Thus the minimum interaction energy is given by:&lt;br /&gt;
&lt;br /&gt;
:&amp;lt;math&amp;gt;E_{min} = -\frac{1}{2}J\cdot2DN = - DNJ &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Entropy of the Minimum Energy State====&lt;br /&gt;
&lt;br /&gt;
The entropy of a state is given by:&lt;br /&gt;
&lt;br /&gt;
:&amp;lt;math&amp;gt;S = k\; ln\; \Omega &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Where &amp;lt;math&amp;gt; \Omega &amp;lt;/math&amp;gt; is the multiplicity of the state, the number of degenerate configurations of said state. The minimum energy state is achievable with all spins ↑ or with all spins ↓. In the absence of an external magnetic field, these configurations are degenerate and indistinguishable giving &amp;lt;math&amp;gt; \Omega = 2 &amp;lt;/math&amp;gt; for this state. Therefore,&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; S_{E_{min}}  = k_{B}\; ln\; 2 = 0.693k_{B} = 9.57 \times 10^{-24} J\!\cdot\!\! K^{-1}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Phase Transitions ==&lt;br /&gt;
&lt;br /&gt;
=== Changes to Minimum Energy Configuration ===&lt;br /&gt;
&lt;br /&gt;
====Energy Change ====&lt;br /&gt;
The energy change &amp;lt;math&amp;gt; \Delta E&amp;lt;/math&amp;gt; associated with a single spin &#039;flip&#039; from the lowest energy onfiguration may be calculated by considering the change in the interaction energy with the spin&#039;s neighbours.&lt;br /&gt;
&lt;br /&gt;
Let &amp;lt;math&amp;gt; D = 3, N = 1000 &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\Delta{E} = E_1 - E_0&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;E_1&amp;lt;/math&amp;gt; Interaction energy after one spin has been &#039;flipped&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;E_0&amp;lt;/math&amp;gt; Lowest energy configuration&lt;br /&gt;
&lt;br /&gt;
[[Image:Task 2 table.PNG]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\displaystyle\sum_{interactions} = -2D + 2D(2D-2) + 2D[N-(2D+1)] &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; = 2DN - 8D &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;E_1 = \displaystyle-\frac{1}{2}J\;\sum_{interactions} = 4DJ - DNJ&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\Delta{E} = E_1 - E_0 = 4DJ - DNJ + DNJ = +4DJ = +12J&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This energy change is independent of &amp;lt;math&amp;gt; N&amp;lt;/math&amp;gt; and depends only on the dimension size and the coupling constant &amp;lt;math&amp;gt; J &amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
In this calculation, the following assumption has been made.&lt;br /&gt;
&lt;br /&gt;
* The lattice dimensions are infinite relative to the size of each cell&lt;br /&gt;
&lt;br /&gt;
This allows &#039;&#039;&#039;any&#039;&#039;&#039; cell to be treated as the centre of the lattice. As every cell interacts with 2D neighbours, flipping any cell in the minimum energy configuration results in the same energy change. Alternatively, the periodic boundary conditions of the Ising model remove the necessity for such an assumption. As a consequence, the absence of &amp;lt;math&amp;gt; N &amp;lt;/math&amp;gt; from the resulting energy change is justified.&lt;br /&gt;
&lt;br /&gt;
====Entropy Change====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; S = k_{B}\; ln\; \Omega &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\Omega = \displaystyle\frac{N!}{{N_{\uparrow}!}{N_{\downarrow}!}}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Where &amp;lt;math&amp;gt;N_{x}!&amp;lt;/math&amp;gt; denotes the factorial of the number of spins in spin state &amp;lt;math&amp;gt;x&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\Delta{S} = k_{B}\;ln\;\left(\displaystyle\frac{\Omega_{2}}{\Omega_{1}}\right)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\Omega_{2} = \frac{1000!}{999!1!} = 1000&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \Omega_{1} = \frac{1000!}{1000!} = 1&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\Delta{S} = k_{B}\;ln\;1000 = 9.54 \times 10^{-23} JK^{-1}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\Delta{S_{mol}} = N_{A}k_{B}\;ln\;1000 = 57.4 \,JK^{-1}mol^{-1}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Magnetisation Values of 1D and 2D Lattices===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;M = \sum_i s_i&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====1D Lattice Magnetisation====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;M_{1D} =\;\;+1&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====2D Lattice Magnetisation====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;M_{2D} =\;\;+1&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Magnetisation at 0K====&lt;br /&gt;
&lt;br /&gt;
At 0K, no thermal energy is available to overcome the energetic barriers to spin flipping. Considering the Hemholtz free energy:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; A = E - TS &amp;lt;/math&amp;gt; &lt;br /&gt;
&lt;br /&gt;
A temperature of 0K nullifies the entropic contribution to the free energy. Thus the energetic driving force (which maximises parallel spin interactions) dominates the entropic driving force (which maximises multiplicity of lattice states). For an Ising Lattice with D =  3, N = 1000 at 0K, the alignment of all spins results in the minimum energy configuration  and an overall magnetisation of &amp;lt;math&amp;gt; M = \pm 1000 &amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
= Calculating the Energy and Magnetisation =&lt;br /&gt;
==Modifying the Files==&lt;br /&gt;
&lt;br /&gt;
===Energy and Magnetisation Functions===&lt;br /&gt;
&lt;br /&gt;
====Energy===&lt;br /&gt;
[[File:First_Ene_Method.PNG]]&lt;br /&gt;
&lt;br /&gt;
The above energy method segments a given lattice into lattice cells on the edges, corners or in the bulk of the lattice and calculates the energy interactions with its neighbours as appropriate.&lt;br /&gt;
&lt;br /&gt;
====Magnetisation====&lt;br /&gt;
[[File:First_Mag_Method.PNG]]&lt;br /&gt;
&lt;br /&gt;
The magnetisation method loops over all elements in the array representing the Ising lattice and adds the value of the spin to the magnetisation variable.&lt;br /&gt;
&lt;br /&gt;
==Testing the Files==&lt;br /&gt;
&lt;br /&gt;
===ILCheck.py===&lt;br /&gt;
&lt;br /&gt;
[[File:ILChecks.PNG]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Above, the results of the ILcheck.py script are presented.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= Introduction to the Monte Carlo Simulation =&lt;br /&gt;
==Average Energy and Magnetisation==&lt;br /&gt;
===Configurations of a 100 Spin System===&lt;br /&gt;
For a system of two spins, 4 configurations are possible (↑↑, ↓↓, ↑↓, ↓↑) i.e. &amp;lt;math&amp;gt;2^{2}&amp;lt;/math&amp;gt;. For a system of 100 spins, there are &amp;lt;math&amp;gt;2^{100}&amp;lt;/math&amp;gt; configurations. In the first example, the ↑↑ and ↓↓ are degenerate, as are the ↑↓ and ↓↑ configurations. Therefore, dividing the number of possible configurations by the multiplicity of each configuration (&amp;lt;math&amp;gt;2&amp;lt;/math&amp;gt;) gives the number of non-degenerate configurations. As previously stated, degenerate configurations are indistinguishable in the absence of an external magnetic field.&lt;br /&gt;
&lt;br /&gt;
For 100 spins, this gives &amp;lt;math&amp;gt;\displaystyle\frac{2^{100}}{2} = 6.338 \times 10^{29} &amp;lt;/math&amp;gt; distinguishable configurations.&lt;br /&gt;
&lt;br /&gt;
If processing speed permits &amp;lt;math&amp;gt; 1 \times 10^{9}&amp;lt;/math&amp;gt; calculations each second, the evaluation of a single value of &amp;lt;math&amp;gt;\left\langle M\right\rangle_T&amp;lt;/math&amp;gt; would last &amp;lt;math&amp;gt; 6.338 \times 10^{20} &amp;lt;/math&amp;gt; seconds or &amp;lt;math&amp;gt; 1458 &amp;lt;/math&amp;gt; times the age of the Universe!&lt;br /&gt;
&lt;br /&gt;
==Modifying IsingLattice.py==&lt;br /&gt;
&lt;br /&gt;
===Monte Carlo and Statistics Methods===&lt;br /&gt;
[[File:Monte_Carlo.PNG]]&lt;br /&gt;
&lt;br /&gt;
[[File:stats.PNG]]&lt;br /&gt;
&lt;br /&gt;
The Metropolis Monte Carlo (MMC) algorithm provides a computationally inexpensive path from random initial states to the minimum free energy states of the Ising lattices generated. First, a random 2D Ising lattice is generated. A single random spin within this lattice is &amp;quot;flipped&amp;quot; and the resulting (internal) energy change between these states is measured. Recalling the relationship between the Hemholtz free energy, internal energy and entropy, it follows that a decrease in internal energy also lowers the free energy of the system: thus the configuration change is accepted.&lt;br /&gt;
&lt;br /&gt;
In the case that the spin &amp;quot;flip&amp;quot; does not lower the internal energy, the MMC algorithm tests this configuration change against the Boltzman factor. In the canonical (NVT) ensemble, the free energy of the system is given by:&lt;br /&gt;
&lt;br /&gt;
:&amp;lt;math&amp;gt;A = -k_{B}T\,lnZ_{NVT} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
where Z is the canonical partition function which depends upon &amp;lt;math&amp;gt; e^{-\frac{\Delta E}{k_BT}} &amp;lt;/math&amp;gt;, the Boltzman factor. By choosing a random value in the interval [0,1)from a continuous uniformm probability distribution and rejecting any value of the Boltzman factor less than this value, ###&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Spontaneous Magnetisation===&lt;br /&gt;
&lt;br /&gt;
Below the Curie Temperature, &amp;lt;math&amp;gt; T_{C} &amp;lt;/math&amp;gt;, the energetic driving force dominates the entropic driving force, resulting in a highly ordered system and an overall magnetisation. The spins of the system align in order to maximise favourable coupling interactions rather than adopting a less ordered configuration of higher multiplicity. Therefore, when &amp;lt;math&amp;gt;T &amp;lt; T_C&amp;lt;/math&amp;gt;, the most probable configurations have an overall magnetisation resulting in &amp;lt;math&amp;gt;\left\langle M\right\rangle \neq 0&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
The plots of magnetisation per spin and energy per spin obtained from ILanim.py support this prediction. Below, the plots show that upon equilibration, the system adopts the minimum energy per spin: &amp;lt;math&amp;gt;E_{min_{spin}} = \frac{-NDJ}{N} = -DJ = -2&amp;lt;/math&amp;gt; and exhibits the maximum magnitude of magnetisation per spin: &amp;lt;math&amp;gt;|M_{spin}| = 1&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:2T=1.0.png]]&lt;br /&gt;
[[File:T=1.0.png]]&lt;br /&gt;
[[File:3T=1.0.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
An unknown system error prevented the statistics() function from printing the average values.&lt;br /&gt;
&lt;br /&gt;
=Accelerating the Code=&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Initial Method Speeds===&lt;br /&gt;
Taking 10 repeat measurements for the time taken to perform 2000 Monte Carlo steps resulted in&lt;br /&gt;
&lt;br /&gt;
* An average time of  &amp;lt;math&amp;gt;11.7s&amp;lt;/math&amp;gt; &lt;br /&gt;
* A standard error of &amp;lt;math&amp;gt;0.020s&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Updating Measurement===&lt;br /&gt;
&lt;br /&gt;
NOTE: ILtimetrial.py has been modified to:&lt;br /&gt;
* Perform a requested number of &#039;2000 Monte Carlo Step&#039; measurements&lt;br /&gt;
* Record these measurements in a CSV file&lt;br /&gt;
* Return the mean measuremd time and the Standard Error i.e.   &amp;lt;math&amp;gt; \frac{\sigma}{n} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:TimeTrialMethod.PNG]]&lt;br /&gt;
&lt;br /&gt;
===Updating Energy and Magnetisation Methods===&lt;br /&gt;
[[File:New_Mag_Method.PNG]]&lt;br /&gt;
[[File:New_Ene_Method.PNG]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Updated Method Speeds===&lt;br /&gt;
[[File:TimeTrial.PNG]]&lt;br /&gt;
&lt;br /&gt;
Taking 30 measurements of the time taken to perform 2000 Monte Carlo Steps resulted in:&lt;br /&gt;
&lt;br /&gt;
* An average time of &amp;lt;math&amp;gt;\displaystyle{0.87s}&amp;lt;/math&amp;gt;&lt;br /&gt;
* A standard error of &amp;lt;math&amp;gt;2.5 \times 10^{-3}s&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This represents a 93% decrease in the average computation time from the initial methods.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=The Effect of Temperature=&lt;br /&gt;
&lt;br /&gt;
==Correcting the Averaging  Code==&lt;br /&gt;
&lt;br /&gt;
===Finding a Delay Value===&lt;br /&gt;
To quickly find a value for &amp;lt;math&amp;gt; N_{d}&amp;lt;/math&amp;gt;, the minimum number of cycles typically needed for the equilibration of a system of within the lattice and temperature ranges of interest, it was assumed that:&lt;br /&gt;
&lt;br /&gt;
* Larger lattices would require more Monte Carlo steps to reach equilibrium from their initial, random configurations&lt;br /&gt;
&lt;br /&gt;
* Lattices at lower temperatures would require more Monte Carlo steps to reach equilibrium from their initial, random configurations.&lt;br /&gt;
&lt;br /&gt;
Therefore, an initial value for &amp;lt;math&amp;gt; N_{d}&amp;lt;/math&amp;gt; was found for a &amp;lt;math&amp;gt; 128\times128 &amp;lt;/math&amp;gt; lattice at a temperature of &amp;lt;math&amp;gt;0.5&amp;lt;/math&amp;gt; reduced temperature units.&lt;br /&gt;
*&amp;lt;math&amp;gt; N_{d} = 185000 &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
By this number of steps, all smaller lattices at all higher temperatures were found to have equilibrated also. Thus, this value of&amp;lt;math&amp;gt; N_{d}&amp;lt;/math&amp;gt; was accepted as an appropriate delay.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:AFinFrame 128 3e5 T= 0.5line.png|400px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
For the 128x128 lattices at T=0.5, equilibration was ensured from 185000 steps onwards.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Smaller lattices at the same temperature did indeed equilibrate more slowly, but all equilibrated within &amp;lt;math&amp;gt; N_{d}&amp;lt;/math&amp;gt; MC steps.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:AFinFrame 64 3e5 T= 0.5line.png|400px]]&lt;br /&gt;
[[File:AFinFrame 32 3e5 T= 0.5line2.png|400px]]&lt;br /&gt;
[[File:AFinFrame 16 3e5 T= 0.5line2.png|400px]]&lt;br /&gt;
[[File:AFinFrame 8 3e5 T= 0.5line.png|400px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The figure below shows the modifications made to IsingLattice.py to incorporate the &amp;lt;math&amp;gt; N_{d} &amp;lt;/math&amp;gt; step delay.&lt;br /&gt;
&lt;br /&gt;
==Running over a Range of Temperatures==&lt;br /&gt;
&lt;br /&gt;
To examine the effect of temperature on the average energy &amp;lt;math&amp;gt; \left\langle E\right\rangle &amp;lt;/math&amp;gt; and average magnetisation &amp;lt;math&amp;gt; \left\langle M\right\rangle &amp;lt;/math&amp;gt; of Ising lattices at equilibrium, the following parameters were used:&lt;br /&gt;
&lt;br /&gt;
* Temperature Range: &amp;lt;math&amp;gt;  0.5 - 5 &amp;lt;/math&amp;gt; reduced units&lt;br /&gt;
* Temperature Interval: &amp;lt;math&amp;gt;0.01&amp;lt;/math&amp;gt; reduced units (&amp;lt;math&amp;gt;450&amp;lt;/math&amp;gt; temperature values)&lt;br /&gt;
* Number of MMC Steps per Temperature value: &amp;lt;math&amp;gt; 2 \times 10^5 &amp;lt;/math&amp;gt; with the aforementioned value of &amp;lt;math&amp;gt; N_{d} = 1.85 \times 10^5 &amp;lt;/math&amp;gt; Monte Carlo steps&lt;br /&gt;
* Lattice Sizes:  &amp;lt;math&amp;gt; 2 \times 2 &amp;lt;/math&amp;gt;, &amp;lt;math&amp;gt; 4 \times 4 &amp;lt;/math&amp;gt; , &amp;lt;math&amp;gt; 8 \times 8 &amp;lt;/math&amp;gt; , &amp;lt;math&amp;gt; 16 \times 16 &amp;lt;/math&amp;gt; , &amp;lt;math&amp;gt; 32 \times 32 &amp;lt;/math&amp;gt; , &amp;lt;math&amp;gt; 64 \times 64 &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Plots of  &amp;lt;math&amp;gt; \left\langle E\right\rangle &amp;lt;/math&amp;gt; and  &amp;lt;math&amp;gt; \left\langle M\right\rangle &amp;lt;/math&amp;gt; per spin as versus temperature are presented below for each lattice size. Errorbars have been implemented to demonstrate how &#039;&#039;well-behaved&#039;&#039; lattice systems of each size are at each temperature, that is, how temperature and lattice size affect the size of the variations in the expected values. For the error calculations, the standard errors, &amp;lt;math&amp;gt; \sigma_\bar{X} &amp;lt;/math&amp;gt;,  in &amp;lt;math&amp;gt; \left\langle E\right\rangle &amp;lt;/math&amp;gt; and  &amp;lt;math&amp;gt; \left\langle M\right\rangle &amp;lt;/math&amp;gt; per spin have been used:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====8x8====&lt;br /&gt;
&lt;br /&gt;
[[File:8x8e+error.png]] [[File:8x8m+error.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
A Python script has been written to generate a plot of &amp;lt;math&amp;gt;\left\langle E\right\rangle&amp;lt;/math&amp;gt; or &amp;lt;math&amp;gt;\left\langle M\right\rangle&amp;lt;/math&amp;gt; against temperature based upon user input. A screenshot of this code has been inserted below.&lt;br /&gt;
&lt;br /&gt;
[[File:ExpectedvsTemp.PNG|200px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=The Effect of System Size=&lt;br /&gt;
&lt;br /&gt;
==Scaling the System Size==&lt;br /&gt;
&lt;br /&gt;
===More Lattice Sizes===&lt;br /&gt;
&lt;br /&gt;
====2x2====&lt;br /&gt;
[[File:2x2e+error.png]] [[File:2x2m+error.png]]&lt;br /&gt;
&lt;br /&gt;
====4x4====&lt;br /&gt;
[[File:4x4e+error.png]] [[File:4x4m+error.png]]&lt;br /&gt;
&lt;br /&gt;
====16x16====&lt;br /&gt;
[[File:16x16e+error.png]] [[File:16x16m+error.png]]&lt;br /&gt;
&lt;br /&gt;
====32x32====&lt;br /&gt;
[[File:32x32e+error.png]] [[File:32x32m+error.png]]&lt;br /&gt;
&lt;br /&gt;
====64x64====&lt;br /&gt;
[[File:64x64e+error.png]] [[File:64x64m+error.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Scrutiny of the plots of average energy per spin for each lattice size reveals an increase in the errorbar width with increasing lattice size. This is most notable in the low temperature region of the plots. Between the &amp;lt;math&amp;gt; 8\times8 &amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt; 16\times16 &amp;lt;/math&amp;gt; lattices, the long range fluctuations become suddenly prominent. The &amp;lt;math&amp;gt;16\times16&amp;lt;/math&amp;gt; lattice is the first (in the range of sizes tested)to clearly capture these fluctuations.&lt;br /&gt;
&lt;br /&gt;
=Determining the Heat Capacity=&lt;br /&gt;
&lt;br /&gt;
==Calculating the Heat Capacity==&lt;br /&gt;
&lt;br /&gt;
===Heat Capacity Derivation===&lt;br /&gt;
Working in the canonical ensemble (constant volume), the heat capacity &amp;lt;math&amp;gt; C_V &amp;lt;/math&amp;gt; is given by:&lt;br /&gt;
&lt;br /&gt;
:&amp;lt;math&amp;gt;C_V = \frac{\partial \left\langle E\right\rangle}{\partial T}_V&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
where &amp;lt;math&amp;gt;\left\langle E\right\rangle&amp;lt;/math&amp;gt; is the average total energy or expected value of the internal energy of the system.&lt;br /&gt;
&lt;br /&gt;
: &amp;lt;math&amp;gt; \left\langle E\right\rangle = - \frac{\partial ln Q}{\partial \beta} = -\frac{1}{Q}\frac{\partial Q}{\partial \beta} &amp;lt;/math&amp;gt;&lt;br /&gt;
where &amp;lt;math&amp;gt; Q&amp;lt;/math&amp;gt; is the partition function for the system of N interacting spins.&lt;br /&gt;
&lt;br /&gt;
By evaluating the second form of the partial derivative with respect to &amp;lt;math&amp;gt; \beta&amp;lt;/math&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \left\langle E\right\rangle = -\frac{1}{Q}\frac{\partial Q}{\partial \beta} = \frac{\Sigma \epsilon_{i} e^{-\beta \epsilon_{i}}}{\Sigma e^{-\beta \epsilon_{i}}} &amp;lt;/math&amp;gt; &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Applying the product rule enables the differentiation of this expression for &amp;lt;math&amp;gt;\left\langle E\right\rangle&amp;lt;/math&amp;gt; with respect to temperature, giving:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\frac{\partial \left\langle E\right\rangle}{\partial T} = \frac{\Sigma \epsilon_{i} \frac{\epsilon_i}{k_BT^2}e^{-\beta \epsilon_{i}}}{\Sigma e^{-\beta \epsilon_{i}}} - \frac{\Sigma \epsilon_i e^{-\beta \epsilon_i}\cdot \frac{\epsilon_i}{k_BT^2}e^{-\beta \epsilon_i}}{(\Sigma e^{-\beta \epsilon_{i}})^2}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\frac{\partial \left\langle E\right\rangle}{\partial T}  = \frac{1}{k_BT^2}\left[\frac{\Sigma \epsilon_i^2 e^{-\beta \epsilon_i}}{\Sigma e^{-\beta \epsilon_i}} - \left(\frac{\Sigma \epsilon_{i} e^{-\beta \epsilon_{i}}}{\Sigma e^{-\beta \epsilon_{i}}}\right)^2\right] &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\frac{\partial \left\langle E\right\rangle}{\partial T}  = \frac{1}{k_BT^2}\left[\left\langle E^2\right\rangle - \left\langle E\right\rangle^2 \right] &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Thus,&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\frac{\partial \left\langle E\right\rangle}{\partial T} = \frac{Var[E]}{k_BT^2} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Heat Capacity versus Temperature===&lt;br /&gt;
Below, a screenshot of the Python script written to produce plots of &amp;lt;math&amp;gt; C_V &amp;lt;/math&amp;gt; against &amp;lt;math&amp;gt; T &amp;lt;/math&amp;gt;, together with the output images of this script.&lt;br /&gt;
 &lt;br /&gt;
[[File:HeatCapScript.PNG]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====2x2====&lt;br /&gt;
[[File:HC2.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====4x4====&lt;br /&gt;
[[File:HC4.png]]&lt;br /&gt;
&lt;br /&gt;
====8x8====&lt;br /&gt;
[[File:HC8.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====16x16====&lt;br /&gt;
[[File:HC16.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====32x32====&lt;br /&gt;
[[File:HC32.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= Locating the Curie Temperature =&lt;br /&gt;
&lt;br /&gt;
===C++ Data Comparison===&lt;br /&gt;
Below a comparison of the &amp;lt;math&amp;gt; C_V &amp;lt;/math&amp;gt; against &amp;lt;math&amp;gt; T &amp;lt;/math&amp;gt; plot generated for the &amp;lt;math&amp;gt; 2 /times 2&amp;lt;/math&amp;gt; to the corresponding C++ data is offered.&lt;br /&gt;
 &lt;br /&gt;
[[File:CHC2.png]]&lt;br /&gt;
&lt;br /&gt;
The data generated by the ILtemperaturerange.py script is a faithful match to the C++ data. However, this is an exceptional case; the plots for all other lattice sizes were found to be very dissimilar, necessitating polynomial fitting.&lt;br /&gt;
&lt;br /&gt;
==Polyfitting of C++ Data==&lt;br /&gt;
&lt;br /&gt;
===Fitting a Polynomial to the Entire Range===&lt;br /&gt;
The following Python script was written to perform a polynomial fit to the entire range of the graph of &amp;lt;math&amp;gt; C_V &amp;lt;/math&amp;gt; against &amp;lt;math&amp;gt; T &amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:HeatCapPoly.PNG]]&lt;br /&gt;
&lt;br /&gt;
Below, the result of the polyfit to the &amp;lt;math&amp;gt; 2/times2&amp;lt;/math&amp;gt; lattice data is offered (for comparison to the previous, non-fitted example).&lt;br /&gt;
&lt;br /&gt;
[[File:15Polyc2x2.png]]&lt;br /&gt;
&lt;br /&gt;
Polynomials with 5 terms and above were found to match the data in the vicinity of the critical region considerably well. Below 7 terms, the &#039;&#039;tails&#039;&#039; of the plot were matched poorly. In the above example, a polynomial of 15 terms was fit to the data.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Fitting a Polynomial to the Critical Region===&lt;br /&gt;
&lt;br /&gt;
The following Python script was written to perform a polynomial fit to the region of interest (the &#039;&#039;critical&#039;&#039; region) of the plots of &amp;lt;math&amp;gt; C_V &amp;lt;/math&amp;gt; against &amp;lt;math&amp;gt; T &amp;lt;/math&amp;gt; to facilitate the discovery of &amp;lt;math&amp;gt; T_C &amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
[[File:HeatCapPolyCrit.PNG]]&lt;br /&gt;
&lt;br /&gt;
An example of the result returned by the script is offered below for the C++ data for the &amp;lt;math&amp;gt; 16\times16&amp;lt;/math&amp;gt; lattice.&lt;br /&gt;
&lt;br /&gt;
[[File:HCPC16,2.6-2.1,5.png]]&lt;br /&gt;
&lt;br /&gt;
=== Python Scripts ===&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
* Frenkel, Daan, et al. Understanding Molecular Simulation : From Algorithms to Applications, Elsevier Science &amp;amp; Technology, 2001&lt;/div&gt;</summary>
		<author><name>Jj1516</name></author>
	</entry>
	<entry>
		<id>https://chemwiki.ch.ic.ac.uk/index.php?title=Rep:JJ1516Ising&amp;diff=736575</id>
		<title>Rep:JJ1516Ising</title>
		<link rel="alternate" type="text/html" href="https://chemwiki.ch.ic.ac.uk/index.php?title=Rep:JJ1516Ising&amp;diff=736575"/>
		<updated>2018-11-20T22:38:20Z</updated>

		<summary type="html">&lt;p&gt;Jj1516: /* Fitting a Polynomial to the Critical Region */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Ex Script Link:&lt;br /&gt;
https://wiki.ch.ic.ac.uk/wiki/index.php?title=Third_year_CMP_compulsory_experiment&lt;br /&gt;
&lt;br /&gt;
= Introduction to the Ising Model =&lt;br /&gt;
&lt;br /&gt;
== The Model ==&lt;br /&gt;
&lt;br /&gt;
=== Minimum Energy State ===&lt;br /&gt;
====Minimum Interaction Energy====&lt;br /&gt;
The interaction energy of an Ising lattice is given by:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;E = -\frac{1}{2}J\displaystyle\sum_{i}^{N} \displaystyle\sum_{j\;\in\;{neighbours}\;(i)} \!\!\!\!\!\!\!\!\!\!\!\!s_{i}s_{j}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In an Ising lattice with D dimensions and periodic boundary conditions, a given spin &amp;lt;math&amp;gt; s_i&amp;lt;/math&amp;gt; has 2D neighbours.&lt;br /&gt;
&lt;br /&gt;
The minimum interaction energy is achieved when all spins in the lattice are aligned (all ↑ or all ↓). As  such, any spin &amp;lt;math&amp;gt; s_i&amp;lt;/math&amp;gt; must be aligned with all 2D of its neighbours. That is, &amp;lt;math&amp;gt;s_{i}s_{j} = 1&amp;lt;/math&amp;gt; for all &amp;lt;math&amp;gt;j&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Therefore, for any &amp;lt;math&amp;gt; s_i&amp;lt;/math&amp;gt;, the sum of its interactions is &amp;lt;math&amp;gt;\displaystyle\sum_{j\;\in\;{neighbours}\;(i)} \!\!\!\!\!\!\!\!\!\!\!\!s_{i}s_{j} = 2D &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
As this is true for all N spins in the lattice, it follows that &amp;lt;math&amp;gt;\displaystyle\sum_{i}^{N} 2D = 2DN&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Thus the minimum interaction energy is given by:&lt;br /&gt;
&lt;br /&gt;
:&amp;lt;math&amp;gt;E_{min} = -\frac{1}{2}J\cdot2DN = - DNJ &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Entropy of the Minimum Energy State====&lt;br /&gt;
&lt;br /&gt;
The entropy of a state is given by:&lt;br /&gt;
&lt;br /&gt;
:&amp;lt;math&amp;gt;S = k\; ln\; \Omega &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Where &amp;lt;math&amp;gt; \Omega &amp;lt;/math&amp;gt; is the multiplicity of the state, the number of degenerate configurations of said state. The minimum energy state is achievable with all spins ↑ or with all spins ↓. In the absence of an external magnetic field, these configurations are degenerate and indistinguishable giving &amp;lt;math&amp;gt; \Omega = 2 &amp;lt;/math&amp;gt; for this state. Therefore,&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; S_{E_{min}}  = k_{B}\; ln\; 2 = 0.693k_{B} = 9.57 \times 10^{-24} J\!\cdot\!\! K^{-1}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Phase Transitions ==&lt;br /&gt;
&lt;br /&gt;
=== Changes to Minimum Energy Configuration ===&lt;br /&gt;
&lt;br /&gt;
====Energy Change ====&lt;br /&gt;
The energy change &amp;lt;math&amp;gt; \Delta E&amp;lt;/math&amp;gt; associated with a single spin &#039;flip&#039; from the lowest energy onfiguration may be calculated by considering the change in the interaction energy with the spin&#039;s neighbours.&lt;br /&gt;
&lt;br /&gt;
Let &amp;lt;math&amp;gt; D = 3, N = 1000 &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\Delta{E} = E_1 - E_0&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;E_1&amp;lt;/math&amp;gt; Interaction energy after one spin has been &#039;flipped&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;E_0&amp;lt;/math&amp;gt; Lowest energy configuration&lt;br /&gt;
&lt;br /&gt;
[[Image:Task 2 table.PNG]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\displaystyle\sum_{interactions} = -2D + 2D(2D-2) + 2D[N-(2D+1)] &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; = 2DN - 8D &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;E_1 = \displaystyle-\frac{1}{2}J\;\sum_{interactions} = 4DJ - DNJ&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\Delta{E} = E_1 - E_0 = 4DJ - DNJ + DNJ = +4DJ = +12J&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This energy change is independent of &amp;lt;math&amp;gt; N&amp;lt;/math&amp;gt; and depends only on the dimension size and the coupling constant &amp;lt;math&amp;gt; J &amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
In this calculation, the following assumption has been made.&lt;br /&gt;
&lt;br /&gt;
* The lattice dimensions are infinite relative to the size of each cell&lt;br /&gt;
&lt;br /&gt;
This allows &#039;&#039;&#039;any&#039;&#039;&#039; cell to be treated as the centre of the lattice. As every cell interacts with 2D neighbours, flipping any cell in the minimum energy configuration results in the same energy change. Alternatively, the periodic boundary conditions of the Ising model remove the necessity for such an assumption. As a consequence, the absence of &amp;lt;math&amp;gt; N &amp;lt;/math&amp;gt; from the resulting energy change is justified.&lt;br /&gt;
&lt;br /&gt;
====Entropy Change====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; S = k_{B}\; ln\; \Omega &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\Omega = \displaystyle\frac{N!}{{N_{\uparrow}!}{N_{\downarrow}!}}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Where &amp;lt;math&amp;gt;N_{x}!&amp;lt;/math&amp;gt; denotes the factorial of the number of spins in spin state &amp;lt;math&amp;gt;x&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\Delta{S} = k_{B}\;ln\;\left(\displaystyle\frac{\Omega_{2}}{\Omega_{1}}\right)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\Omega_{2} = \frac{1000!}{999!1!} = 1000&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \Omega_{1} = \frac{1000!}{1000!} = 1&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\Delta{S} = k_{B}\;ln\;1000 = 9.54 \times 10^{-23} JK^{-1}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\Delta{S_{mol}} = N_{A}k_{B}\;ln\;1000 = 57.4 \,JK^{-1}mol^{-1}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Magnetisation Values of 1D and 2D Lattices===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;M = \sum_i s_i&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====1D Lattice Magnetisation====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;M_{1D} =\;\;+1&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====2D Lattice Magnetisation====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;M_{2D} =\;\;+1&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Magnetisation at 0K====&lt;br /&gt;
&lt;br /&gt;
At 0K, no thermal energy is available to overcome the energetic barriers to spin flipping. Considering the Hemholtz free energy:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; A = E - TS &amp;lt;/math&amp;gt; &lt;br /&gt;
&lt;br /&gt;
A temperature of 0K nullifies the entropic contribution to the free energy. Thus the energetic driving force (which maximises parallel spin interactions) dominates the entropic driving force (which maximises multiplicity of lattice states). For an Ising Lattice with D =  3, N = 1000 at 0K, the alignment of all spins results in the minimum energy configuration  and an overall magnetisation of &amp;lt;math&amp;gt; M = \pm 1000 &amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
= Calculating the Energy and Magnetisation =&lt;br /&gt;
==Modifying the Files==&lt;br /&gt;
&lt;br /&gt;
===Energy and Magnetisation Functions===&lt;br /&gt;
&lt;br /&gt;
====Energy===&lt;br /&gt;
[[File:First_Ene_Method.PNG]]&lt;br /&gt;
&lt;br /&gt;
The above energy method segments a given lattice into lattice cells on the edges, corners or in the bulk of the lattice and calculates the energy interactions with its neighbours as appropriate.&lt;br /&gt;
&lt;br /&gt;
====Magnetisation====&lt;br /&gt;
[[File:First_Mag_Method.PNG]]&lt;br /&gt;
&lt;br /&gt;
The magnetisation method loops over all elements in the array representing the Ising lattice and adds the value of the spin to the magnetisation variable.&lt;br /&gt;
&lt;br /&gt;
==Testing the Files==&lt;br /&gt;
&lt;br /&gt;
===ILCheck.py===&lt;br /&gt;
&lt;br /&gt;
[[File:ILChecks.PNG]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Above, the results of the ILcheck.py script are presented.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= Introduction to the Monte Carlo Simulation =&lt;br /&gt;
==Average Energy and Magnetisation==&lt;br /&gt;
===Configurations of a 100 Spin System===&lt;br /&gt;
For a system of two spins, 4 configurations are possible (↑↑, ↓↓, ↑↓, ↓↑) i.e. &amp;lt;math&amp;gt;2^{2}&amp;lt;/math&amp;gt;. For a system of 100 spins, there are &amp;lt;math&amp;gt;2^{100}&amp;lt;/math&amp;gt; configurations. In the first example, the ↑↑ and ↓↓ are degenerate, as are the ↑↓ and ↓↑ configurations. Therefore, dividing the number of possible configurations by the multiplicity of each configuration (&amp;lt;math&amp;gt;2&amp;lt;/math&amp;gt;) gives the number of non-degenerate configurations. As previously stated, degenerate configurations are indistinguishable in the absence of an external magnetic field.&lt;br /&gt;
&lt;br /&gt;
For 100 spins, this gives &amp;lt;math&amp;gt;\displaystyle\frac{2^{100}}{2} = 6.338 \times 10^{29} &amp;lt;/math&amp;gt; distinguishable configurations.&lt;br /&gt;
&lt;br /&gt;
If processing speed permits &amp;lt;math&amp;gt; 1 \times 10^{9}&amp;lt;/math&amp;gt; calculations each second, the evaluation of a single value of &amp;lt;math&amp;gt;\left\langle M\right\rangle_T&amp;lt;/math&amp;gt; would last &amp;lt;math&amp;gt; 6.338 \times 10^{20} &amp;lt;/math&amp;gt; seconds or &amp;lt;math&amp;gt; 1458 &amp;lt;/math&amp;gt; times the age of the Universe!&lt;br /&gt;
&lt;br /&gt;
==Modifying IsingLattice.py==&lt;br /&gt;
&lt;br /&gt;
===Monte Carlo and Statistics Methods===&lt;br /&gt;
[[File:Monte_Carlo.PNG]]&lt;br /&gt;
&lt;br /&gt;
[[File:stats.PNG]]&lt;br /&gt;
&lt;br /&gt;
The Metropolis Monte Carlo (MMC) algorithm provides a computationally inexpensive path from random initial states to the minimum free energy states of the Ising lattices generated. First, a random 2D Ising lattice is generated. A single random spin within this lattice is &amp;quot;flipped&amp;quot; and the resulting (internal) energy change between these states is measured. Recalling the relationship between the Hemholtz free energy, internal energy and entropy, it follows that a decrease in internal energy also lowers the free energy of the system: thus the configuration change is accepted.&lt;br /&gt;
&lt;br /&gt;
In the case that the spin &amp;quot;flip&amp;quot; does not lower the internal energy, the MMC algorithm tests this configuration change against the Boltzman factor. In the canonical (NVT) ensemble, the free energy of the system is given by:&lt;br /&gt;
&lt;br /&gt;
:&amp;lt;math&amp;gt;A = -k_{B}T\,lnZ_{NVT} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
where Z is the canonical partition function which depends upon &amp;lt;math&amp;gt; e^{-\frac{\Delta E}{k_BT}} &amp;lt;/math&amp;gt;, the Boltzman factor. By choosing a random value in the interval [0,1)from a continuous uniformm probability distribution and rejecting any value of the Boltzman factor less than this value, ###&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Spontaneous Magnetisation===&lt;br /&gt;
&lt;br /&gt;
Below the Curie Temperature, &amp;lt;math&amp;gt; T_{C} &amp;lt;/math&amp;gt;, the energetic driving force dominates the entropic driving force, resulting in a highly ordered system and an overall magnetisation. The spins of the system align in order to maximise favourable coupling interactions rather than adopting a less ordered configuration of higher multiplicity. Therefore, when &amp;lt;math&amp;gt;T &amp;lt; T_C&amp;lt;/math&amp;gt;, the most probable configurations have an overall magnetisation resulting in &amp;lt;math&amp;gt;\left\langle M\right\rangle \neq 0&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
The plots of magnetisation per spin and energy per spin obtained from ILanim.py support this prediction. Below, the plots show that upon equilibration, the system adopts the minimum energy per spin: &amp;lt;math&amp;gt;E_{min_{spin}} = \frac{-NDJ}{N} = -DJ = -2&amp;lt;/math&amp;gt; and exhibits the maximum magnitude of magnetisation per spin: &amp;lt;math&amp;gt;|M_{spin}| = 1&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:2T=1.0.png]]&lt;br /&gt;
[[File:T=1.0.png]]&lt;br /&gt;
[[File:3T=1.0.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
An unknown system error prevented the statistics() function from printing the average values.&lt;br /&gt;
&lt;br /&gt;
=Accelerating the Code=&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Initial Method Speeds===&lt;br /&gt;
Taking 10 repeat measurements for the time taken to perform 2000 Monte Carlo steps resulted in&lt;br /&gt;
&lt;br /&gt;
* An average time of  &amp;lt;math&amp;gt;11.7s&amp;lt;/math&amp;gt; &lt;br /&gt;
* A standard error of &amp;lt;math&amp;gt;0.020s&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Updating Measurement===&lt;br /&gt;
&lt;br /&gt;
NOTE: ILtimetrial.py has been modified to:&lt;br /&gt;
* Perform a requested number of &#039;2000 Monte Carlo Step&#039; measurements&lt;br /&gt;
* Record these measurements in a CSV file&lt;br /&gt;
* Return the mean measuremd time and the Standard Error i.e.   &amp;lt;math&amp;gt; \frac{\sigma}{n} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:TimeTrialMethod.PNG]]&lt;br /&gt;
&lt;br /&gt;
===Updating Energy and Magnetisation Methods===&lt;br /&gt;
[[File:New_Mag_Method.PNG]]&lt;br /&gt;
[[File:New_Ene_Method.PNG]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Updated Method Speeds===&lt;br /&gt;
[[File:TimeTrial.PNG]]&lt;br /&gt;
&lt;br /&gt;
Taking 30 measurements of the time taken to perform 2000 Monte Carlo Steps resulted in:&lt;br /&gt;
&lt;br /&gt;
* An average time of &amp;lt;math&amp;gt;\displaystyle{0.87s}&amp;lt;/math&amp;gt;&lt;br /&gt;
* A standard error of &amp;lt;math&amp;gt;2.5 \times 10^{-3}s&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This represents a 93% decrease in the average computation time from the initial methods.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=The Effect of Temperature=&lt;br /&gt;
&lt;br /&gt;
==Correcting the Averaging  Code==&lt;br /&gt;
&lt;br /&gt;
===Finding a Delay Value===&lt;br /&gt;
To quickly find a value for &amp;lt;math&amp;gt; N_{d}&amp;lt;/math&amp;gt;, the minimum number of cycles typically needed for the equilibration of a system of within the lattice and temperature ranges of interest, it was assumed that:&lt;br /&gt;
&lt;br /&gt;
* Larger lattices would require more Monte Carlo steps to reach equilibrium from their initial, random configurations&lt;br /&gt;
&lt;br /&gt;
* Lattices at lower temperatures would require more Monte Carlo steps to reach equilibrium from their initial, random configurations.&lt;br /&gt;
&lt;br /&gt;
Therefore, an initial value for &amp;lt;math&amp;gt; N_{d}&amp;lt;/math&amp;gt; was found for a &amp;lt;math&amp;gt; 128\times128 &amp;lt;/math&amp;gt; lattice at a temperature of &amp;lt;math&amp;gt;0.5&amp;lt;/math&amp;gt; reduced temperature units.&lt;br /&gt;
*&amp;lt;math&amp;gt; N_{d} = 185000 &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
By this number of steps, all smaller lattices at all higher temperatures were found to have equilibrated also. Thus, this value of&amp;lt;math&amp;gt; N_{d}&amp;lt;/math&amp;gt; was accepted as an appropriate delay.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:AFinFrame 128 3e5 T= 0.5line.png|400px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
For the 128x128 lattices at T=0.5, equilibration was ensured from 185000 steps onwards.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Smaller lattices at the same temperature did indeed equilibrate more slowly, but all equilibrated within &amp;lt;math&amp;gt; N_{d}&amp;lt;/math&amp;gt; MC steps.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:AFinFrame 64 3e5 T= 0.5line.png|400px]]&lt;br /&gt;
[[File:AFinFrame 32 3e5 T= 0.5line2.png|400px]]&lt;br /&gt;
[[File:AFinFrame 16 3e5 T= 0.5line2.png|400px]]&lt;br /&gt;
[[File:AFinFrame 8 3e5 T= 0.5line.png|400px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The figure below shows the modifications made to IsingLattice.py to incorporate the &amp;lt;math&amp;gt; N_{d} &amp;lt;/math&amp;gt; step delay.&lt;br /&gt;
&lt;br /&gt;
==Running over a Range of Temperatures==&lt;br /&gt;
&lt;br /&gt;
To examine the effect of temperature on the average energy &amp;lt;math&amp;gt; \left\langle E\right\rangle &amp;lt;/math&amp;gt; and average magnetisation &amp;lt;math&amp;gt; \left\langle M\right\rangle &amp;lt;/math&amp;gt; of Ising lattices at equilibrium, the following parameters were used:&lt;br /&gt;
&lt;br /&gt;
* Temperature Range: &amp;lt;math&amp;gt;  0.5 - 5 &amp;lt;/math&amp;gt; reduced units&lt;br /&gt;
* Temperature Interval: &amp;lt;math&amp;gt;0.01&amp;lt;/math&amp;gt; reduced units (&amp;lt;math&amp;gt;450&amp;lt;/math&amp;gt; temperature values)&lt;br /&gt;
* Number of MMC Steps per Temperature value: &amp;lt;math&amp;gt; 2 \times 10^5 &amp;lt;/math&amp;gt; with the aforementioned value of &amp;lt;math&amp;gt; N_{d} = 1.85 \times 10^5 &amp;lt;/math&amp;gt; Monte Carlo steps&lt;br /&gt;
* Lattice Sizes:  &amp;lt;math&amp;gt; 2 \times 2 &amp;lt;/math&amp;gt;, &amp;lt;math&amp;gt; 4 \times 4 &amp;lt;/math&amp;gt; , &amp;lt;math&amp;gt; 8 \times 8 &amp;lt;/math&amp;gt; , &amp;lt;math&amp;gt; 16 \times 16 &amp;lt;/math&amp;gt; , &amp;lt;math&amp;gt; 32 \times 32 &amp;lt;/math&amp;gt; , &amp;lt;math&amp;gt; 64 \times 64 &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Plots of  &amp;lt;math&amp;gt; \left\langle E\right\rangle &amp;lt;/math&amp;gt; and  &amp;lt;math&amp;gt; \left\langle M\right\rangle &amp;lt;/math&amp;gt; per spin as versus temperature are presented below for each lattice size. Errorbars have been implemented to demonstrate how &#039;&#039;well-behaved&#039;&#039; lattice systems of each size are at each temperature, that is, how temperature and lattice size affect the size of the variations in the expected values. For the error calculations, the standard errors, &amp;lt;math&amp;gt; \sigma_\bar{X} &amp;lt;/math&amp;gt;,  in &amp;lt;math&amp;gt; \left\langle E\right\rangle &amp;lt;/math&amp;gt; and  &amp;lt;math&amp;gt; \left\langle M\right\rangle &amp;lt;/math&amp;gt; per spin have been used:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====8x8====&lt;br /&gt;
&lt;br /&gt;
[[File:8x8e+error.png]] [[File:8x8m+error.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
A Python script has been written to generate a plot of &amp;lt;math&amp;gt;\left\langle E\right\rangle&amp;lt;/math&amp;gt; or &amp;lt;math&amp;gt;\left\langle M\right\rangle&amp;lt;/math&amp;gt; against temperature based upon user input. A screenshot of this code has been inserted below.&lt;br /&gt;
&lt;br /&gt;
[[File:ExpectedvsTemp.PNG|200px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=The Effect of System Size=&lt;br /&gt;
&lt;br /&gt;
==Scaling the System Size==&lt;br /&gt;
&lt;br /&gt;
===More Lattice Sizes===&lt;br /&gt;
&lt;br /&gt;
====2x2====&lt;br /&gt;
[[File:2x2e+error.png]] [[File:2x2m+error.png]]&lt;br /&gt;
&lt;br /&gt;
====4x4====&lt;br /&gt;
[[File:4x4e+error.png]] [[File:4x4m+error.png]]&lt;br /&gt;
&lt;br /&gt;
====16x16====&lt;br /&gt;
[[File:16x16e+error.png]] [[File:16x16m+error.png]]&lt;br /&gt;
&lt;br /&gt;
====32x32====&lt;br /&gt;
[[File:32x32e+error.png]] [[File:32x32m+error.png]]&lt;br /&gt;
&lt;br /&gt;
====64x64====&lt;br /&gt;
[[File:64x64e+error.png]] [[File:64x64m+error.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Scrutiny of the plots of average energy per spin for each lattice size reveals an increase in the errorbar width with increasing lattice size. This is most notable in the low temperature region of the plots. Between the &amp;lt;math&amp;gt; 8\times8 &amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt; 16\times16 &amp;lt;/math&amp;gt; lattices, the long range fluctuations become suddenly prominent. The &amp;lt;math&amp;gt;16\times16&amp;lt;/math&amp;gt; lattice is the first (in the range of sizes tested)to clearly capture these fluctuations.&lt;br /&gt;
&lt;br /&gt;
=Determining the Heat Capacity=&lt;br /&gt;
&lt;br /&gt;
==Calculating the Heat Capacity==&lt;br /&gt;
&lt;br /&gt;
===Heat Capacity Derivation===&lt;br /&gt;
Working in the canonical ensemble (constant volume), the heat capacity &amp;lt;math&amp;gt; C_V &amp;lt;/math&amp;gt; is given by:&lt;br /&gt;
&lt;br /&gt;
:&amp;lt;math&amp;gt;C_V = \frac{\partial \left\langle E\right\rangle}{\partial T}_V&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
where &amp;lt;math&amp;gt;\left\langle E\right\rangle&amp;lt;/math&amp;gt; is the average total energy or expected value of the internal energy of the system.&lt;br /&gt;
&lt;br /&gt;
: &amp;lt;math&amp;gt; \left\langle E\right\rangle = - \frac{\partial ln Q}{\partial \beta} = -\frac{1}{Q}\frac{\partial Q}{\partial \beta} &amp;lt;/math&amp;gt;&lt;br /&gt;
where &amp;lt;math&amp;gt; Q&amp;lt;/math&amp;gt; is the partition function for the system of N interacting spins.&lt;br /&gt;
&lt;br /&gt;
By evaluating the second form of the partial derivative with respect to &amp;lt;math&amp;gt; \beta&amp;lt;/math&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \left\langle E\right\rangle = -\frac{1}{Q}\frac{\partial Q}{\partial \beta} = \frac{\Sigma \epsilon_{i} e^{-\beta \epsilon_{i}}}{\Sigma e^{-\beta \epsilon_{i}}} &amp;lt;/math&amp;gt; &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Applying the product rule enables the differentiation of this expression for &amp;lt;math&amp;gt;\left\langle E\right\rangle&amp;lt;/math&amp;gt; with respect to temperature, giving:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\frac{\partial \left\langle E\right\rangle}{\partial T} = \frac{\Sigma \epsilon_{i} \frac{\epsilon_i}{k_BT^2}e^{-\beta \epsilon_{i}}}{\Sigma e^{-\beta \epsilon_{i}}} - \frac{\Sigma \epsilon_i e^{-\beta \epsilon_i}\cdot \frac{\epsilon_i}{k_BT^2}e^{-\beta \epsilon_i}}{(\Sigma e^{-\beta \epsilon_{i}})^2}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\frac{\partial \left\langle E\right\rangle}{\partial T}  = \frac{1}{k_BT^2}\left[\frac{\Sigma \epsilon_i^2 e^{-\beta \epsilon_i}}{\Sigma e^{-\beta \epsilon_i}} - \left(\frac{\Sigma \epsilon_{i} e^{-\beta \epsilon_{i}}}{\Sigma e^{-\beta \epsilon_{i}}}\right)^2\right] &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\frac{\partial \left\langle E\right\rangle}{\partial T}  = \frac{1}{k_BT^2}\left[\left\langle E^2\right\rangle - \left\langle E\right\rangle^2 \right] &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Thus,&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\frac{\partial \left\langle E\right\rangle}{\partial T} = \frac{Var[E]}{k_BT^2} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Heat Capacity versus Temperature===&lt;br /&gt;
Below, a screenshot of the Python script written to produce plots of &amp;lt;math&amp;gt; C_V &amp;lt;/math&amp;gt; against &amp;lt;math&amp;gt; T &amp;lt;/math&amp;gt;, together with the output images of this script.&lt;br /&gt;
 &lt;br /&gt;
[[File:HeatCapScript.PNG]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====2x2====&lt;br /&gt;
[[File:HC2.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====4x4====&lt;br /&gt;
[[File:HC4.png]]&lt;br /&gt;
&lt;br /&gt;
====8x8====&lt;br /&gt;
[[File:HC8.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====16x16====&lt;br /&gt;
[[File:HC16.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====32x32====&lt;br /&gt;
[[File:HC32.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= Locating the Curie Temperature =&lt;br /&gt;
&lt;br /&gt;
===C++ Data Comparison===&lt;br /&gt;
Below a comparison of the &amp;lt;math&amp;gt; C_V &amp;lt;/math&amp;gt; against &amp;lt;math&amp;gt; T &amp;lt;/math&amp;gt; plot generated for the &amp;lt;math&amp;gt; 2 /times 2&amp;lt;/math&amp;gt; to the corresponding C++ data is offered.&lt;br /&gt;
 &lt;br /&gt;
[[File:CHC2.png]]&lt;br /&gt;
&lt;br /&gt;
The data generated by the ILtemperaturerange.py script is a faithful match to the C++ data. However, this is an exceptional case; the plots for all other lattice sizes were found to be very dissimilar, necessitating polynomial fitting.&lt;br /&gt;
&lt;br /&gt;
==Polyfitting of C++ Data==&lt;br /&gt;
&lt;br /&gt;
===Fitting a Polynomial to the Entire Range===&lt;br /&gt;
The following Python script was written to perform a polynomial fit to the entire range of the graph of &amp;lt;math&amp;gt; C_V &amp;lt;/math&amp;gt; against &amp;lt;math&amp;gt; T &amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:HeatCapPoly.PNG]]&lt;br /&gt;
&lt;br /&gt;
Below, the result of the polyfit to the &amp;lt;math&amp;gt; 2/times2&amp;lt;/math&amp;gt; lattice data is offered (for comparison to the previous, non-fitted example).&lt;br /&gt;
&lt;br /&gt;
[[File:15Polyc2x2.png]]&lt;br /&gt;
&lt;br /&gt;
Polynomials with 5 terms and above were found to match the data in the vicinity of the critical region considerably well. Below 7 terms, the &#039;&#039;tails&#039;&#039; of the plot were matched poorly. In the above example, a polynomial of 15 terms was fit to the data.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Fitting a Polynomial to the Critical Region===&lt;br /&gt;
&lt;br /&gt;
The following Python script was written to perform a polynomial fit to the region of interest (the &#039;&#039;critical&#039;&#039; region) of the plots of &amp;lt;math&amp;gt; C_V &amp;lt;/math&amp;gt; against &amp;lt;math&amp;gt; T &amp;lt;/math&amp;gt; to facilitate the discovery of &amp;lt;math&amp;gt; T_C &amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
[[File:HeatCapPolyCrit.PNG]]&lt;br /&gt;
&lt;br /&gt;
An example of the result returned by the script is offered below for the C++ data for the &amp;lt;math&amp;gt; 16\times16&amp;lt;/math&amp;gt; lattice.&lt;br /&gt;
&lt;br /&gt;
=== Python Scripts ===&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
* Frenkel, Daan, et al. Understanding Molecular Simulation : From Algorithms to Applications, Elsevier Science &amp;amp; Technology, 2001&lt;/div&gt;</summary>
		<author><name>Jj1516</name></author>
	</entry>
	<entry>
		<id>https://chemwiki.ch.ic.ac.uk/index.php?title=File:HCPC16,2.6-2.1,5.png&amp;diff=736574</id>
		<title>File:HCPC16,2.6-2.1,5.png</title>
		<link rel="alternate" type="text/html" href="https://chemwiki.ch.ic.ac.uk/index.php?title=File:HCPC16,2.6-2.1,5.png&amp;diff=736574"/>
		<updated>2018-11-20T22:37:34Z</updated>

		<summary type="html">&lt;p&gt;Jj1516: Jj1516 uploaded a new version of File:HCPC16,2.6-2.1,5.png&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Jj1516</name></author>
	</entry>
	<entry>
		<id>https://chemwiki.ch.ic.ac.uk/index.php?title=Rep:JJ1516Ising&amp;diff=736573</id>
		<title>Rep:JJ1516Ising</title>
		<link rel="alternate" type="text/html" href="https://chemwiki.ch.ic.ac.uk/index.php?title=Rep:JJ1516Ising&amp;diff=736573"/>
		<updated>2018-11-20T22:35:53Z</updated>

		<summary type="html">&lt;p&gt;Jj1516: /* C++ Data Comparison */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Ex Script Link:&lt;br /&gt;
https://wiki.ch.ic.ac.uk/wiki/index.php?title=Third_year_CMP_compulsory_experiment&lt;br /&gt;
&lt;br /&gt;
= Introduction to the Ising Model =&lt;br /&gt;
&lt;br /&gt;
== The Model ==&lt;br /&gt;
&lt;br /&gt;
=== Minimum Energy State ===&lt;br /&gt;
====Minimum Interaction Energy====&lt;br /&gt;
The interaction energy of an Ising lattice is given by:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;E = -\frac{1}{2}J\displaystyle\sum_{i}^{N} \displaystyle\sum_{j\;\in\;{neighbours}\;(i)} \!\!\!\!\!\!\!\!\!\!\!\!s_{i}s_{j}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In an Ising lattice with D dimensions and periodic boundary conditions, a given spin &amp;lt;math&amp;gt; s_i&amp;lt;/math&amp;gt; has 2D neighbours.&lt;br /&gt;
&lt;br /&gt;
The minimum interaction energy is achieved when all spins in the lattice are aligned (all ↑ or all ↓). As  such, any spin &amp;lt;math&amp;gt; s_i&amp;lt;/math&amp;gt; must be aligned with all 2D of its neighbours. That is, &amp;lt;math&amp;gt;s_{i}s_{j} = 1&amp;lt;/math&amp;gt; for all &amp;lt;math&amp;gt;j&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Therefore, for any &amp;lt;math&amp;gt; s_i&amp;lt;/math&amp;gt;, the sum of its interactions is &amp;lt;math&amp;gt;\displaystyle\sum_{j\;\in\;{neighbours}\;(i)} \!\!\!\!\!\!\!\!\!\!\!\!s_{i}s_{j} = 2D &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
As this is true for all N spins in the lattice, it follows that &amp;lt;math&amp;gt;\displaystyle\sum_{i}^{N} 2D = 2DN&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Thus the minimum interaction energy is given by:&lt;br /&gt;
&lt;br /&gt;
:&amp;lt;math&amp;gt;E_{min} = -\frac{1}{2}J\cdot2DN = - DNJ &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Entropy of the Minimum Energy State====&lt;br /&gt;
&lt;br /&gt;
The entropy of a state is given by:&lt;br /&gt;
&lt;br /&gt;
:&amp;lt;math&amp;gt;S = k\; ln\; \Omega &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Where &amp;lt;math&amp;gt; \Omega &amp;lt;/math&amp;gt; is the multiplicity of the state, the number of degenerate configurations of said state. The minimum energy state is achievable with all spins ↑ or with all spins ↓. In the absence of an external magnetic field, these configurations are degenerate and indistinguishable giving &amp;lt;math&amp;gt; \Omega = 2 &amp;lt;/math&amp;gt; for this state. Therefore,&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; S_{E_{min}}  = k_{B}\; ln\; 2 = 0.693k_{B} = 9.57 \times 10^{-24} J\!\cdot\!\! K^{-1}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Phase Transitions ==&lt;br /&gt;
&lt;br /&gt;
=== Changes to Minimum Energy Configuration ===&lt;br /&gt;
&lt;br /&gt;
====Energy Change ====&lt;br /&gt;
The energy change &amp;lt;math&amp;gt; \Delta E&amp;lt;/math&amp;gt; associated with a single spin &#039;flip&#039; from the lowest energy onfiguration may be calculated by considering the change in the interaction energy with the spin&#039;s neighbours.&lt;br /&gt;
&lt;br /&gt;
Let &amp;lt;math&amp;gt; D = 3, N = 1000 &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\Delta{E} = E_1 - E_0&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;E_1&amp;lt;/math&amp;gt; Interaction energy after one spin has been &#039;flipped&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;E_0&amp;lt;/math&amp;gt; Lowest energy configuration&lt;br /&gt;
&lt;br /&gt;
[[Image:Task 2 table.PNG]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\displaystyle\sum_{interactions} = -2D + 2D(2D-2) + 2D[N-(2D+1)] &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; = 2DN - 8D &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;E_1 = \displaystyle-\frac{1}{2}J\;\sum_{interactions} = 4DJ - DNJ&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\Delta{E} = E_1 - E_0 = 4DJ - DNJ + DNJ = +4DJ = +12J&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This energy change is independent of &amp;lt;math&amp;gt; N&amp;lt;/math&amp;gt; and depends only on the dimension size and the coupling constant &amp;lt;math&amp;gt; J &amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
In this calculation, the following assumption has been made.&lt;br /&gt;
&lt;br /&gt;
* The lattice dimensions are infinite relative to the size of each cell&lt;br /&gt;
&lt;br /&gt;
This allows &#039;&#039;&#039;any&#039;&#039;&#039; cell to be treated as the centre of the lattice. As every cell interacts with 2D neighbours, flipping any cell in the minimum energy configuration results in the same energy change. Alternatively, the periodic boundary conditions of the Ising model remove the necessity for such an assumption. As a consequence, the absence of &amp;lt;math&amp;gt; N &amp;lt;/math&amp;gt; from the resulting energy change is justified.&lt;br /&gt;
&lt;br /&gt;
====Entropy Change====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; S = k_{B}\; ln\; \Omega &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\Omega = \displaystyle\frac{N!}{{N_{\uparrow}!}{N_{\downarrow}!}}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Where &amp;lt;math&amp;gt;N_{x}!&amp;lt;/math&amp;gt; denotes the factorial of the number of spins in spin state &amp;lt;math&amp;gt;x&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\Delta{S} = k_{B}\;ln\;\left(\displaystyle\frac{\Omega_{2}}{\Omega_{1}}\right)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\Omega_{2} = \frac{1000!}{999!1!} = 1000&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \Omega_{1} = \frac{1000!}{1000!} = 1&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\Delta{S} = k_{B}\;ln\;1000 = 9.54 \times 10^{-23} JK^{-1}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\Delta{S_{mol}} = N_{A}k_{B}\;ln\;1000 = 57.4 \,JK^{-1}mol^{-1}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Magnetisation Values of 1D and 2D Lattices===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;M = \sum_i s_i&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====1D Lattice Magnetisation====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;M_{1D} =\;\;+1&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====2D Lattice Magnetisation====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;M_{2D} =\;\;+1&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Magnetisation at 0K====&lt;br /&gt;
&lt;br /&gt;
At 0K, no thermal energy is available to overcome the energetic barriers to spin flipping. Considering the Hemholtz free energy:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; A = E - TS &amp;lt;/math&amp;gt; &lt;br /&gt;
&lt;br /&gt;
A temperature of 0K nullifies the entropic contribution to the free energy. Thus the energetic driving force (which maximises parallel spin interactions) dominates the entropic driving force (which maximises multiplicity of lattice states). For an Ising Lattice with D =  3, N = 1000 at 0K, the alignment of all spins results in the minimum energy configuration  and an overall magnetisation of &amp;lt;math&amp;gt; M = \pm 1000 &amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
= Calculating the Energy and Magnetisation =&lt;br /&gt;
==Modifying the Files==&lt;br /&gt;
&lt;br /&gt;
===Energy and Magnetisation Functions===&lt;br /&gt;
&lt;br /&gt;
====Energy===&lt;br /&gt;
[[File:First_Ene_Method.PNG]]&lt;br /&gt;
&lt;br /&gt;
The above energy method segments a given lattice into lattice cells on the edges, corners or in the bulk of the lattice and calculates the energy interactions with its neighbours as appropriate.&lt;br /&gt;
&lt;br /&gt;
====Magnetisation====&lt;br /&gt;
[[File:First_Mag_Method.PNG]]&lt;br /&gt;
&lt;br /&gt;
The magnetisation method loops over all elements in the array representing the Ising lattice and adds the value of the spin to the magnetisation variable.&lt;br /&gt;
&lt;br /&gt;
==Testing the Files==&lt;br /&gt;
&lt;br /&gt;
===ILCheck.py===&lt;br /&gt;
&lt;br /&gt;
[[File:ILChecks.PNG]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Above, the results of the ILcheck.py script are presented.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= Introduction to the Monte Carlo Simulation =&lt;br /&gt;
==Average Energy and Magnetisation==&lt;br /&gt;
===Configurations of a 100 Spin System===&lt;br /&gt;
For a system of two spins, 4 configurations are possible (↑↑, ↓↓, ↑↓, ↓↑) i.e. &amp;lt;math&amp;gt;2^{2}&amp;lt;/math&amp;gt;. For a system of 100 spins, there are &amp;lt;math&amp;gt;2^{100}&amp;lt;/math&amp;gt; configurations. In the first example, the ↑↑ and ↓↓ are degenerate, as are the ↑↓ and ↓↑ configurations. Therefore, dividing the number of possible configurations by the multiplicity of each configuration (&amp;lt;math&amp;gt;2&amp;lt;/math&amp;gt;) gives the number of non-degenerate configurations. As previously stated, degenerate configurations are indistinguishable in the absence of an external magnetic field.&lt;br /&gt;
&lt;br /&gt;
For 100 spins, this gives &amp;lt;math&amp;gt;\displaystyle\frac{2^{100}}{2} = 6.338 \times 10^{29} &amp;lt;/math&amp;gt; distinguishable configurations.&lt;br /&gt;
&lt;br /&gt;
If processing speed permits &amp;lt;math&amp;gt; 1 \times 10^{9}&amp;lt;/math&amp;gt; calculations each second, the evaluation of a single value of &amp;lt;math&amp;gt;\left\langle M\right\rangle_T&amp;lt;/math&amp;gt; would last &amp;lt;math&amp;gt; 6.338 \times 10^{20} &amp;lt;/math&amp;gt; seconds or &amp;lt;math&amp;gt; 1458 &amp;lt;/math&amp;gt; times the age of the Universe!&lt;br /&gt;
&lt;br /&gt;
==Modifying IsingLattice.py==&lt;br /&gt;
&lt;br /&gt;
===Monte Carlo and Statistics Methods===&lt;br /&gt;
[[File:Monte_Carlo.PNG]]&lt;br /&gt;
&lt;br /&gt;
[[File:stats.PNG]]&lt;br /&gt;
&lt;br /&gt;
The Metropolis Monte Carlo (MMC) algorithm provides a computationally inexpensive path from random initial states to the minimum free energy states of the Ising lattices generated. First, a random 2D Ising lattice is generated. A single random spin within this lattice is &amp;quot;flipped&amp;quot; and the resulting (internal) energy change between these states is measured. Recalling the relationship between the Hemholtz free energy, internal energy and entropy, it follows that a decrease in internal energy also lowers the free energy of the system: thus the configuration change is accepted.&lt;br /&gt;
&lt;br /&gt;
In the case that the spin &amp;quot;flip&amp;quot; does not lower the internal energy, the MMC algorithm tests this configuration change against the Boltzman factor. In the canonical (NVT) ensemble, the free energy of the system is given by:&lt;br /&gt;
&lt;br /&gt;
:&amp;lt;math&amp;gt;A = -k_{B}T\,lnZ_{NVT} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
where Z is the canonical partition function which depends upon &amp;lt;math&amp;gt; e^{-\frac{\Delta E}{k_BT}} &amp;lt;/math&amp;gt;, the Boltzman factor. By choosing a random value in the interval [0,1)from a continuous uniformm probability distribution and rejecting any value of the Boltzman factor less than this value, ###&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Spontaneous Magnetisation===&lt;br /&gt;
&lt;br /&gt;
Below the Curie Temperature, &amp;lt;math&amp;gt; T_{C} &amp;lt;/math&amp;gt;, the energetic driving force dominates the entropic driving force, resulting in a highly ordered system and an overall magnetisation. The spins of the system align in order to maximise favourable coupling interactions rather than adopting a less ordered configuration of higher multiplicity. Therefore, when &amp;lt;math&amp;gt;T &amp;lt; T_C&amp;lt;/math&amp;gt;, the most probable configurations have an overall magnetisation resulting in &amp;lt;math&amp;gt;\left\langle M\right\rangle \neq 0&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
The plots of magnetisation per spin and energy per spin obtained from ILanim.py support this prediction. Below, the plots show that upon equilibration, the system adopts the minimum energy per spin: &amp;lt;math&amp;gt;E_{min_{spin}} = \frac{-NDJ}{N} = -DJ = -2&amp;lt;/math&amp;gt; and exhibits the maximum magnitude of magnetisation per spin: &amp;lt;math&amp;gt;|M_{spin}| = 1&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:2T=1.0.png]]&lt;br /&gt;
[[File:T=1.0.png]]&lt;br /&gt;
[[File:3T=1.0.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
An unknown system error prevented the statistics() function from printing the average values.&lt;br /&gt;
&lt;br /&gt;
=Accelerating the Code=&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Initial Method Speeds===&lt;br /&gt;
Taking 10 repeat measurements for the time taken to perform 2000 Monte Carlo steps resulted in&lt;br /&gt;
&lt;br /&gt;
* An average time of  &amp;lt;math&amp;gt;11.7s&amp;lt;/math&amp;gt; &lt;br /&gt;
* A standard error of &amp;lt;math&amp;gt;0.020s&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Updating Measurement===&lt;br /&gt;
&lt;br /&gt;
NOTE: ILtimetrial.py has been modified to:&lt;br /&gt;
* Perform a requested number of &#039;2000 Monte Carlo Step&#039; measurements&lt;br /&gt;
* Record these measurements in a CSV file&lt;br /&gt;
* Return the mean measuremd time and the Standard Error i.e.   &amp;lt;math&amp;gt; \frac{\sigma}{n} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:TimeTrialMethod.PNG]]&lt;br /&gt;
&lt;br /&gt;
===Updating Energy and Magnetisation Methods===&lt;br /&gt;
[[File:New_Mag_Method.PNG]]&lt;br /&gt;
[[File:New_Ene_Method.PNG]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Updated Method Speeds===&lt;br /&gt;
[[File:TimeTrial.PNG]]&lt;br /&gt;
&lt;br /&gt;
Taking 30 measurements of the time taken to perform 2000 Monte Carlo Steps resulted in:&lt;br /&gt;
&lt;br /&gt;
* An average time of &amp;lt;math&amp;gt;\displaystyle{0.87s}&amp;lt;/math&amp;gt;&lt;br /&gt;
* A standard error of &amp;lt;math&amp;gt;2.5 \times 10^{-3}s&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This represents a 93% decrease in the average computation time from the initial methods.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=The Effect of Temperature=&lt;br /&gt;
&lt;br /&gt;
==Correcting the Averaging  Code==&lt;br /&gt;
&lt;br /&gt;
===Finding a Delay Value===&lt;br /&gt;
To quickly find a value for &amp;lt;math&amp;gt; N_{d}&amp;lt;/math&amp;gt;, the minimum number of cycles typically needed for the equilibration of a system of within the lattice and temperature ranges of interest, it was assumed that:&lt;br /&gt;
&lt;br /&gt;
* Larger lattices would require more Monte Carlo steps to reach equilibrium from their initial, random configurations&lt;br /&gt;
&lt;br /&gt;
* Lattices at lower temperatures would require more Monte Carlo steps to reach equilibrium from their initial, random configurations.&lt;br /&gt;
&lt;br /&gt;
Therefore, an initial value for &amp;lt;math&amp;gt; N_{d}&amp;lt;/math&amp;gt; was found for a &amp;lt;math&amp;gt; 128\times128 &amp;lt;/math&amp;gt; lattice at a temperature of &amp;lt;math&amp;gt;0.5&amp;lt;/math&amp;gt; reduced temperature units.&lt;br /&gt;
*&amp;lt;math&amp;gt; N_{d} = 185000 &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
By this number of steps, all smaller lattices at all higher temperatures were found to have equilibrated also. Thus, this value of&amp;lt;math&amp;gt; N_{d}&amp;lt;/math&amp;gt; was accepted as an appropriate delay.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:AFinFrame 128 3e5 T= 0.5line.png|400px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
For the 128x128 lattices at T=0.5, equilibration was ensured from 185000 steps onwards.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Smaller lattices at the same temperature did indeed equilibrate more slowly, but all equilibrated within &amp;lt;math&amp;gt; N_{d}&amp;lt;/math&amp;gt; MC steps.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:AFinFrame 64 3e5 T= 0.5line.png|400px]]&lt;br /&gt;
[[File:AFinFrame 32 3e5 T= 0.5line2.png|400px]]&lt;br /&gt;
[[File:AFinFrame 16 3e5 T= 0.5line2.png|400px]]&lt;br /&gt;
[[File:AFinFrame 8 3e5 T= 0.5line.png|400px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The figure below shows the modifications made to IsingLattice.py to incorporate the &amp;lt;math&amp;gt; N_{d} &amp;lt;/math&amp;gt; step delay.&lt;br /&gt;
&lt;br /&gt;
==Running over a Range of Temperatures==&lt;br /&gt;
&lt;br /&gt;
To examine the effect of temperature on the average energy &amp;lt;math&amp;gt; \left\langle E\right\rangle &amp;lt;/math&amp;gt; and average magnetisation &amp;lt;math&amp;gt; \left\langle M\right\rangle &amp;lt;/math&amp;gt; of Ising lattices at equilibrium, the following parameters were used:&lt;br /&gt;
&lt;br /&gt;
* Temperature Range: &amp;lt;math&amp;gt;  0.5 - 5 &amp;lt;/math&amp;gt; reduced units&lt;br /&gt;
* Temperature Interval: &amp;lt;math&amp;gt;0.01&amp;lt;/math&amp;gt; reduced units (&amp;lt;math&amp;gt;450&amp;lt;/math&amp;gt; temperature values)&lt;br /&gt;
* Number of MMC Steps per Temperature value: &amp;lt;math&amp;gt; 2 \times 10^5 &amp;lt;/math&amp;gt; with the aforementioned value of &amp;lt;math&amp;gt; N_{d} = 1.85 \times 10^5 &amp;lt;/math&amp;gt; Monte Carlo steps&lt;br /&gt;
* Lattice Sizes:  &amp;lt;math&amp;gt; 2 \times 2 &amp;lt;/math&amp;gt;, &amp;lt;math&amp;gt; 4 \times 4 &amp;lt;/math&amp;gt; , &amp;lt;math&amp;gt; 8 \times 8 &amp;lt;/math&amp;gt; , &amp;lt;math&amp;gt; 16 \times 16 &amp;lt;/math&amp;gt; , &amp;lt;math&amp;gt; 32 \times 32 &amp;lt;/math&amp;gt; , &amp;lt;math&amp;gt; 64 \times 64 &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Plots of  &amp;lt;math&amp;gt; \left\langle E\right\rangle &amp;lt;/math&amp;gt; and  &amp;lt;math&amp;gt; \left\langle M\right\rangle &amp;lt;/math&amp;gt; per spin as versus temperature are presented below for each lattice size. Errorbars have been implemented to demonstrate how &#039;&#039;well-behaved&#039;&#039; lattice systems of each size are at each temperature, that is, how temperature and lattice size affect the size of the variations in the expected values. For the error calculations, the standard errors, &amp;lt;math&amp;gt; \sigma_\bar{X} &amp;lt;/math&amp;gt;,  in &amp;lt;math&amp;gt; \left\langle E\right\rangle &amp;lt;/math&amp;gt; and  &amp;lt;math&amp;gt; \left\langle M\right\rangle &amp;lt;/math&amp;gt; per spin have been used:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====8x8====&lt;br /&gt;
&lt;br /&gt;
[[File:8x8e+error.png]] [[File:8x8m+error.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
A Python script has been written to generate a plot of &amp;lt;math&amp;gt;\left\langle E\right\rangle&amp;lt;/math&amp;gt; or &amp;lt;math&amp;gt;\left\langle M\right\rangle&amp;lt;/math&amp;gt; against temperature based upon user input. A screenshot of this code has been inserted below.&lt;br /&gt;
&lt;br /&gt;
[[File:ExpectedvsTemp.PNG|200px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=The Effect of System Size=&lt;br /&gt;
&lt;br /&gt;
==Scaling the System Size==&lt;br /&gt;
&lt;br /&gt;
===More Lattice Sizes===&lt;br /&gt;
&lt;br /&gt;
====2x2====&lt;br /&gt;
[[File:2x2e+error.png]] [[File:2x2m+error.png]]&lt;br /&gt;
&lt;br /&gt;
====4x4====&lt;br /&gt;
[[File:4x4e+error.png]] [[File:4x4m+error.png]]&lt;br /&gt;
&lt;br /&gt;
====16x16====&lt;br /&gt;
[[File:16x16e+error.png]] [[File:16x16m+error.png]]&lt;br /&gt;
&lt;br /&gt;
====32x32====&lt;br /&gt;
[[File:32x32e+error.png]] [[File:32x32m+error.png]]&lt;br /&gt;
&lt;br /&gt;
====64x64====&lt;br /&gt;
[[File:64x64e+error.png]] [[File:64x64m+error.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Scrutiny of the plots of average energy per spin for each lattice size reveals an increase in the errorbar width with increasing lattice size. This is most notable in the low temperature region of the plots. Between the &amp;lt;math&amp;gt; 8\times8 &amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt; 16\times16 &amp;lt;/math&amp;gt; lattices, the long range fluctuations become suddenly prominent. The &amp;lt;math&amp;gt;16\times16&amp;lt;/math&amp;gt; lattice is the first (in the range of sizes tested)to clearly capture these fluctuations.&lt;br /&gt;
&lt;br /&gt;
=Determining the Heat Capacity=&lt;br /&gt;
&lt;br /&gt;
==Calculating the Heat Capacity==&lt;br /&gt;
&lt;br /&gt;
===Heat Capacity Derivation===&lt;br /&gt;
Working in the canonical ensemble (constant volume), the heat capacity &amp;lt;math&amp;gt; C_V &amp;lt;/math&amp;gt; is given by:&lt;br /&gt;
&lt;br /&gt;
:&amp;lt;math&amp;gt;C_V = \frac{\partial \left\langle E\right\rangle}{\partial T}_V&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
where &amp;lt;math&amp;gt;\left\langle E\right\rangle&amp;lt;/math&amp;gt; is the average total energy or expected value of the internal energy of the system.&lt;br /&gt;
&lt;br /&gt;
: &amp;lt;math&amp;gt; \left\langle E\right\rangle = - \frac{\partial ln Q}{\partial \beta} = -\frac{1}{Q}\frac{\partial Q}{\partial \beta} &amp;lt;/math&amp;gt;&lt;br /&gt;
where &amp;lt;math&amp;gt; Q&amp;lt;/math&amp;gt; is the partition function for the system of N interacting spins.&lt;br /&gt;
&lt;br /&gt;
By evaluating the second form of the partial derivative with respect to &amp;lt;math&amp;gt; \beta&amp;lt;/math&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \left\langle E\right\rangle = -\frac{1}{Q}\frac{\partial Q}{\partial \beta} = \frac{\Sigma \epsilon_{i} e^{-\beta \epsilon_{i}}}{\Sigma e^{-\beta \epsilon_{i}}} &amp;lt;/math&amp;gt; &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Applying the product rule enables the differentiation of this expression for &amp;lt;math&amp;gt;\left\langle E\right\rangle&amp;lt;/math&amp;gt; with respect to temperature, giving:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\frac{\partial \left\langle E\right\rangle}{\partial T} = \frac{\Sigma \epsilon_{i} \frac{\epsilon_i}{k_BT^2}e^{-\beta \epsilon_{i}}}{\Sigma e^{-\beta \epsilon_{i}}} - \frac{\Sigma \epsilon_i e^{-\beta \epsilon_i}\cdot \frac{\epsilon_i}{k_BT^2}e^{-\beta \epsilon_i}}{(\Sigma e^{-\beta \epsilon_{i}})^2}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\frac{\partial \left\langle E\right\rangle}{\partial T}  = \frac{1}{k_BT^2}\left[\frac{\Sigma \epsilon_i^2 e^{-\beta \epsilon_i}}{\Sigma e^{-\beta \epsilon_i}} - \left(\frac{\Sigma \epsilon_{i} e^{-\beta \epsilon_{i}}}{\Sigma e^{-\beta \epsilon_{i}}}\right)^2\right] &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\frac{\partial \left\langle E\right\rangle}{\partial T}  = \frac{1}{k_BT^2}\left[\left\langle E^2\right\rangle - \left\langle E\right\rangle^2 \right] &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Thus,&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\frac{\partial \left\langle E\right\rangle}{\partial T} = \frac{Var[E]}{k_BT^2} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Heat Capacity versus Temperature===&lt;br /&gt;
Below, a screenshot of the Python script written to produce plots of &amp;lt;math&amp;gt; C_V &amp;lt;/math&amp;gt; against &amp;lt;math&amp;gt; T &amp;lt;/math&amp;gt;, together with the output images of this script.&lt;br /&gt;
 &lt;br /&gt;
[[File:HeatCapScript.PNG]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====2x2====&lt;br /&gt;
[[File:HC2.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====4x4====&lt;br /&gt;
[[File:HC4.png]]&lt;br /&gt;
&lt;br /&gt;
====8x8====&lt;br /&gt;
[[File:HC8.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====16x16====&lt;br /&gt;
[[File:HC16.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====32x32====&lt;br /&gt;
[[File:HC32.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= Locating the Curie Temperature =&lt;br /&gt;
&lt;br /&gt;
===C++ Data Comparison===&lt;br /&gt;
Below a comparison of the &amp;lt;math&amp;gt; C_V &amp;lt;/math&amp;gt; against &amp;lt;math&amp;gt; T &amp;lt;/math&amp;gt; plot generated for the &amp;lt;math&amp;gt; 2 /times 2&amp;lt;/math&amp;gt; to the corresponding C++ data is offered.&lt;br /&gt;
 &lt;br /&gt;
[[File:CHC2.png]]&lt;br /&gt;
&lt;br /&gt;
The data generated by the ILtemperaturerange.py script is a faithful match to the C++ data. However, this is an exceptional case; the plots for all other lattice sizes were found to be very dissimilar, necessitating polynomial fitting.&lt;br /&gt;
&lt;br /&gt;
==Polyfitting of C++ Data==&lt;br /&gt;
&lt;br /&gt;
===Fitting a Polynomial to the Entire Range===&lt;br /&gt;
The following Python script was written to perform a polynomial fit to the entire range of the graph of &amp;lt;math&amp;gt; C_V &amp;lt;/math&amp;gt; against &amp;lt;math&amp;gt; T &amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:HeatCapPoly.PNG]]&lt;br /&gt;
&lt;br /&gt;
Below, the result of the polyfit to the &amp;lt;math&amp;gt; 2/times2&amp;lt;/math&amp;gt; lattice data is offered (for comparison to the previous, non-fitted example).&lt;br /&gt;
&lt;br /&gt;
[[File:15Polyc2x2.png]]&lt;br /&gt;
&lt;br /&gt;
Polynomials with 5 terms and above were found to match the data in the vicinity of the critical region considerably well. Below 7 terms, the &#039;&#039;tails&#039;&#039; of the plot were matched poorly. In the above example, a polynomial of 15 terms was fit to the data.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Fitting a Polynomial to the Critical Region===&lt;br /&gt;
&lt;br /&gt;
The following Python script was written to perform a polynomial fit to the region of interest (the &#039;&#039;critical&#039;&#039; region) of the plots of &amp;lt;math&amp;gt; C_V &amp;lt;/math&amp;gt; against &amp;lt;math&amp;gt; T &amp;lt;/math&amp;gt; to facilitate the discovery of &amp;lt;math&amp;gt; T_C &amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
[[File:HeatCapPolyCrit.PNG]]&lt;br /&gt;
&lt;br /&gt;
An example of the result returned by the script is offered below for the C++ data for the &amp;lt;math&amp;gt; 16\times16&amp;lt;/math&amp;gt; lattice.&lt;br /&gt;
&lt;br /&gt;
[[File:HCPC16,2.6-2.1,5.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Python Scripts ===&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
* Frenkel, Daan, et al. Understanding Molecular Simulation : From Algorithms to Applications, Elsevier Science &amp;amp; Technology, 2001&lt;/div&gt;</summary>
		<author><name>Jj1516</name></author>
	</entry>
	<entry>
		<id>https://chemwiki.ch.ic.ac.uk/index.php?title=Rep:JJ1516Ising&amp;diff=736572</id>
		<title>Rep:JJ1516Ising</title>
		<link rel="alternate" type="text/html" href="https://chemwiki.ch.ic.ac.uk/index.php?title=Rep:JJ1516Ising&amp;diff=736572"/>
		<updated>2018-11-20T22:34:53Z</updated>

		<summary type="html">&lt;p&gt;Jj1516: /* Polyfitting of C++ Data */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Ex Script Link:&lt;br /&gt;
https://wiki.ch.ic.ac.uk/wiki/index.php?title=Third_year_CMP_compulsory_experiment&lt;br /&gt;
&lt;br /&gt;
= Introduction to the Ising Model =&lt;br /&gt;
&lt;br /&gt;
== The Model ==&lt;br /&gt;
&lt;br /&gt;
=== Minimum Energy State ===&lt;br /&gt;
====Minimum Interaction Energy====&lt;br /&gt;
The interaction energy of an Ising lattice is given by:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;E = -\frac{1}{2}J\displaystyle\sum_{i}^{N} \displaystyle\sum_{j\;\in\;{neighbours}\;(i)} \!\!\!\!\!\!\!\!\!\!\!\!s_{i}s_{j}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In an Ising lattice with D dimensions and periodic boundary conditions, a given spin &amp;lt;math&amp;gt; s_i&amp;lt;/math&amp;gt; has 2D neighbours.&lt;br /&gt;
&lt;br /&gt;
The minimum interaction energy is achieved when all spins in the lattice are aligned (all ↑ or all ↓). As  such, any spin &amp;lt;math&amp;gt; s_i&amp;lt;/math&amp;gt; must be aligned with all 2D of its neighbours. That is, &amp;lt;math&amp;gt;s_{i}s_{j} = 1&amp;lt;/math&amp;gt; for all &amp;lt;math&amp;gt;j&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Therefore, for any &amp;lt;math&amp;gt; s_i&amp;lt;/math&amp;gt;, the sum of its interactions is &amp;lt;math&amp;gt;\displaystyle\sum_{j\;\in\;{neighbours}\;(i)} \!\!\!\!\!\!\!\!\!\!\!\!s_{i}s_{j} = 2D &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
As this is true for all N spins in the lattice, it follows that &amp;lt;math&amp;gt;\displaystyle\sum_{i}^{N} 2D = 2DN&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Thus the minimum interaction energy is given by:&lt;br /&gt;
&lt;br /&gt;
:&amp;lt;math&amp;gt;E_{min} = -\frac{1}{2}J\cdot2DN = - DNJ &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Entropy of the Minimum Energy State====&lt;br /&gt;
&lt;br /&gt;
The entropy of a state is given by:&lt;br /&gt;
&lt;br /&gt;
:&amp;lt;math&amp;gt;S = k\; ln\; \Omega &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Where &amp;lt;math&amp;gt; \Omega &amp;lt;/math&amp;gt; is the multiplicity of the state, the number of degenerate configurations of said state. The minimum energy state is achievable with all spins ↑ or with all spins ↓. In the absence of an external magnetic field, these configurations are degenerate and indistinguishable giving &amp;lt;math&amp;gt; \Omega = 2 &amp;lt;/math&amp;gt; for this state. Therefore,&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; S_{E_{min}}  = k_{B}\; ln\; 2 = 0.693k_{B} = 9.57 \times 10^{-24} J\!\cdot\!\! K^{-1}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Phase Transitions ==&lt;br /&gt;
&lt;br /&gt;
=== Changes to Minimum Energy Configuration ===&lt;br /&gt;
&lt;br /&gt;
====Energy Change ====&lt;br /&gt;
The energy change &amp;lt;math&amp;gt; \Delta E&amp;lt;/math&amp;gt; associated with a single spin &#039;flip&#039; from the lowest energy onfiguration may be calculated by considering the change in the interaction energy with the spin&#039;s neighbours.&lt;br /&gt;
&lt;br /&gt;
Let &amp;lt;math&amp;gt; D = 3, N = 1000 &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\Delta{E} = E_1 - E_0&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;E_1&amp;lt;/math&amp;gt; Interaction energy after one spin has been &#039;flipped&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;E_0&amp;lt;/math&amp;gt; Lowest energy configuration&lt;br /&gt;
&lt;br /&gt;
[[Image:Task 2 table.PNG]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\displaystyle\sum_{interactions} = -2D + 2D(2D-2) + 2D[N-(2D+1)] &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; = 2DN - 8D &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;E_1 = \displaystyle-\frac{1}{2}J\;\sum_{interactions} = 4DJ - DNJ&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\Delta{E} = E_1 - E_0 = 4DJ - DNJ + DNJ = +4DJ = +12J&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This energy change is independent of &amp;lt;math&amp;gt; N&amp;lt;/math&amp;gt; and depends only on the dimension size and the coupling constant &amp;lt;math&amp;gt; J &amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
In this calculation, the following assumption has been made.&lt;br /&gt;
&lt;br /&gt;
* The lattice dimensions are infinite relative to the size of each cell&lt;br /&gt;
&lt;br /&gt;
This allows &#039;&#039;&#039;any&#039;&#039;&#039; cell to be treated as the centre of the lattice. As every cell interacts with 2D neighbours, flipping any cell in the minimum energy configuration results in the same energy change. Alternatively, the periodic boundary conditions of the Ising model remove the necessity for such an assumption. As a consequence, the absence of &amp;lt;math&amp;gt; N &amp;lt;/math&amp;gt; from the resulting energy change is justified.&lt;br /&gt;
&lt;br /&gt;
====Entropy Change====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; S = k_{B}\; ln\; \Omega &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\Omega = \displaystyle\frac{N!}{{N_{\uparrow}!}{N_{\downarrow}!}}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Where &amp;lt;math&amp;gt;N_{x}!&amp;lt;/math&amp;gt; denotes the factorial of the number of spins in spin state &amp;lt;math&amp;gt;x&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\Delta{S} = k_{B}\;ln\;\left(\displaystyle\frac{\Omega_{2}}{\Omega_{1}}\right)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\Omega_{2} = \frac{1000!}{999!1!} = 1000&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \Omega_{1} = \frac{1000!}{1000!} = 1&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\Delta{S} = k_{B}\;ln\;1000 = 9.54 \times 10^{-23} JK^{-1}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\Delta{S_{mol}} = N_{A}k_{B}\;ln\;1000 = 57.4 \,JK^{-1}mol^{-1}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Magnetisation Values of 1D and 2D Lattices===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;M = \sum_i s_i&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====1D Lattice Magnetisation====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;M_{1D} =\;\;+1&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====2D Lattice Magnetisation====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;M_{2D} =\;\;+1&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Magnetisation at 0K====&lt;br /&gt;
&lt;br /&gt;
At 0K, no thermal energy is available to overcome the energetic barriers to spin flipping. Considering the Hemholtz free energy:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; A = E - TS &amp;lt;/math&amp;gt; &lt;br /&gt;
&lt;br /&gt;
A temperature of 0K nullifies the entropic contribution to the free energy. Thus the energetic driving force (which maximises parallel spin interactions) dominates the entropic driving force (which maximises multiplicity of lattice states). For an Ising Lattice with D =  3, N = 1000 at 0K, the alignment of all spins results in the minimum energy configuration  and an overall magnetisation of &amp;lt;math&amp;gt; M = \pm 1000 &amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
= Calculating the Energy and Magnetisation =&lt;br /&gt;
==Modifying the Files==&lt;br /&gt;
&lt;br /&gt;
===Energy and Magnetisation Functions===&lt;br /&gt;
&lt;br /&gt;
====Energy===&lt;br /&gt;
[[File:First_Ene_Method.PNG]]&lt;br /&gt;
&lt;br /&gt;
The above energy method segments a given lattice into lattice cells on the edges, corners or in the bulk of the lattice and calculates the energy interactions with its neighbours as appropriate.&lt;br /&gt;
&lt;br /&gt;
====Magnetisation====&lt;br /&gt;
[[File:First_Mag_Method.PNG]]&lt;br /&gt;
&lt;br /&gt;
The magnetisation method loops over all elements in the array representing the Ising lattice and adds the value of the spin to the magnetisation variable.&lt;br /&gt;
&lt;br /&gt;
==Testing the Files==&lt;br /&gt;
&lt;br /&gt;
===ILCheck.py===&lt;br /&gt;
&lt;br /&gt;
[[File:ILChecks.PNG]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Above, the results of the ILcheck.py script are presented.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= Introduction to the Monte Carlo Simulation =&lt;br /&gt;
==Average Energy and Magnetisation==&lt;br /&gt;
===Configurations of a 100 Spin System===&lt;br /&gt;
For a system of two spins, 4 configurations are possible (↑↑, ↓↓, ↑↓, ↓↑) i.e. &amp;lt;math&amp;gt;2^{2}&amp;lt;/math&amp;gt;. For a system of 100 spins, there are &amp;lt;math&amp;gt;2^{100}&amp;lt;/math&amp;gt; configurations. In the first example, the ↑↑ and ↓↓ are degenerate, as are the ↑↓ and ↓↑ configurations. Therefore, dividing the number of possible configurations by the multiplicity of each configuration (&amp;lt;math&amp;gt;2&amp;lt;/math&amp;gt;) gives the number of non-degenerate configurations. As previously stated, degenerate configurations are indistinguishable in the absence of an external magnetic field.&lt;br /&gt;
&lt;br /&gt;
For 100 spins, this gives &amp;lt;math&amp;gt;\displaystyle\frac{2^{100}}{2} = 6.338 \times 10^{29} &amp;lt;/math&amp;gt; distinguishable configurations.&lt;br /&gt;
&lt;br /&gt;
If processing speed permits &amp;lt;math&amp;gt; 1 \times 10^{9}&amp;lt;/math&amp;gt; calculations each second, the evaluation of a single value of &amp;lt;math&amp;gt;\left\langle M\right\rangle_T&amp;lt;/math&amp;gt; would last &amp;lt;math&amp;gt; 6.338 \times 10^{20} &amp;lt;/math&amp;gt; seconds or &amp;lt;math&amp;gt; 1458 &amp;lt;/math&amp;gt; times the age of the Universe!&lt;br /&gt;
&lt;br /&gt;
==Modifying IsingLattice.py==&lt;br /&gt;
&lt;br /&gt;
===Monte Carlo and Statistics Methods===&lt;br /&gt;
[[File:Monte_Carlo.PNG]]&lt;br /&gt;
&lt;br /&gt;
[[File:stats.PNG]]&lt;br /&gt;
&lt;br /&gt;
The Metropolis Monte Carlo (MMC) algorithm provides a computationally inexpensive path from random initial states to the minimum free energy states of the Ising lattices generated. First, a random 2D Ising lattice is generated. A single random spin within this lattice is &amp;quot;flipped&amp;quot; and the resulting (internal) energy change between these states is measured. Recalling the relationship between the Hemholtz free energy, internal energy and entropy, it follows that a decrease in internal energy also lowers the free energy of the system: thus the configuration change is accepted.&lt;br /&gt;
&lt;br /&gt;
In the case that the spin &amp;quot;flip&amp;quot; does not lower the internal energy, the MMC algorithm tests this configuration change against the Boltzman factor. In the canonical (NVT) ensemble, the free energy of the system is given by:&lt;br /&gt;
&lt;br /&gt;
:&amp;lt;math&amp;gt;A = -k_{B}T\,lnZ_{NVT} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
where Z is the canonical partition function which depends upon &amp;lt;math&amp;gt; e^{-\frac{\Delta E}{k_BT}} &amp;lt;/math&amp;gt;, the Boltzman factor. By choosing a random value in the interval [0,1)from a continuous uniformm probability distribution and rejecting any value of the Boltzman factor less than this value, ###&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Spontaneous Magnetisation===&lt;br /&gt;
&lt;br /&gt;
Below the Curie Temperature, &amp;lt;math&amp;gt; T_{C} &amp;lt;/math&amp;gt;, the energetic driving force dominates the entropic driving force, resulting in a highly ordered system and an overall magnetisation. The spins of the system align in order to maximise favourable coupling interactions rather than adopting a less ordered configuration of higher multiplicity. Therefore, when &amp;lt;math&amp;gt;T &amp;lt; T_C&amp;lt;/math&amp;gt;, the most probable configurations have an overall magnetisation resulting in &amp;lt;math&amp;gt;\left\langle M\right\rangle \neq 0&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
The plots of magnetisation per spin and energy per spin obtained from ILanim.py support this prediction. Below, the plots show that upon equilibration, the system adopts the minimum energy per spin: &amp;lt;math&amp;gt;E_{min_{spin}} = \frac{-NDJ}{N} = -DJ = -2&amp;lt;/math&amp;gt; and exhibits the maximum magnitude of magnetisation per spin: &amp;lt;math&amp;gt;|M_{spin}| = 1&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:2T=1.0.png]]&lt;br /&gt;
[[File:T=1.0.png]]&lt;br /&gt;
[[File:3T=1.0.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
An unknown system error prevented the statistics() function from printing the average values.&lt;br /&gt;
&lt;br /&gt;
=Accelerating the Code=&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Initial Method Speeds===&lt;br /&gt;
Taking 10 repeat measurements for the time taken to perform 2000 Monte Carlo steps resulted in&lt;br /&gt;
&lt;br /&gt;
* An average time of  &amp;lt;math&amp;gt;11.7s&amp;lt;/math&amp;gt; &lt;br /&gt;
* A standard error of &amp;lt;math&amp;gt;0.020s&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Updating Measurement===&lt;br /&gt;
&lt;br /&gt;
NOTE: ILtimetrial.py has been modified to:&lt;br /&gt;
* Perform a requested number of &#039;2000 Monte Carlo Step&#039; measurements&lt;br /&gt;
* Record these measurements in a CSV file&lt;br /&gt;
* Return the mean measuremd time and the Standard Error i.e.   &amp;lt;math&amp;gt; \frac{\sigma}{n} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:TimeTrialMethod.PNG]]&lt;br /&gt;
&lt;br /&gt;
===Updating Energy and Magnetisation Methods===&lt;br /&gt;
[[File:New_Mag_Method.PNG]]&lt;br /&gt;
[[File:New_Ene_Method.PNG]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Updated Method Speeds===&lt;br /&gt;
[[File:TimeTrial.PNG]]&lt;br /&gt;
&lt;br /&gt;
Taking 30 measurements of the time taken to perform 2000 Monte Carlo Steps resulted in:&lt;br /&gt;
&lt;br /&gt;
* An average time of &amp;lt;math&amp;gt;\displaystyle{0.87s}&amp;lt;/math&amp;gt;&lt;br /&gt;
* A standard error of &amp;lt;math&amp;gt;2.5 \times 10^{-3}s&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This represents a 93% decrease in the average computation time from the initial methods.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=The Effect of Temperature=&lt;br /&gt;
&lt;br /&gt;
==Correcting the Averaging  Code==&lt;br /&gt;
&lt;br /&gt;
===Finding a Delay Value===&lt;br /&gt;
To quickly find a value for &amp;lt;math&amp;gt; N_{d}&amp;lt;/math&amp;gt;, the minimum number of cycles typically needed for the equilibration of a system of within the lattice and temperature ranges of interest, it was assumed that:&lt;br /&gt;
&lt;br /&gt;
* Larger lattices would require more Monte Carlo steps to reach equilibrium from their initial, random configurations&lt;br /&gt;
&lt;br /&gt;
* Lattices at lower temperatures would require more Monte Carlo steps to reach equilibrium from their initial, random configurations.&lt;br /&gt;
&lt;br /&gt;
Therefore, an initial value for &amp;lt;math&amp;gt; N_{d}&amp;lt;/math&amp;gt; was found for a &amp;lt;math&amp;gt; 128\times128 &amp;lt;/math&amp;gt; lattice at a temperature of &amp;lt;math&amp;gt;0.5&amp;lt;/math&amp;gt; reduced temperature units.&lt;br /&gt;
*&amp;lt;math&amp;gt; N_{d} = 185000 &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
By this number of steps, all smaller lattices at all higher temperatures were found to have equilibrated also. Thus, this value of&amp;lt;math&amp;gt; N_{d}&amp;lt;/math&amp;gt; was accepted as an appropriate delay.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:AFinFrame 128 3e5 T= 0.5line.png|400px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
For the 128x128 lattices at T=0.5, equilibration was ensured from 185000 steps onwards.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Smaller lattices at the same temperature did indeed equilibrate more slowly, but all equilibrated within &amp;lt;math&amp;gt; N_{d}&amp;lt;/math&amp;gt; MC steps.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:AFinFrame 64 3e5 T= 0.5line.png|400px]]&lt;br /&gt;
[[File:AFinFrame 32 3e5 T= 0.5line2.png|400px]]&lt;br /&gt;
[[File:AFinFrame 16 3e5 T= 0.5line2.png|400px]]&lt;br /&gt;
[[File:AFinFrame 8 3e5 T= 0.5line.png|400px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The figure below shows the modifications made to IsingLattice.py to incorporate the &amp;lt;math&amp;gt; N_{d} &amp;lt;/math&amp;gt; step delay.&lt;br /&gt;
&lt;br /&gt;
==Running over a Range of Temperatures==&lt;br /&gt;
&lt;br /&gt;
To examine the effect of temperature on the average energy &amp;lt;math&amp;gt; \left\langle E\right\rangle &amp;lt;/math&amp;gt; and average magnetisation &amp;lt;math&amp;gt; \left\langle M\right\rangle &amp;lt;/math&amp;gt; of Ising lattices at equilibrium, the following parameters were used:&lt;br /&gt;
&lt;br /&gt;
* Temperature Range: &amp;lt;math&amp;gt;  0.5 - 5 &amp;lt;/math&amp;gt; reduced units&lt;br /&gt;
* Temperature Interval: &amp;lt;math&amp;gt;0.01&amp;lt;/math&amp;gt; reduced units (&amp;lt;math&amp;gt;450&amp;lt;/math&amp;gt; temperature values)&lt;br /&gt;
* Number of MMC Steps per Temperature value: &amp;lt;math&amp;gt; 2 \times 10^5 &amp;lt;/math&amp;gt; with the aforementioned value of &amp;lt;math&amp;gt; N_{d} = 1.85 \times 10^5 &amp;lt;/math&amp;gt; Monte Carlo steps&lt;br /&gt;
* Lattice Sizes:  &amp;lt;math&amp;gt; 2 \times 2 &amp;lt;/math&amp;gt;, &amp;lt;math&amp;gt; 4 \times 4 &amp;lt;/math&amp;gt; , &amp;lt;math&amp;gt; 8 \times 8 &amp;lt;/math&amp;gt; , &amp;lt;math&amp;gt; 16 \times 16 &amp;lt;/math&amp;gt; , &amp;lt;math&amp;gt; 32 \times 32 &amp;lt;/math&amp;gt; , &amp;lt;math&amp;gt; 64 \times 64 &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Plots of  &amp;lt;math&amp;gt; \left\langle E\right\rangle &amp;lt;/math&amp;gt; and  &amp;lt;math&amp;gt; \left\langle M\right\rangle &amp;lt;/math&amp;gt; per spin as versus temperature are presented below for each lattice size. Errorbars have been implemented to demonstrate how &#039;&#039;well-behaved&#039;&#039; lattice systems of each size are at each temperature, that is, how temperature and lattice size affect the size of the variations in the expected values. For the error calculations, the standard errors, &amp;lt;math&amp;gt; \sigma_\bar{X} &amp;lt;/math&amp;gt;,  in &amp;lt;math&amp;gt; \left\langle E\right\rangle &amp;lt;/math&amp;gt; and  &amp;lt;math&amp;gt; \left\langle M\right\rangle &amp;lt;/math&amp;gt; per spin have been used:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====8x8====&lt;br /&gt;
&lt;br /&gt;
[[File:8x8e+error.png]] [[File:8x8m+error.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
A Python script has been written to generate a plot of &amp;lt;math&amp;gt;\left\langle E\right\rangle&amp;lt;/math&amp;gt; or &amp;lt;math&amp;gt;\left\langle M\right\rangle&amp;lt;/math&amp;gt; against temperature based upon user input. A screenshot of this code has been inserted below.&lt;br /&gt;
&lt;br /&gt;
[[File:ExpectedvsTemp.PNG|200px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=The Effect of System Size=&lt;br /&gt;
&lt;br /&gt;
==Scaling the System Size==&lt;br /&gt;
&lt;br /&gt;
===More Lattice Sizes===&lt;br /&gt;
&lt;br /&gt;
====2x2====&lt;br /&gt;
[[File:2x2e+error.png]] [[File:2x2m+error.png]]&lt;br /&gt;
&lt;br /&gt;
====4x4====&lt;br /&gt;
[[File:4x4e+error.png]] [[File:4x4m+error.png]]&lt;br /&gt;
&lt;br /&gt;
====16x16====&lt;br /&gt;
[[File:16x16e+error.png]] [[File:16x16m+error.png]]&lt;br /&gt;
&lt;br /&gt;
====32x32====&lt;br /&gt;
[[File:32x32e+error.png]] [[File:32x32m+error.png]]&lt;br /&gt;
&lt;br /&gt;
====64x64====&lt;br /&gt;
[[File:64x64e+error.png]] [[File:64x64m+error.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Scrutiny of the plots of average energy per spin for each lattice size reveals an increase in the errorbar width with increasing lattice size. This is most notable in the low temperature region of the plots. Between the &amp;lt;math&amp;gt; 8\times8 &amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt; 16\times16 &amp;lt;/math&amp;gt; lattices, the long range fluctuations become suddenly prominent. The &amp;lt;math&amp;gt;16\times16&amp;lt;/math&amp;gt; lattice is the first (in the range of sizes tested)to clearly capture these fluctuations.&lt;br /&gt;
&lt;br /&gt;
=Determining the Heat Capacity=&lt;br /&gt;
&lt;br /&gt;
==Calculating the Heat Capacity==&lt;br /&gt;
&lt;br /&gt;
===Heat Capacity Derivation===&lt;br /&gt;
Working in the canonical ensemble (constant volume), the heat capacity &amp;lt;math&amp;gt; C_V &amp;lt;/math&amp;gt; is given by:&lt;br /&gt;
&lt;br /&gt;
:&amp;lt;math&amp;gt;C_V = \frac{\partial \left\langle E\right\rangle}{\partial T}_V&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
where &amp;lt;math&amp;gt;\left\langle E\right\rangle&amp;lt;/math&amp;gt; is the average total energy or expected value of the internal energy of the system.&lt;br /&gt;
&lt;br /&gt;
: &amp;lt;math&amp;gt; \left\langle E\right\rangle = - \frac{\partial ln Q}{\partial \beta} = -\frac{1}{Q}\frac{\partial Q}{\partial \beta} &amp;lt;/math&amp;gt;&lt;br /&gt;
where &amp;lt;math&amp;gt; Q&amp;lt;/math&amp;gt; is the partition function for the system of N interacting spins.&lt;br /&gt;
&lt;br /&gt;
By evaluating the second form of the partial derivative with respect to &amp;lt;math&amp;gt; \beta&amp;lt;/math&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \left\langle E\right\rangle = -\frac{1}{Q}\frac{\partial Q}{\partial \beta} = \frac{\Sigma \epsilon_{i} e^{-\beta \epsilon_{i}}}{\Sigma e^{-\beta \epsilon_{i}}} &amp;lt;/math&amp;gt; &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Applying the product rule enables the differentiation of this expression for &amp;lt;math&amp;gt;\left\langle E\right\rangle&amp;lt;/math&amp;gt; with respect to temperature, giving:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\frac{\partial \left\langle E\right\rangle}{\partial T} = \frac{\Sigma \epsilon_{i} \frac{\epsilon_i}{k_BT^2}e^{-\beta \epsilon_{i}}}{\Sigma e^{-\beta \epsilon_{i}}} - \frac{\Sigma \epsilon_i e^{-\beta \epsilon_i}\cdot \frac{\epsilon_i}{k_BT^2}e^{-\beta \epsilon_i}}{(\Sigma e^{-\beta \epsilon_{i}})^2}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\frac{\partial \left\langle E\right\rangle}{\partial T}  = \frac{1}{k_BT^2}\left[\frac{\Sigma \epsilon_i^2 e^{-\beta \epsilon_i}}{\Sigma e^{-\beta \epsilon_i}} - \left(\frac{\Sigma \epsilon_{i} e^{-\beta \epsilon_{i}}}{\Sigma e^{-\beta \epsilon_{i}}}\right)^2\right] &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\frac{\partial \left\langle E\right\rangle}{\partial T}  = \frac{1}{k_BT^2}\left[\left\langle E^2\right\rangle - \left\langle E\right\rangle^2 \right] &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Thus,&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\frac{\partial \left\langle E\right\rangle}{\partial T} = \frac{Var[E]}{k_BT^2} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Heat Capacity versus Temperature===&lt;br /&gt;
Below, a screenshot of the Python script written to produce plots of &amp;lt;math&amp;gt; C_V &amp;lt;/math&amp;gt; against &amp;lt;math&amp;gt; T &amp;lt;/math&amp;gt;, together with the output images of this script.&lt;br /&gt;
 &lt;br /&gt;
[[File:HeatCapScript.PNG]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====2x2====&lt;br /&gt;
[[File:HC2.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====4x4====&lt;br /&gt;
[[File:HC4.png]]&lt;br /&gt;
&lt;br /&gt;
====8x8====&lt;br /&gt;
[[File:HC8.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====16x16====&lt;br /&gt;
[[File:HC16.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====32x32====&lt;br /&gt;
[[File:HC32.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= Locating the Curie Temperature =&lt;br /&gt;
&lt;br /&gt;
===C++ Data Comparison===&lt;br /&gt;
Below a comparison of the &amp;lt;math&amp;gt; C_V &amp;lt;/math&amp;gt; against &amp;lt;math&amp;gt; T &amp;lt;/plot&amp;gt; generated for the &amp;lt;math&amp;gt; 2 /times 2&amp;lt;/math&amp;gt; to the corresponding C++ data is offered.&lt;br /&gt;
 &lt;br /&gt;
[[File:CHC2.png]]&lt;br /&gt;
&lt;br /&gt;
The data generated by the ILtemperaturerange.py script is a faithful match to the C++ data. However, this is an exceptional case; the plots for all other lattice sizes were found to be very dissimilar, necessitating polynomial fitting.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Polyfitting of C++ Data==&lt;br /&gt;
&lt;br /&gt;
===Fitting a Polynomial to the Entire Range===&lt;br /&gt;
The following Python script was written to perform a polynomial fit to the entire range of the graph of &amp;lt;math&amp;gt; C_V &amp;lt;/math&amp;gt; against &amp;lt;math&amp;gt; T &amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:HeatCapPoly.PNG]]&lt;br /&gt;
&lt;br /&gt;
Below, the result of the polyfit to the &amp;lt;math&amp;gt; 2/times2&amp;lt;/math&amp;gt; lattice data is offered (for comparison to the previous, non-fitted example).&lt;br /&gt;
&lt;br /&gt;
[[File:15Polyc2x2.png]]&lt;br /&gt;
&lt;br /&gt;
Polynomials with 5 terms and above were found to match the data in the vicinity of the critical region considerably well. Below 7 terms, the &#039;&#039;tails&#039;&#039; of the plot were matched poorly. In the above example, a polynomial of 15 terms was fit to the data.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Fitting a Polynomial to the Critical Region===&lt;br /&gt;
&lt;br /&gt;
The following Python script was written to perform a polynomial fit to the region of interest (the &#039;&#039;critical&#039;&#039; region) of the plots of &amp;lt;math&amp;gt; C_V &amp;lt;/math&amp;gt; against &amp;lt;math&amp;gt; T &amp;lt;/math&amp;gt; to facilitate the discovery of &amp;lt;math&amp;gt; T_C &amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
[[File:HeatCapPolyCrit.PNG]]&lt;br /&gt;
&lt;br /&gt;
An example of the result returned by the script is offered below for the C++ data for the &amp;lt;math&amp;gt; 16\times16&amp;lt;/math&amp;gt; lattice.&lt;br /&gt;
&lt;br /&gt;
[[File:HCPC16,2.6-2.1,5.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Python Scripts ===&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
* Frenkel, Daan, et al. Understanding Molecular Simulation : From Algorithms to Applications, Elsevier Science &amp;amp; Technology, 2001&lt;/div&gt;</summary>
		<author><name>Jj1516</name></author>
	</entry>
	<entry>
		<id>https://chemwiki.ch.ic.ac.uk/index.php?title=File:HCPC16,2.6-2.1,5.png&amp;diff=736569</id>
		<title>File:HCPC16,2.6-2.1,5.png</title>
		<link rel="alternate" type="text/html" href="https://chemwiki.ch.ic.ac.uk/index.php?title=File:HCPC16,2.6-2.1,5.png&amp;diff=736569"/>
		<updated>2018-11-20T22:34:27Z</updated>

		<summary type="html">&lt;p&gt;Jj1516: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Jj1516</name></author>
	</entry>
	<entry>
		<id>https://chemwiki.ch.ic.ac.uk/index.php?title=File:HeatCapPolyCrit.PNG&amp;diff=736567</id>
		<title>File:HeatCapPolyCrit.PNG</title>
		<link rel="alternate" type="text/html" href="https://chemwiki.ch.ic.ac.uk/index.php?title=File:HeatCapPolyCrit.PNG&amp;diff=736567"/>
		<updated>2018-11-20T22:28:43Z</updated>

		<summary type="html">&lt;p&gt;Jj1516: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Jj1516</name></author>
	</entry>
	<entry>
		<id>https://chemwiki.ch.ic.ac.uk/index.php?title=Rep:JJ1516Ising&amp;diff=736555</id>
		<title>Rep:JJ1516Ising</title>
		<link rel="alternate" type="text/html" href="https://chemwiki.ch.ic.ac.uk/index.php?title=Rep:JJ1516Ising&amp;diff=736555"/>
		<updated>2018-11-20T22:17:42Z</updated>

		<summary type="html">&lt;p&gt;Jj1516: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Ex Script Link:&lt;br /&gt;
https://wiki.ch.ic.ac.uk/wiki/index.php?title=Third_year_CMP_compulsory_experiment&lt;br /&gt;
&lt;br /&gt;
= Introduction to the Ising Model =&lt;br /&gt;
&lt;br /&gt;
== The Model ==&lt;br /&gt;
&lt;br /&gt;
=== Minimum Energy State ===&lt;br /&gt;
====Minimum Interaction Energy====&lt;br /&gt;
The interaction energy of an Ising lattice is given by:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;E = -\frac{1}{2}J\displaystyle\sum_{i}^{N} \displaystyle\sum_{j\;\in\;{neighbours}\;(i)} \!\!\!\!\!\!\!\!\!\!\!\!s_{i}s_{j}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In an Ising lattice with D dimensions and periodic boundary conditions, a given spin &amp;lt;math&amp;gt; s_i&amp;lt;/math&amp;gt; has 2D neighbours.&lt;br /&gt;
&lt;br /&gt;
The minimum interaction energy is achieved when all spins in the lattice are aligned (all ↑ or all ↓). As  such, any spin &amp;lt;math&amp;gt; s_i&amp;lt;/math&amp;gt; must be aligned with all 2D of its neighbours. That is, &amp;lt;math&amp;gt;s_{i}s_{j} = 1&amp;lt;/math&amp;gt; for all &amp;lt;math&amp;gt;j&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Therefore, for any &amp;lt;math&amp;gt; s_i&amp;lt;/math&amp;gt;, the sum of its interactions is &amp;lt;math&amp;gt;\displaystyle\sum_{j\;\in\;{neighbours}\;(i)} \!\!\!\!\!\!\!\!\!\!\!\!s_{i}s_{j} = 2D &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
As this is true for all N spins in the lattice, it follows that &amp;lt;math&amp;gt;\displaystyle\sum_{i}^{N} 2D = 2DN&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Thus the minimum interaction energy is given by:&lt;br /&gt;
&lt;br /&gt;
:&amp;lt;math&amp;gt;E_{min} = -\frac{1}{2}J\cdot2DN = - DNJ &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Entropy of the Minimum Energy State====&lt;br /&gt;
&lt;br /&gt;
The entropy of a state is given by:&lt;br /&gt;
&lt;br /&gt;
:&amp;lt;math&amp;gt;S = k\; ln\; \Omega &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Where &amp;lt;math&amp;gt; \Omega &amp;lt;/math&amp;gt; is the multiplicity of the state, the number of degenerate configurations of said state. The minimum energy state is achievable with all spins ↑ or with all spins ↓. In the absence of an external magnetic field, these configurations are degenerate and indistinguishable giving &amp;lt;math&amp;gt; \Omega = 2 &amp;lt;/math&amp;gt; for this state. Therefore,&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; S_{E_{min}}  = k_{B}\; ln\; 2 = 0.693k_{B} = 9.57 \times 10^{-24} J\!\cdot\!\! K^{-1}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Phase Transitions ==&lt;br /&gt;
&lt;br /&gt;
=== Changes to Minimum Energy Configuration ===&lt;br /&gt;
&lt;br /&gt;
====Energy Change ====&lt;br /&gt;
The energy change &amp;lt;math&amp;gt; \Delta E&amp;lt;/math&amp;gt; associated with a single spin &#039;flip&#039; from the lowest energy onfiguration may be calculated by considering the change in the interaction energy with the spin&#039;s neighbours.&lt;br /&gt;
&lt;br /&gt;
Let &amp;lt;math&amp;gt; D = 3, N = 1000 &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\Delta{E} = E_1 - E_0&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;E_1&amp;lt;/math&amp;gt; Interaction energy after one spin has been &#039;flipped&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;E_0&amp;lt;/math&amp;gt; Lowest energy configuration&lt;br /&gt;
&lt;br /&gt;
[[Image:Task 2 table.PNG]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\displaystyle\sum_{interactions} = -2D + 2D(2D-2) + 2D[N-(2D+1)] &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; = 2DN - 8D &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;E_1 = \displaystyle-\frac{1}{2}J\;\sum_{interactions} = 4DJ - DNJ&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\Delta{E} = E_1 - E_0 = 4DJ - DNJ + DNJ = +4DJ = +12J&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This energy change is independent of &amp;lt;math&amp;gt; N&amp;lt;/math&amp;gt; and depends only on the dimension size and the coupling constant &amp;lt;math&amp;gt; J &amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
In this calculation, the following assumption has been made.&lt;br /&gt;
&lt;br /&gt;
* The lattice dimensions are infinite relative to the size of each cell&lt;br /&gt;
&lt;br /&gt;
This allows &#039;&#039;&#039;any&#039;&#039;&#039; cell to be treated as the centre of the lattice. As every cell interacts with 2D neighbours, flipping any cell in the minimum energy configuration results in the same energy change. Alternatively, the periodic boundary conditions of the Ising model remove the necessity for such an assumption. As a consequence, the absence of &amp;lt;math&amp;gt; N &amp;lt;/math&amp;gt; from the resulting energy change is justified.&lt;br /&gt;
&lt;br /&gt;
====Entropy Change====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; S = k_{B}\; ln\; \Omega &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\Omega = \displaystyle\frac{N!}{{N_{\uparrow}!}{N_{\downarrow}!}}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Where &amp;lt;math&amp;gt;N_{x}!&amp;lt;/math&amp;gt; denotes the factorial of the number of spins in spin state &amp;lt;math&amp;gt;x&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\Delta{S} = k_{B}\;ln\;\left(\displaystyle\frac{\Omega_{2}}{\Omega_{1}}\right)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\Omega_{2} = \frac{1000!}{999!1!} = 1000&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \Omega_{1} = \frac{1000!}{1000!} = 1&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\Delta{S} = k_{B}\;ln\;1000 = 9.54 \times 10^{-23} JK^{-1}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\Delta{S_{mol}} = N_{A}k_{B}\;ln\;1000 = 57.4 \,JK^{-1}mol^{-1}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Magnetisation Values of 1D and 2D Lattices===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;M = \sum_i s_i&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====1D Lattice Magnetisation====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;M_{1D} =\;\;+1&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====2D Lattice Magnetisation====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;M_{2D} =\;\;+1&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Magnetisation at 0K====&lt;br /&gt;
&lt;br /&gt;
At 0K, no thermal energy is available to overcome the energetic barriers to spin flipping. Considering the Hemholtz free energy:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; A = E - TS &amp;lt;/math&amp;gt; &lt;br /&gt;
&lt;br /&gt;
A temperature of 0K nullifies the entropic contribution to the free energy. Thus the energetic driving force (which maximises parallel spin interactions) dominates the entropic driving force (which maximises multiplicity of lattice states). For an Ising Lattice with D =  3, N = 1000 at 0K, the alignment of all spins results in the minimum energy configuration  and an overall magnetisation of &amp;lt;math&amp;gt; M = \pm 1000 &amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
= Calculating the Energy and Magnetisation =&lt;br /&gt;
==Modifying the Files==&lt;br /&gt;
&lt;br /&gt;
===Energy and Magnetisation Functions===&lt;br /&gt;
&lt;br /&gt;
====Energy===&lt;br /&gt;
[[File:First_Ene_Method.PNG]]&lt;br /&gt;
&lt;br /&gt;
The above energy method segments a given lattice into lattice cells on the edges, corners or in the bulk of the lattice and calculates the energy interactions with its neighbours as appropriate.&lt;br /&gt;
&lt;br /&gt;
====Magnetisation====&lt;br /&gt;
[[File:First_Mag_Method.PNG]]&lt;br /&gt;
&lt;br /&gt;
The magnetisation method loops over all elements in the array representing the Ising lattice and adds the value of the spin to the magnetisation variable.&lt;br /&gt;
&lt;br /&gt;
==Testing the Files==&lt;br /&gt;
&lt;br /&gt;
===ILCheck.py===&lt;br /&gt;
&lt;br /&gt;
[[File:ILChecks.PNG]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Above, the results of the ILcheck.py script are presented.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= Introduction to the Monte Carlo Simulation =&lt;br /&gt;
==Average Energy and Magnetisation==&lt;br /&gt;
===Configurations of a 100 Spin System===&lt;br /&gt;
For a system of two spins, 4 configurations are possible (↑↑, ↓↓, ↑↓, ↓↑) i.e. &amp;lt;math&amp;gt;2^{2}&amp;lt;/math&amp;gt;. For a system of 100 spins, there are &amp;lt;math&amp;gt;2^{100}&amp;lt;/math&amp;gt; configurations. In the first example, the ↑↑ and ↓↓ are degenerate, as are the ↑↓ and ↓↑ configurations. Therefore, dividing the number of possible configurations by the multiplicity of each configuration (&amp;lt;math&amp;gt;2&amp;lt;/math&amp;gt;) gives the number of non-degenerate configurations. As previously stated, degenerate configurations are indistinguishable in the absence of an external magnetic field.&lt;br /&gt;
&lt;br /&gt;
For 100 spins, this gives &amp;lt;math&amp;gt;\displaystyle\frac{2^{100}}{2} = 6.338 \times 10^{29} &amp;lt;/math&amp;gt; distinguishable configurations.&lt;br /&gt;
&lt;br /&gt;
If processing speed permits &amp;lt;math&amp;gt; 1 \times 10^{9}&amp;lt;/math&amp;gt; calculations each second, the evaluation of a single value of &amp;lt;math&amp;gt;\left\langle M\right\rangle_T&amp;lt;/math&amp;gt; would last &amp;lt;math&amp;gt; 6.338 \times 10^{20} &amp;lt;/math&amp;gt; seconds or &amp;lt;math&amp;gt; 1458 &amp;lt;/math&amp;gt; times the age of the Universe!&lt;br /&gt;
&lt;br /&gt;
==Modifying IsingLattice.py==&lt;br /&gt;
&lt;br /&gt;
===Monte Carlo and Statistics Methods===&lt;br /&gt;
[[File:Monte_Carlo.PNG]]&lt;br /&gt;
&lt;br /&gt;
[[File:stats.PNG]]&lt;br /&gt;
&lt;br /&gt;
The Metropolis Monte Carlo (MMC) algorithm provides a computationally inexpensive path from random initial states to the minimum free energy states of the Ising lattices generated. First, a random 2D Ising lattice is generated. A single random spin within this lattice is &amp;quot;flipped&amp;quot; and the resulting (internal) energy change between these states is measured. Recalling the relationship between the Hemholtz free energy, internal energy and entropy, it follows that a decrease in internal energy also lowers the free energy of the system: thus the configuration change is accepted.&lt;br /&gt;
&lt;br /&gt;
In the case that the spin &amp;quot;flip&amp;quot; does not lower the internal energy, the MMC algorithm tests this configuration change against the Boltzman factor. In the canonical (NVT) ensemble, the free energy of the system is given by:&lt;br /&gt;
&lt;br /&gt;
:&amp;lt;math&amp;gt;A = -k_{B}T\,lnZ_{NVT} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
where Z is the canonical partition function which depends upon &amp;lt;math&amp;gt; e^{-\frac{\Delta E}{k_BT}} &amp;lt;/math&amp;gt;, the Boltzman factor. By choosing a random value in the interval [0,1)from a continuous uniformm probability distribution and rejecting any value of the Boltzman factor less than this value, ###&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Spontaneous Magnetisation===&lt;br /&gt;
&lt;br /&gt;
Below the Curie Temperature, &amp;lt;math&amp;gt; T_{C} &amp;lt;/math&amp;gt;, the energetic driving force dominates the entropic driving force, resulting in a highly ordered system and an overall magnetisation. The spins of the system align in order to maximise favourable coupling interactions rather than adopting a less ordered configuration of higher multiplicity. Therefore, when &amp;lt;math&amp;gt;T &amp;lt; T_C&amp;lt;/math&amp;gt;, the most probable configurations have an overall magnetisation resulting in &amp;lt;math&amp;gt;\left\langle M\right\rangle \neq 0&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
The plots of magnetisation per spin and energy per spin obtained from ILanim.py support this prediction. Below, the plots show that upon equilibration, the system adopts the minimum energy per spin: &amp;lt;math&amp;gt;E_{min_{spin}} = \frac{-NDJ}{N} = -DJ = -2&amp;lt;/math&amp;gt; and exhibits the maximum magnitude of magnetisation per spin: &amp;lt;math&amp;gt;|M_{spin}| = 1&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:2T=1.0.png]]&lt;br /&gt;
[[File:T=1.0.png]]&lt;br /&gt;
[[File:3T=1.0.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
An unknown system error prevented the statistics() function from printing the average values.&lt;br /&gt;
&lt;br /&gt;
=Accelerating the Code=&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Initial Method Speeds===&lt;br /&gt;
Taking 10 repeat measurements for the time taken to perform 2000 Monte Carlo steps resulted in&lt;br /&gt;
&lt;br /&gt;
* An average time of  &amp;lt;math&amp;gt;11.7s&amp;lt;/math&amp;gt; &lt;br /&gt;
* A standard error of &amp;lt;math&amp;gt;0.020s&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Updating Measurement===&lt;br /&gt;
&lt;br /&gt;
NOTE: ILtimetrial.py has been modified to:&lt;br /&gt;
* Perform a requested number of &#039;2000 Monte Carlo Step&#039; measurements&lt;br /&gt;
* Record these measurements in a CSV file&lt;br /&gt;
* Return the mean measuremd time and the Standard Error i.e.   &amp;lt;math&amp;gt; \frac{\sigma}{n} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:TimeTrialMethod.PNG]]&lt;br /&gt;
&lt;br /&gt;
===Updating Energy and Magnetisation Methods===&lt;br /&gt;
[[File:New_Mag_Method.PNG]]&lt;br /&gt;
[[File:New_Ene_Method.PNG]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Updated Method Speeds===&lt;br /&gt;
[[File:TimeTrial.PNG]]&lt;br /&gt;
&lt;br /&gt;
Taking 30 measurements of the time taken to perform 2000 Monte Carlo Steps resulted in:&lt;br /&gt;
&lt;br /&gt;
* An average time of &amp;lt;math&amp;gt;\displaystyle{0.87s}&amp;lt;/math&amp;gt;&lt;br /&gt;
* A standard error of &amp;lt;math&amp;gt;2.5 \times 10^{-3}s&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This represents a 93% decrease in the average computation time from the initial methods.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=The Effect of Temperature=&lt;br /&gt;
&lt;br /&gt;
==Correcting the Averaging  Code==&lt;br /&gt;
&lt;br /&gt;
===Finding a Delay Value===&lt;br /&gt;
To quickly find a value for &amp;lt;math&amp;gt; N_{d}&amp;lt;/math&amp;gt;, the minimum number of cycles typically needed for the equilibration of a system of within the lattice and temperature ranges of interest, it was assumed that:&lt;br /&gt;
&lt;br /&gt;
* Larger lattices would require more Monte Carlo steps to reach equilibrium from their initial, random configurations&lt;br /&gt;
&lt;br /&gt;
* Lattices at lower temperatures would require more Monte Carlo steps to reach equilibrium from their initial, random configurations.&lt;br /&gt;
&lt;br /&gt;
Therefore, an initial value for &amp;lt;math&amp;gt; N_{d}&amp;lt;/math&amp;gt; was found for a &amp;lt;math&amp;gt; 128\times128 &amp;lt;/math&amp;gt; lattice at a temperature of &amp;lt;math&amp;gt;0.5&amp;lt;/math&amp;gt; reduced temperature units.&lt;br /&gt;
*&amp;lt;math&amp;gt; N_{d} = 185000 &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
By this number of steps, all smaller lattices at all higher temperatures were found to have equilibrated also. Thus, this value of&amp;lt;math&amp;gt; N_{d}&amp;lt;/math&amp;gt; was accepted as an appropriate delay.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:AFinFrame 128 3e5 T= 0.5line.png|400px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
For the 128x128 lattices at T=0.5, equilibration was ensured from 185000 steps onwards.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Smaller lattices at the same temperature did indeed equilibrate more slowly, but all equilibrated within &amp;lt;math&amp;gt; N_{d}&amp;lt;/math&amp;gt; MC steps.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:AFinFrame 64 3e5 T= 0.5line.png|400px]]&lt;br /&gt;
[[File:AFinFrame 32 3e5 T= 0.5line2.png|400px]]&lt;br /&gt;
[[File:AFinFrame 16 3e5 T= 0.5line2.png|400px]]&lt;br /&gt;
[[File:AFinFrame 8 3e5 T= 0.5line.png|400px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The figure below shows the modifications made to IsingLattice.py to incorporate the &amp;lt;math&amp;gt; N_{d} &amp;lt;/math&amp;gt; step delay.&lt;br /&gt;
&lt;br /&gt;
==Running over a Range of Temperatures==&lt;br /&gt;
&lt;br /&gt;
To examine the effect of temperature on the average energy &amp;lt;math&amp;gt; \left\langle E\right\rangle &amp;lt;/math&amp;gt; and average magnetisation &amp;lt;math&amp;gt; \left\langle M\right\rangle &amp;lt;/math&amp;gt; of Ising lattices at equilibrium, the following parameters were used:&lt;br /&gt;
&lt;br /&gt;
* Temperature Range: &amp;lt;math&amp;gt;  0.5 - 5 &amp;lt;/math&amp;gt; reduced units&lt;br /&gt;
* Temperature Interval: &amp;lt;math&amp;gt;0.01&amp;lt;/math&amp;gt; reduced units (&amp;lt;math&amp;gt;450&amp;lt;/math&amp;gt; temperature values)&lt;br /&gt;
* Number of MMC Steps per Temperature value: &amp;lt;math&amp;gt; 2 \times 10^5 &amp;lt;/math&amp;gt; with the aforementioned value of &amp;lt;math&amp;gt; N_{d} = 1.85 \times 10^5 &amp;lt;/math&amp;gt; Monte Carlo steps&lt;br /&gt;
* Lattice Sizes:  &amp;lt;math&amp;gt; 2 \times 2 &amp;lt;/math&amp;gt;, &amp;lt;math&amp;gt; 4 \times 4 &amp;lt;/math&amp;gt; , &amp;lt;math&amp;gt; 8 \times 8 &amp;lt;/math&amp;gt; , &amp;lt;math&amp;gt; 16 \times 16 &amp;lt;/math&amp;gt; , &amp;lt;math&amp;gt; 32 \times 32 &amp;lt;/math&amp;gt; , &amp;lt;math&amp;gt; 64 \times 64 &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Plots of  &amp;lt;math&amp;gt; \left\langle E\right\rangle &amp;lt;/math&amp;gt; and  &amp;lt;math&amp;gt; \left\langle M\right\rangle &amp;lt;/math&amp;gt; per spin as versus temperature are presented below for each lattice size. Errorbars have been implemented to demonstrate how &#039;&#039;well-behaved&#039;&#039; lattice systems of each size are at each temperature, that is, how temperature and lattice size affect the size of the variations in the expected values. For the error calculations, the standard errors, &amp;lt;math&amp;gt; \sigma_\bar{X} &amp;lt;/math&amp;gt;,  in &amp;lt;math&amp;gt; \left\langle E\right\rangle &amp;lt;/math&amp;gt; and  &amp;lt;math&amp;gt; \left\langle M\right\rangle &amp;lt;/math&amp;gt; per spin have been used:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====8x8====&lt;br /&gt;
&lt;br /&gt;
[[File:8x8e+error.png]] [[File:8x8m+error.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
A Python script has been written to generate a plot of &amp;lt;math&amp;gt;\left\langle E\right\rangle&amp;lt;/math&amp;gt; or &amp;lt;math&amp;gt;\left\langle M\right\rangle&amp;lt;/math&amp;gt; against temperature based upon user input. A screenshot of this code has been inserted below.&lt;br /&gt;
&lt;br /&gt;
[[File:ExpectedvsTemp.PNG|200px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=The Effect of System Size=&lt;br /&gt;
&lt;br /&gt;
==Scaling the System Size==&lt;br /&gt;
&lt;br /&gt;
===More Lattice Sizes===&lt;br /&gt;
&lt;br /&gt;
====2x2====&lt;br /&gt;
[[File:2x2e+error.png]] [[File:2x2m+error.png]]&lt;br /&gt;
&lt;br /&gt;
====4x4====&lt;br /&gt;
[[File:4x4e+error.png]] [[File:4x4m+error.png]]&lt;br /&gt;
&lt;br /&gt;
====16x16====&lt;br /&gt;
[[File:16x16e+error.png]] [[File:16x16m+error.png]]&lt;br /&gt;
&lt;br /&gt;
====32x32====&lt;br /&gt;
[[File:32x32e+error.png]] [[File:32x32m+error.png]]&lt;br /&gt;
&lt;br /&gt;
====64x64====&lt;br /&gt;
[[File:64x64e+error.png]] [[File:64x64m+error.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Scrutiny of the plots of average energy per spin for each lattice size reveals an increase in the errorbar width with increasing lattice size. This is most notable in the low temperature region of the plots. Between the &amp;lt;math&amp;gt; 8\times8 &amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt; 16\times16 &amp;lt;/math&amp;gt; lattices, the long range fluctuations become suddenly prominent. The &amp;lt;math&amp;gt;16\times16&amp;lt;/math&amp;gt; lattice is the first (in the range of sizes tested)to clearly capture these fluctuations.&lt;br /&gt;
&lt;br /&gt;
=Determining the Heat Capacity=&lt;br /&gt;
&lt;br /&gt;
==Calculating the Heat Capacity==&lt;br /&gt;
&lt;br /&gt;
===Heat Capacity Derivation===&lt;br /&gt;
Working in the canonical ensemble (constant volume), the heat capacity &amp;lt;math&amp;gt; C_V &amp;lt;/math&amp;gt; is given by:&lt;br /&gt;
&lt;br /&gt;
:&amp;lt;math&amp;gt;C_V = \frac{\partial \left\langle E\right\rangle}{\partial T}_V&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
where &amp;lt;math&amp;gt;\left\langle E\right\rangle&amp;lt;/math&amp;gt; is the average total energy or expected value of the internal energy of the system.&lt;br /&gt;
&lt;br /&gt;
: &amp;lt;math&amp;gt; \left\langle E\right\rangle = - \frac{\partial ln Q}{\partial \beta} = -\frac{1}{Q}\frac{\partial Q}{\partial \beta} &amp;lt;/math&amp;gt;&lt;br /&gt;
where &amp;lt;math&amp;gt; Q&amp;lt;/math&amp;gt; is the partition function for the system of N interacting spins.&lt;br /&gt;
&lt;br /&gt;
By evaluating the second form of the partial derivative with respect to &amp;lt;math&amp;gt; \beta&amp;lt;/math&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \left\langle E\right\rangle = -\frac{1}{Q}\frac{\partial Q}{\partial \beta} = \frac{\Sigma \epsilon_{i} e^{-\beta \epsilon_{i}}}{\Sigma e^{-\beta \epsilon_{i}}} &amp;lt;/math&amp;gt; &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Applying the product rule enables the differentiation of this expression for &amp;lt;math&amp;gt;\left\langle E\right\rangle&amp;lt;/math&amp;gt; with respect to temperature, giving:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\frac{\partial \left\langle E\right\rangle}{\partial T} = \frac{\Sigma \epsilon_{i} \frac{\epsilon_i}{k_BT^2}e^{-\beta \epsilon_{i}}}{\Sigma e^{-\beta \epsilon_{i}}} - \frac{\Sigma \epsilon_i e^{-\beta \epsilon_i}\cdot \frac{\epsilon_i}{k_BT^2}e^{-\beta \epsilon_i}}{(\Sigma e^{-\beta \epsilon_{i}})^2}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\frac{\partial \left\langle E\right\rangle}{\partial T}  = \frac{1}{k_BT^2}\left[\frac{\Sigma \epsilon_i^2 e^{-\beta \epsilon_i}}{\Sigma e^{-\beta \epsilon_i}} - \left(\frac{\Sigma \epsilon_{i} e^{-\beta \epsilon_{i}}}{\Sigma e^{-\beta \epsilon_{i}}}\right)^2\right] &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\frac{\partial \left\langle E\right\rangle}{\partial T}  = \frac{1}{k_BT^2}\left[\left\langle E^2\right\rangle - \left\langle E\right\rangle^2 \right] &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Thus,&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\frac{\partial \left\langle E\right\rangle}{\partial T} = \frac{Var[E]}{k_BT^2} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Heat Capacity versus Temperature===&lt;br /&gt;
Below, a screenshot of the Python script written to produce plots of &amp;lt;math&amp;gt; C_V &amp;lt;/math&amp;gt; against &amp;lt;math&amp;gt; T &amp;lt;/math&amp;gt;, together with the output images of this script.&lt;br /&gt;
 &lt;br /&gt;
[[File:HeatCapScript.PNG]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====2x2====&lt;br /&gt;
[[File:HC2.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====4x4====&lt;br /&gt;
[[File:HC4.png]]&lt;br /&gt;
&lt;br /&gt;
====8x8====&lt;br /&gt;
[[File:HC8.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====16x16====&lt;br /&gt;
[[File:HC16.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====32x32====&lt;br /&gt;
[[File:HC32.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= Locating the Curie Temperature =&lt;br /&gt;
&lt;br /&gt;
===C++ Data Comparison===&lt;br /&gt;
Below a comparison of the &amp;lt;math&amp;gt; C_V &amp;lt;/math&amp;gt; against &amp;lt;math&amp;gt; T &amp;lt;/plot&amp;gt; generated for the &amp;lt;math&amp;gt; 2 /times 2&amp;lt;/math&amp;gt; to the corresponding C++ data is offered.&lt;br /&gt;
 &lt;br /&gt;
[[File:CHC2.png]]&lt;br /&gt;
&lt;br /&gt;
The data generated by the ILtemperaturerange.py script is a faithful match to the C++ data. However, this is an exceptional case; the plots for all other lattice sizes were found to be very dissimilar, necessitating polynomial fitting.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Polyfitting of C++ Data==&lt;br /&gt;
&lt;br /&gt;
===Fitting a Polynomial to the Entire Range===&lt;br /&gt;
The following Python script was written to perform a polynomial fitting to the entire range of the graph of &amp;lt;math&amp;gt; C_V &amp;lt;/math&amp;gt; against &amp;lt;math&amp;gt; T &amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:HeatCapPoly.PNG]]&lt;br /&gt;
&lt;br /&gt;
Below, the result of the polyfit to the &amp;lt;math&amp;gt; 2/times2&amp;lt;/math&amp;gt; lattice data is offered (for comparison to the previous, non-fitted example).&lt;br /&gt;
&lt;br /&gt;
[[File:15Polyc2x2.png]]&lt;br /&gt;
&lt;br /&gt;
Polynomials with 5 terms and above were found to match the data in the vicinity of the critical region considerably well. Below 7 terms, the &#039;&#039;tails&#039;&#039; of the plot were matched poorly. In the above example, a polynomial of 15 terms was fit to the data.&lt;br /&gt;
&lt;br /&gt;
=== Python Scripts ===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
* Frenkel, Daan, et al. Understanding Molecular Simulation : From Algorithms to Applications, Elsevier Science &amp;amp; Technology, 2001&lt;/div&gt;</summary>
		<author><name>Jj1516</name></author>
	</entry>
	<entry>
		<id>https://chemwiki.ch.ic.ac.uk/index.php?title=File:HeatCapPoly.PNG&amp;diff=736552</id>
		<title>File:HeatCapPoly.PNG</title>
		<link rel="alternate" type="text/html" href="https://chemwiki.ch.ic.ac.uk/index.php?title=File:HeatCapPoly.PNG&amp;diff=736552"/>
		<updated>2018-11-20T22:15:38Z</updated>

		<summary type="html">&lt;p&gt;Jj1516: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Jj1516</name></author>
	</entry>
	<entry>
		<id>https://chemwiki.ch.ic.ac.uk/index.php?title=Rep:JJ1516Ising&amp;diff=736547</id>
		<title>Rep:JJ1516Ising</title>
		<link rel="alternate" type="text/html" href="https://chemwiki.ch.ic.ac.uk/index.php?title=Rep:JJ1516Ising&amp;diff=736547"/>
		<updated>2018-11-20T22:04:01Z</updated>

		<summary type="html">&lt;p&gt;Jj1516: /* More Lattice Sizes */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Ex Script Link:&lt;br /&gt;
https://wiki.ch.ic.ac.uk/wiki/index.php?title=Third_year_CMP_compulsory_experiment&lt;br /&gt;
&lt;br /&gt;
= Introduction to the Ising Model =&lt;br /&gt;
&lt;br /&gt;
== The Model ==&lt;br /&gt;
&lt;br /&gt;
=== Minimum Energy State ===&lt;br /&gt;
====Minimum Interaction Energy====&lt;br /&gt;
The interaction energy of an Ising lattice is given by:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;E = -\frac{1}{2}J\displaystyle\sum_{i}^{N} \displaystyle\sum_{j\;\in\;{neighbours}\;(i)} \!\!\!\!\!\!\!\!\!\!\!\!s_{i}s_{j}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In an Ising lattice with D dimensions and periodic boundary conditions, a given spin &amp;lt;math&amp;gt; s_i&amp;lt;/math&amp;gt; has 2D neighbours.&lt;br /&gt;
&lt;br /&gt;
The minimum interaction energy is achieved when all spins in the lattice are aligned (all ↑ or all ↓). As  such, any spin &amp;lt;math&amp;gt; s_i&amp;lt;/math&amp;gt; must be aligned with all 2D of its neighbours. That is, &amp;lt;math&amp;gt;s_{i}s_{j} = 1&amp;lt;/math&amp;gt; for all &amp;lt;math&amp;gt;j&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Therefore, for any &amp;lt;math&amp;gt; s_i&amp;lt;/math&amp;gt;, the sum of its interactions is &amp;lt;math&amp;gt;\displaystyle\sum_{j\;\in\;{neighbours}\;(i)} \!\!\!\!\!\!\!\!\!\!\!\!s_{i}s_{j} = 2D &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
As this is true for all N spins in the lattice, it follows that &amp;lt;math&amp;gt;\displaystyle\sum_{i}^{N} 2D = 2DN&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Thus the minimum interaction energy is given by:&lt;br /&gt;
&lt;br /&gt;
:&amp;lt;math&amp;gt;E_{min} = -\frac{1}{2}J\cdot2DN = - DNJ &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Entropy of the Minimum Energy State====&lt;br /&gt;
&lt;br /&gt;
The entropy of a state is given by:&lt;br /&gt;
&lt;br /&gt;
:&amp;lt;math&amp;gt;S = k\; ln\; \Omega &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Where &amp;lt;math&amp;gt; \Omega &amp;lt;/math&amp;gt; is the multiplicity of the state, the number of degenerate configurations of said state. The minimum energy state is achievable with all spins ↑ or with all spins ↓. In the absence of an external magnetic field, these configurations are degenerate and indistinguishable giving &amp;lt;math&amp;gt; \Omega = 2 &amp;lt;/math&amp;gt; for this state. Therefore,&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; S_{E_{min}}  = k_{B}\; ln\; 2 = 0.693k_{B} = 9.57 \times 10^{-24} J\!\cdot\!\! K^{-1}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Phase Transitions ==&lt;br /&gt;
&lt;br /&gt;
=== Changes to Minimum Energy Configuration ===&lt;br /&gt;
&lt;br /&gt;
====Energy Change ====&lt;br /&gt;
The energy change &amp;lt;math&amp;gt; \Delta E&amp;lt;/math&amp;gt; associated with a single spin &#039;flip&#039; from the lowest energy onfiguration may be calculated by considering the change in the interaction energy with the spin&#039;s neighbours.&lt;br /&gt;
&lt;br /&gt;
Let &amp;lt;math&amp;gt; D = 3, N = 1000 &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\Delta{E} = E_1 - E_0&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;E_1&amp;lt;/math&amp;gt; Interaction energy after one spin has been &#039;flipped&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;E_0&amp;lt;/math&amp;gt; Lowest energy configuration&lt;br /&gt;
&lt;br /&gt;
[[Image:Task 2 table.PNG]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\displaystyle\sum_{interactions} = -2D + 2D(2D-2) + 2D[N-(2D+1)] &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; = 2DN - 8D &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;E_1 = \displaystyle-\frac{1}{2}J\;\sum_{interactions} = 4DJ - DNJ&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\Delta{E} = E_1 - E_0 = 4DJ - DNJ + DNJ = +4DJ = +12J&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This energy change is independent of &amp;lt;math&amp;gt; N&amp;lt;/math&amp;gt; and depends only on the dimension size and the coupling constant &amp;lt;math&amp;gt; J &amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
In this calculation, the following assumption has been made.&lt;br /&gt;
&lt;br /&gt;
* The lattice dimensions are infinite relative to the size of each cell&lt;br /&gt;
&lt;br /&gt;
This allows &#039;&#039;&#039;any&#039;&#039;&#039; cell to be treated as the centre of the lattice. As every cell interacts with 2D neighbours, flipping any cell in the minimum energy configuration results in the same energy change. Alternatively, the periodic boundary conditions of the Ising model remove the necessity for such an assumption. As a consequence, the absence of &amp;lt;math&amp;gt; N &amp;lt;/math&amp;gt; from the resulting energy change is justified.&lt;br /&gt;
&lt;br /&gt;
====Entropy Change====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; S = k_{B}\; ln\; \Omega &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\Omega = \displaystyle\frac{N!}{{N_{\uparrow}!}{N_{\downarrow}!}}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Where &amp;lt;math&amp;gt;N_{x}!&amp;lt;/math&amp;gt; denotes the factorial of the number of spins in spin state &amp;lt;math&amp;gt;x&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\Delta{S} = k_{B}\;ln\;\left(\displaystyle\frac{\Omega_{2}}{\Omega_{1}}\right)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\Omega_{2} = \frac{1000!}{999!1!} = 1000&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \Omega_{1} = \frac{1000!}{1000!} = 1&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\Delta{S} = k_{B}\;ln\;1000 = 9.54 \times 10^{-23} JK^{-1}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\Delta{S_{mol}} = N_{A}k_{B}\;ln\;1000 = 57.4 \,JK^{-1}mol^{-1}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Magnetisation Values of 1D and 2D Lattices===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;M = \sum_i s_i&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====1D Lattice Magnetisation====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;M_{1D} =\;\;+1&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====2D Lattice Magnetisation====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;M_{2D} =\;\;+1&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Magnetisation at 0K====&lt;br /&gt;
&lt;br /&gt;
At 0K, no thermal energy is available to overcome the energetic barriers to spin flipping. Considering the Hemholtz free energy:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; A = E - TS &amp;lt;/math&amp;gt; &lt;br /&gt;
&lt;br /&gt;
A temperature of 0K nullifies the entropic contribution to the free energy. Thus the energetic driving force (which maximises parallel spin interactions) dominates the entropic driving force (which maximises multiplicity of lattice states). For an Ising Lattice with D =  3, N = 1000 at 0K, the alignment of all spins results in the minimum energy configuration  and an overall magnetisation of &amp;lt;math&amp;gt; M = \pm 1000 &amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
= Calculating the Energy and Magnetisation =&lt;br /&gt;
==Modifying the Files==&lt;br /&gt;
&lt;br /&gt;
===Energy and Magnetisation Functions===&lt;br /&gt;
&lt;br /&gt;
====Energy===&lt;br /&gt;
[[File:First_Ene_Method.PNG]]&lt;br /&gt;
&lt;br /&gt;
The above energy method segments a given lattice into lattice cells on the edges, corners or in the bulk of the lattice and calculates the energy interactions with its neighbours as appropriate.&lt;br /&gt;
&lt;br /&gt;
====Magnetisation====&lt;br /&gt;
[[File:First_Mag_Method.PNG]]&lt;br /&gt;
&lt;br /&gt;
The magnetisation method loops over all elements in the array representing the Ising lattice and adds the value of the spin to the magnetisation variable.&lt;br /&gt;
&lt;br /&gt;
==Testing the Files==&lt;br /&gt;
&lt;br /&gt;
===ILCheck.py===&lt;br /&gt;
&lt;br /&gt;
[[File:ILChecks.PNG]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Above, the results of the ILcheck.py script are presented.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= Introduction to the Monte Carlo Simulation =&lt;br /&gt;
==Average Energy and Magnetisation==&lt;br /&gt;
===Configurations of a 100 Spin System===&lt;br /&gt;
For a system of two spins, 4 configurations are possible (↑↑, ↓↓, ↑↓, ↓↑) i.e. &amp;lt;math&amp;gt;2^{2}&amp;lt;/math&amp;gt;. For a system of 100 spins, there are &amp;lt;math&amp;gt;2^{100}&amp;lt;/math&amp;gt; configurations. In the first example, the ↑↑ and ↓↓ are degenerate, as are the ↑↓ and ↓↑ configurations. Therefore, dividing the number of possible configurations by the multiplicity of each configuration (&amp;lt;math&amp;gt;2&amp;lt;/math&amp;gt;) gives the number of non-degenerate configurations. As previously stated, degenerate configurations are indistinguishable in the absence of an external magnetic field.&lt;br /&gt;
&lt;br /&gt;
For 100 spins, this gives &amp;lt;math&amp;gt;\displaystyle\frac{2^{100}}{2} = 6.338 \times 10^{29} &amp;lt;/math&amp;gt; distinguishable configurations.&lt;br /&gt;
&lt;br /&gt;
If processing speed permits &amp;lt;math&amp;gt; 1 \times 10^{9}&amp;lt;/math&amp;gt; calculations each second, the evaluation of a single value of &amp;lt;math&amp;gt;\left\langle M\right\rangle_T&amp;lt;/math&amp;gt; would last &amp;lt;math&amp;gt; 6.338 \times 10^{20} &amp;lt;/math&amp;gt; seconds or &amp;lt;math&amp;gt; 1458 &amp;lt;/math&amp;gt; times the age of the Universe!&lt;br /&gt;
&lt;br /&gt;
==Modifying IsingLattice.py==&lt;br /&gt;
&lt;br /&gt;
===Monte Carlo and Statistics Methods===&lt;br /&gt;
[[File:Monte_Carlo.PNG]]&lt;br /&gt;
&lt;br /&gt;
[[File:stats.PNG]]&lt;br /&gt;
&lt;br /&gt;
The Metropolis Monte Carlo (MMC) algorithm provides a computationally inexpensive path from random initial states to the minimum free energy states of the Ising lattices generated. First, a random 2D Ising lattice is generated. A single random spin within this lattice is &amp;quot;flipped&amp;quot; and the resulting (internal) energy change between these states is measured. Recalling the relationship between the Hemholtz free energy, internal energy and entropy, it follows that a decrease in internal energy also lowers the free energy of the system: thus the configuration change is accepted.&lt;br /&gt;
&lt;br /&gt;
In the case that the spin &amp;quot;flip&amp;quot; does not lower the internal energy, the MMC algorithm tests this configuration change against the Boltzman factor. In the canonical (NVT) ensemble, the free energy of the system is given by:&lt;br /&gt;
&lt;br /&gt;
:&amp;lt;math&amp;gt;A = -k_{B}T\,lnZ_{NVT} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
where Z is the canonical partition function which depends upon &amp;lt;math&amp;gt; e^{-\frac{\Delta E}{k_BT}} &amp;lt;/math&amp;gt;, the Boltzman factor. By choosing a random value in the interval [0,1)from a continuous uniformm probability distribution and rejecting any value of the Boltzman factor less than this value, ###&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Spontaneous Magnetisation===&lt;br /&gt;
&lt;br /&gt;
Below the Curie Temperature, &amp;lt;math&amp;gt; T_{C} &amp;lt;/math&amp;gt;, the energetic driving force dominates the entropic driving force, resulting in a highly ordered system and an overall magnetisation. The spins of the system align in order to maximise favourable coupling interactions rather than adopting a less ordered configuration of higher multiplicity. Therefore, when &amp;lt;math&amp;gt;T &amp;lt; T_C&amp;lt;/math&amp;gt;, the most probable configurations have an overall magnetisation resulting in &amp;lt;math&amp;gt;\left\langle M\right\rangle \neq 0&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
The plots of magnetisation per spin and energy per spin obtained from ILanim.py support this prediction. Below, the plots show that upon equilibration, the system adopts the minimum energy per spin: &amp;lt;math&amp;gt;E_{min_{spin}} = \frac{-NDJ}{N} = -DJ = -2&amp;lt;/math&amp;gt; and exhibits the maximum magnitude of magnetisation per spin: &amp;lt;math&amp;gt;|M_{spin}| = 1&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:2T=1.0.png]]&lt;br /&gt;
[[File:T=1.0.png]]&lt;br /&gt;
[[File:3T=1.0.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
An unknown system error prevented the statistics() function from printing the average values.&lt;br /&gt;
&lt;br /&gt;
=Accelerating the Code=&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Initial Method Speeds===&lt;br /&gt;
Taking 10 repeat measurements for the time taken to perform 2000 Monte Carlo steps resulted in&lt;br /&gt;
&lt;br /&gt;
* An average time of  &amp;lt;math&amp;gt;11.7s&amp;lt;/math&amp;gt; &lt;br /&gt;
* A standard error of &amp;lt;math&amp;gt;0.020s&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Updating Measurement===&lt;br /&gt;
&lt;br /&gt;
NOTE: ILtimetrial.py has been modified to:&lt;br /&gt;
* Perform a requested number of &#039;2000 Monte Carlo Step&#039; measurements&lt;br /&gt;
* Record these measurements in a CSV file&lt;br /&gt;
* Return the mean measuremd time and the Standard Error i.e.   &amp;lt;math&amp;gt; \frac{\sigma}{n} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:TimeTrialMethod.PNG]]&lt;br /&gt;
&lt;br /&gt;
===Updating Energy and Magnetisation Methods===&lt;br /&gt;
[[File:New_Mag_Method.PNG]]&lt;br /&gt;
[[File:New_Ene_Method.PNG]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Updated Method Speeds===&lt;br /&gt;
[[File:TimeTrial.PNG]]&lt;br /&gt;
&lt;br /&gt;
Taking 30 measurements of the time taken to perform 2000 Monte Carlo Steps resulted in:&lt;br /&gt;
&lt;br /&gt;
* An average time of &amp;lt;math&amp;gt;\displaystyle{0.87s}&amp;lt;/math&amp;gt;&lt;br /&gt;
* A standard error of &amp;lt;math&amp;gt;2.5 \times 10^{-3}s&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This represents a 93% decrease in the average computation time from the initial methods.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=The Effect of Temperature=&lt;br /&gt;
&lt;br /&gt;
==Correcting the Averaging  Code==&lt;br /&gt;
&lt;br /&gt;
===Finding a Delay Value===&lt;br /&gt;
To quickly find a value for &amp;lt;math&amp;gt; N_{d}&amp;lt;/math&amp;gt;, the minimum number of cycles typically needed for the equilibration of a system of within the lattice and temperature ranges of interest, it was assumed that:&lt;br /&gt;
&lt;br /&gt;
* Larger lattices would require more Monte Carlo steps to reach equilibrium from their initial, random configurations&lt;br /&gt;
&lt;br /&gt;
* Lattices at lower temperatures would require more Monte Carlo steps to reach equilibrium from their initial, random configurations.&lt;br /&gt;
&lt;br /&gt;
Therefore, an initial value for &amp;lt;math&amp;gt; N_{d}&amp;lt;/math&amp;gt; was found for a &amp;lt;math&amp;gt; 128\times128 &amp;lt;/math&amp;gt; lattice at a temperature of &amp;lt;math&amp;gt;0.5&amp;lt;/math&amp;gt; reduced temperature units.&lt;br /&gt;
*&amp;lt;math&amp;gt; N_{d} = 185000 &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
By this number of steps, all smaller lattices at all higher temperatures were found to have equilibrated also. Thus, this value of&amp;lt;math&amp;gt; N_{d}&amp;lt;/math&amp;gt; was accepted as an appropriate delay.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:AFinFrame 128 3e5 T= 0.5line.png|400px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
For the 128x128 lattices at T=0.5, equilibration was ensured from 185000 steps onwards.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Smaller lattices at the same temperature did indeed equilibrate more slowly, but all equilibrated within &amp;lt;math&amp;gt; N_{d}&amp;lt;/math&amp;gt; MC steps.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:AFinFrame 64 3e5 T= 0.5line.png|400px]]&lt;br /&gt;
[[File:AFinFrame 32 3e5 T= 0.5line2.png|400px]]&lt;br /&gt;
[[File:AFinFrame 16 3e5 T= 0.5line2.png|400px]]&lt;br /&gt;
[[File:AFinFrame 8 3e5 T= 0.5line.png|400px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The figure below shows the modifications made to IsingLattice.py to incorporate the &amp;lt;math&amp;gt; N_{d} &amp;lt;/math&amp;gt; step delay.&lt;br /&gt;
&lt;br /&gt;
==Running over a Range of Temperatures==&lt;br /&gt;
&lt;br /&gt;
To examine the effect of temperature on the average energy &amp;lt;math&amp;gt; \left\langle E\right\rangle &amp;lt;/math&amp;gt; and average magnetisation &amp;lt;math&amp;gt; \left\langle M\right\rangle &amp;lt;/math&amp;gt; of Ising lattices at equilibrium, the following parameters were used:&lt;br /&gt;
&lt;br /&gt;
* Temperature Range: &amp;lt;math&amp;gt;  0.5 - 5 &amp;lt;/math&amp;gt; reduced units&lt;br /&gt;
* Temperature Interval: &amp;lt;math&amp;gt;0.01&amp;lt;/math&amp;gt; reduced units (&amp;lt;math&amp;gt;450&amp;lt;/math&amp;gt; temperature values)&lt;br /&gt;
* Number of MMC Steps per Temperature value: &amp;lt;math&amp;gt; 2 \times 10^5 &amp;lt;/math&amp;gt; with the aforementioned value of &amp;lt;math&amp;gt; N_{d} = 1.85 \times 10^5 &amp;lt;/math&amp;gt; Monte Carlo steps&lt;br /&gt;
* Lattice Sizes:  &amp;lt;math&amp;gt; 2 \times 2 &amp;lt;/math&amp;gt;, &amp;lt;math&amp;gt; 4 \times 4 &amp;lt;/math&amp;gt; , &amp;lt;math&amp;gt; 8 \times 8 &amp;lt;/math&amp;gt; , &amp;lt;math&amp;gt; 16 \times 16 &amp;lt;/math&amp;gt; , &amp;lt;math&amp;gt; 32 \times 32 &amp;lt;/math&amp;gt; , &amp;lt;math&amp;gt; 64 \times 64 &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Plots of  &amp;lt;math&amp;gt; \left\langle E\right\rangle &amp;lt;/math&amp;gt; and  &amp;lt;math&amp;gt; \left\langle M\right\rangle &amp;lt;/math&amp;gt; per spin as versus temperature are presented below for each lattice size. Errorbars have been implemented to demonstrate how &#039;&#039;well-behaved&#039;&#039; lattice systems of each size are at each temperature, that is, how temperature and lattice size affect the size of the variations in the expected values. For the error calculations, the standard errors, &amp;lt;math&amp;gt; \sigma_\bar{X} &amp;lt;/math&amp;gt;,  in &amp;lt;math&amp;gt; \left\langle E\right\rangle &amp;lt;/math&amp;gt; and  &amp;lt;math&amp;gt; \left\langle M\right\rangle &amp;lt;/math&amp;gt; per spin have been used:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====8x8====&lt;br /&gt;
&lt;br /&gt;
[[File:8x8e+error.png]] [[File:8x8m+error.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
A Python script has been written to generate a plot of &amp;lt;math&amp;gt;\left\langle E\right\rangle&amp;lt;/math&amp;gt; or &amp;lt;math&amp;gt;\left\langle M\right\rangle&amp;lt;/math&amp;gt; against temperature based upon user input. A screenshot of this code has been inserted below.&lt;br /&gt;
&lt;br /&gt;
[[File:ExpectedvsTemp.PNG|200px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=The Effect of System Size=&lt;br /&gt;
&lt;br /&gt;
==Scaling the System Size==&lt;br /&gt;
&lt;br /&gt;
===More Lattice Sizes===&lt;br /&gt;
&lt;br /&gt;
====2x2====&lt;br /&gt;
[[File:2x2e+error.png]] [[File:2x2m+error.png]]&lt;br /&gt;
&lt;br /&gt;
====4x4====&lt;br /&gt;
[[File:4x4e+error.png]] [[File:4x4m+error.png]]&lt;br /&gt;
&lt;br /&gt;
====16x16====&lt;br /&gt;
[[File:16x16e+error.png]] [[File:16x16m+error.png]]&lt;br /&gt;
&lt;br /&gt;
====32x32====&lt;br /&gt;
[[File:32x32e+error.png]] [[File:32x32m+error.png]]&lt;br /&gt;
&lt;br /&gt;
====64x64====&lt;br /&gt;
[[File:64x64e+error.png]] [[File:64x64m+error.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Scrutiny of the plots of average energy per spin for each lattice size reveals an increase in the errorbar width with increasing lattice size. This is most notable in the low temperature region of the plots. Between the &amp;lt;math&amp;gt; 8\times8 &amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt; 16\times16 &amp;lt;/math&amp;gt; lattices, the long range fluctuations become suddenly prominent. The &amp;lt;math&amp;gt;16\times16&amp;lt;/math&amp;gt; lattice is the first (in the range of sizes tested)to clearly capture these fluctuations.&lt;br /&gt;
&lt;br /&gt;
=Determining the Heat Capacity=&lt;br /&gt;
&lt;br /&gt;
==Calculating the Heat Capacity==&lt;br /&gt;
&lt;br /&gt;
===Heat Capacity Derivation===&lt;br /&gt;
Working in the canonical ensemble (constant volume), the heat capacity &amp;lt;math&amp;gt; C_V &amp;lt;/math&amp;gt; is given by:&lt;br /&gt;
&lt;br /&gt;
:&amp;lt;math&amp;gt;C_V = \frac{\partial \left\langle E\right\rangle}{\partial T}_V&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
where &amp;lt;math&amp;gt;\left\langle E\right\rangle&amp;lt;/math&amp;gt; is the average total energy or expected value of the internal energy of the system.&lt;br /&gt;
&lt;br /&gt;
: &amp;lt;math&amp;gt; \left\langle E\right\rangle = - \frac{\partial ln Q}{\partial \beta} = -\frac{1}{Q}\frac{\partial Q}{\partial \beta} &amp;lt;/math&amp;gt;&lt;br /&gt;
where &amp;lt;math&amp;gt; Q&amp;lt;/math&amp;gt; is the partition function for the system of N interacting spins.&lt;br /&gt;
&lt;br /&gt;
By evaluating the second form of the partial derivative with respect to &amp;lt;math&amp;gt; \beta&amp;lt;/math&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \left\langle E\right\rangle = -\frac{1}{Q}\frac{\partial Q}{\partial \beta} = \frac{\Sigma \epsilon_{i} e^{-\beta \epsilon_{i}}}{\Sigma e^{-\beta \epsilon_{i}}} &amp;lt;/math&amp;gt; &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Applying the product rule enables the differentiation of this expression for &amp;lt;math&amp;gt;\left\langle E\right\rangle&amp;lt;/math&amp;gt; with respect to temperature, giving:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\frac{\partial \left\langle E\right\rangle}{\partial T} = \frac{\Sigma \epsilon_{i} \frac{\epsilon_i}{k_BT^2}e^{-\beta \epsilon_{i}}}{\Sigma e^{-\beta \epsilon_{i}}} - \frac{\Sigma \epsilon_i e^{-\beta \epsilon_i}\cdot \frac{\epsilon_i}{k_BT^2}e^{-\beta \epsilon_i}}{(\Sigma e^{-\beta \epsilon_{i}})^2}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\frac{\partial \left\langle E\right\rangle}{\partial T}  = \frac{1}{k_BT^2}\left[\frac{\Sigma \epsilon_i^2 e^{-\beta \epsilon_i}}{\Sigma e^{-\beta \epsilon_i}} - \left(\frac{\Sigma \epsilon_{i} e^{-\beta \epsilon_{i}}}{\Sigma e^{-\beta \epsilon_{i}}}\right)^2\right] &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\frac{\partial \left\langle E\right\rangle}{\partial T}  = \frac{1}{k_BT^2}\left[\left\langle E^2\right\rangle - \left\langle E\right\rangle^2 \right] &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Thus,&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\frac{\partial \left\langle E\right\rangle}{\partial T} = \frac{Var[E]}{k_BT^2} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Heat Capacity versus Temperature===&lt;br /&gt;
Below, a screenshot of the Python script written to produce plots of &amp;lt;math&amp;gt; C_V &amp;lt;/math&amp;gt; against &amp;lt;math&amp;gt; T &amp;lt;/math&amp;gt;, together with the output images of this script.&lt;br /&gt;
 &lt;br /&gt;
[[File:HeatCapScript.PNG]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====2x2====&lt;br /&gt;
[[File:HC2.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====4x4====&lt;br /&gt;
[[File:HC4.png]]&lt;br /&gt;
&lt;br /&gt;
====8x8====&lt;br /&gt;
[[File:HC8.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====16x16====&lt;br /&gt;
[[File:HC16.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====32x32====&lt;br /&gt;
[[File:HC32.png]]&lt;br /&gt;
&lt;br /&gt;
== Locating the Curie Temperature ==&lt;br /&gt;
&lt;br /&gt;
===C++ Data Comparison===&lt;br /&gt;
&lt;br /&gt;
[[File:CHC2.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Polyfitting of C++ Data===&lt;br /&gt;
&lt;br /&gt;
====Fitting a Polynomial to the Entire Range====&lt;br /&gt;
&lt;br /&gt;
[[File:15Polyc2x2.png]]&lt;br /&gt;
Polynomials with 5 terms and above were found to match the data in the vicinity of the critical region considerably well. Below 7 terms, the &#039;&#039;tails&#039;&#039; of the plot were matched poorly. In the above example, a polynomial of 15 terms was fit to the data.&lt;br /&gt;
&lt;br /&gt;
=== Python Scripts ===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
* Frenkel, Daan, et al. Understanding Molecular Simulation : From Algorithms to Applications, Elsevier Science &amp;amp; Technology, 2001&lt;/div&gt;</summary>
		<author><name>Jj1516</name></author>
	</entry>
	<entry>
		<id>https://chemwiki.ch.ic.ac.uk/index.php?title=Rep:JJ1516Ising&amp;diff=736546</id>
		<title>Rep:JJ1516Ising</title>
		<link rel="alternate" type="text/html" href="https://chemwiki.ch.ic.ac.uk/index.php?title=Rep:JJ1516Ising&amp;diff=736546"/>
		<updated>2018-11-20T22:02:16Z</updated>

		<summary type="html">&lt;p&gt;Jj1516: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Ex Script Link:&lt;br /&gt;
https://wiki.ch.ic.ac.uk/wiki/index.php?title=Third_year_CMP_compulsory_experiment&lt;br /&gt;
&lt;br /&gt;
= Introduction to the Ising Model =&lt;br /&gt;
&lt;br /&gt;
== The Model ==&lt;br /&gt;
&lt;br /&gt;
=== Minimum Energy State ===&lt;br /&gt;
====Minimum Interaction Energy====&lt;br /&gt;
The interaction energy of an Ising lattice is given by:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;E = -\frac{1}{2}J\displaystyle\sum_{i}^{N} \displaystyle\sum_{j\;\in\;{neighbours}\;(i)} \!\!\!\!\!\!\!\!\!\!\!\!s_{i}s_{j}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In an Ising lattice with D dimensions and periodic boundary conditions, a given spin &amp;lt;math&amp;gt; s_i&amp;lt;/math&amp;gt; has 2D neighbours.&lt;br /&gt;
&lt;br /&gt;
The minimum interaction energy is achieved when all spins in the lattice are aligned (all ↑ or all ↓). As  such, any spin &amp;lt;math&amp;gt; s_i&amp;lt;/math&amp;gt; must be aligned with all 2D of its neighbours. That is, &amp;lt;math&amp;gt;s_{i}s_{j} = 1&amp;lt;/math&amp;gt; for all &amp;lt;math&amp;gt;j&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Therefore, for any &amp;lt;math&amp;gt; s_i&amp;lt;/math&amp;gt;, the sum of its interactions is &amp;lt;math&amp;gt;\displaystyle\sum_{j\;\in\;{neighbours}\;(i)} \!\!\!\!\!\!\!\!\!\!\!\!s_{i}s_{j} = 2D &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
As this is true for all N spins in the lattice, it follows that &amp;lt;math&amp;gt;\displaystyle\sum_{i}^{N} 2D = 2DN&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Thus the minimum interaction energy is given by:&lt;br /&gt;
&lt;br /&gt;
:&amp;lt;math&amp;gt;E_{min} = -\frac{1}{2}J\cdot2DN = - DNJ &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Entropy of the Minimum Energy State====&lt;br /&gt;
&lt;br /&gt;
The entropy of a state is given by:&lt;br /&gt;
&lt;br /&gt;
:&amp;lt;math&amp;gt;S = k\; ln\; \Omega &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Where &amp;lt;math&amp;gt; \Omega &amp;lt;/math&amp;gt; is the multiplicity of the state, the number of degenerate configurations of said state. The minimum energy state is achievable with all spins ↑ or with all spins ↓. In the absence of an external magnetic field, these configurations are degenerate and indistinguishable giving &amp;lt;math&amp;gt; \Omega = 2 &amp;lt;/math&amp;gt; for this state. Therefore,&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; S_{E_{min}}  = k_{B}\; ln\; 2 = 0.693k_{B} = 9.57 \times 10^{-24} J\!\cdot\!\! K^{-1}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Phase Transitions ==&lt;br /&gt;
&lt;br /&gt;
=== Changes to Minimum Energy Configuration ===&lt;br /&gt;
&lt;br /&gt;
====Energy Change ====&lt;br /&gt;
The energy change &amp;lt;math&amp;gt; \Delta E&amp;lt;/math&amp;gt; associated with a single spin &#039;flip&#039; from the lowest energy onfiguration may be calculated by considering the change in the interaction energy with the spin&#039;s neighbours.&lt;br /&gt;
&lt;br /&gt;
Let &amp;lt;math&amp;gt; D = 3, N = 1000 &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\Delta{E} = E_1 - E_0&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;E_1&amp;lt;/math&amp;gt; Interaction energy after one spin has been &#039;flipped&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;E_0&amp;lt;/math&amp;gt; Lowest energy configuration&lt;br /&gt;
&lt;br /&gt;
[[Image:Task 2 table.PNG]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\displaystyle\sum_{interactions} = -2D + 2D(2D-2) + 2D[N-(2D+1)] &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; = 2DN - 8D &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;E_1 = \displaystyle-\frac{1}{2}J\;\sum_{interactions} = 4DJ - DNJ&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\Delta{E} = E_1 - E_0 = 4DJ - DNJ + DNJ = +4DJ = +12J&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This energy change is independent of &amp;lt;math&amp;gt; N&amp;lt;/math&amp;gt; and depends only on the dimension size and the coupling constant &amp;lt;math&amp;gt; J &amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
In this calculation, the following assumption has been made.&lt;br /&gt;
&lt;br /&gt;
* The lattice dimensions are infinite relative to the size of each cell&lt;br /&gt;
&lt;br /&gt;
This allows &#039;&#039;&#039;any&#039;&#039;&#039; cell to be treated as the centre of the lattice. As every cell interacts with 2D neighbours, flipping any cell in the minimum energy configuration results in the same energy change. Alternatively, the periodic boundary conditions of the Ising model remove the necessity for such an assumption. As a consequence, the absence of &amp;lt;math&amp;gt; N &amp;lt;/math&amp;gt; from the resulting energy change is justified.&lt;br /&gt;
&lt;br /&gt;
====Entropy Change====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; S = k_{B}\; ln\; \Omega &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\Omega = \displaystyle\frac{N!}{{N_{\uparrow}!}{N_{\downarrow}!}}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Where &amp;lt;math&amp;gt;N_{x}!&amp;lt;/math&amp;gt; denotes the factorial of the number of spins in spin state &amp;lt;math&amp;gt;x&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\Delta{S} = k_{B}\;ln\;\left(\displaystyle\frac{\Omega_{2}}{\Omega_{1}}\right)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\Omega_{2} = \frac{1000!}{999!1!} = 1000&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \Omega_{1} = \frac{1000!}{1000!} = 1&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\Delta{S} = k_{B}\;ln\;1000 = 9.54 \times 10^{-23} JK^{-1}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\Delta{S_{mol}} = N_{A}k_{B}\;ln\;1000 = 57.4 \,JK^{-1}mol^{-1}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Magnetisation Values of 1D and 2D Lattices===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;M = \sum_i s_i&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====1D Lattice Magnetisation====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;M_{1D} =\;\;+1&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====2D Lattice Magnetisation====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;M_{2D} =\;\;+1&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Magnetisation at 0K====&lt;br /&gt;
&lt;br /&gt;
At 0K, no thermal energy is available to overcome the energetic barriers to spin flipping. Considering the Hemholtz free energy:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; A = E - TS &amp;lt;/math&amp;gt; &lt;br /&gt;
&lt;br /&gt;
A temperature of 0K nullifies the entropic contribution to the free energy. Thus the energetic driving force (which maximises parallel spin interactions) dominates the entropic driving force (which maximises multiplicity of lattice states). For an Ising Lattice with D =  3, N = 1000 at 0K, the alignment of all spins results in the minimum energy configuration  and an overall magnetisation of &amp;lt;math&amp;gt; M = \pm 1000 &amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
= Calculating the Energy and Magnetisation =&lt;br /&gt;
==Modifying the Files==&lt;br /&gt;
&lt;br /&gt;
===Energy and Magnetisation Functions===&lt;br /&gt;
&lt;br /&gt;
====Energy===&lt;br /&gt;
[[File:First_Ene_Method.PNG]]&lt;br /&gt;
&lt;br /&gt;
The above energy method segments a given lattice into lattice cells on the edges, corners or in the bulk of the lattice and calculates the energy interactions with its neighbours as appropriate.&lt;br /&gt;
&lt;br /&gt;
====Magnetisation====&lt;br /&gt;
[[File:First_Mag_Method.PNG]]&lt;br /&gt;
&lt;br /&gt;
The magnetisation method loops over all elements in the array representing the Ising lattice and adds the value of the spin to the magnetisation variable.&lt;br /&gt;
&lt;br /&gt;
==Testing the Files==&lt;br /&gt;
&lt;br /&gt;
===ILCheck.py===&lt;br /&gt;
&lt;br /&gt;
[[File:ILChecks.PNG]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Above, the results of the ILcheck.py script are presented.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= Introduction to the Monte Carlo Simulation =&lt;br /&gt;
==Average Energy and Magnetisation==&lt;br /&gt;
===Configurations of a 100 Spin System===&lt;br /&gt;
For a system of two spins, 4 configurations are possible (↑↑, ↓↓, ↑↓, ↓↑) i.e. &amp;lt;math&amp;gt;2^{2}&amp;lt;/math&amp;gt;. For a system of 100 spins, there are &amp;lt;math&amp;gt;2^{100}&amp;lt;/math&amp;gt; configurations. In the first example, the ↑↑ and ↓↓ are degenerate, as are the ↑↓ and ↓↑ configurations. Therefore, dividing the number of possible configurations by the multiplicity of each configuration (&amp;lt;math&amp;gt;2&amp;lt;/math&amp;gt;) gives the number of non-degenerate configurations. As previously stated, degenerate configurations are indistinguishable in the absence of an external magnetic field.&lt;br /&gt;
&lt;br /&gt;
For 100 spins, this gives &amp;lt;math&amp;gt;\displaystyle\frac{2^{100}}{2} = 6.338 \times 10^{29} &amp;lt;/math&amp;gt; distinguishable configurations.&lt;br /&gt;
&lt;br /&gt;
If processing speed permits &amp;lt;math&amp;gt; 1 \times 10^{9}&amp;lt;/math&amp;gt; calculations each second, the evaluation of a single value of &amp;lt;math&amp;gt;\left\langle M\right\rangle_T&amp;lt;/math&amp;gt; would last &amp;lt;math&amp;gt; 6.338 \times 10^{20} &amp;lt;/math&amp;gt; seconds or &amp;lt;math&amp;gt; 1458 &amp;lt;/math&amp;gt; times the age of the Universe!&lt;br /&gt;
&lt;br /&gt;
==Modifying IsingLattice.py==&lt;br /&gt;
&lt;br /&gt;
===Monte Carlo and Statistics Methods===&lt;br /&gt;
[[File:Monte_Carlo.PNG]]&lt;br /&gt;
&lt;br /&gt;
[[File:stats.PNG]]&lt;br /&gt;
&lt;br /&gt;
The Metropolis Monte Carlo (MMC) algorithm provides a computationally inexpensive path from random initial states to the minimum free energy states of the Ising lattices generated. First, a random 2D Ising lattice is generated. A single random spin within this lattice is &amp;quot;flipped&amp;quot; and the resulting (internal) energy change between these states is measured. Recalling the relationship between the Hemholtz free energy, internal energy and entropy, it follows that a decrease in internal energy also lowers the free energy of the system: thus the configuration change is accepted.&lt;br /&gt;
&lt;br /&gt;
In the case that the spin &amp;quot;flip&amp;quot; does not lower the internal energy, the MMC algorithm tests this configuration change against the Boltzman factor. In the canonical (NVT) ensemble, the free energy of the system is given by:&lt;br /&gt;
&lt;br /&gt;
:&amp;lt;math&amp;gt;A = -k_{B}T\,lnZ_{NVT} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
where Z is the canonical partition function which depends upon &amp;lt;math&amp;gt; e^{-\frac{\Delta E}{k_BT}} &amp;lt;/math&amp;gt;, the Boltzman factor. By choosing a random value in the interval [0,1)from a continuous uniformm probability distribution and rejecting any value of the Boltzman factor less than this value, ###&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Spontaneous Magnetisation===&lt;br /&gt;
&lt;br /&gt;
Below the Curie Temperature, &amp;lt;math&amp;gt; T_{C} &amp;lt;/math&amp;gt;, the energetic driving force dominates the entropic driving force, resulting in a highly ordered system and an overall magnetisation. The spins of the system align in order to maximise favourable coupling interactions rather than adopting a less ordered configuration of higher multiplicity. Therefore, when &amp;lt;math&amp;gt;T &amp;lt; T_C&amp;lt;/math&amp;gt;, the most probable configurations have an overall magnetisation resulting in &amp;lt;math&amp;gt;\left\langle M\right\rangle \neq 0&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
The plots of magnetisation per spin and energy per spin obtained from ILanim.py support this prediction. Below, the plots show that upon equilibration, the system adopts the minimum energy per spin: &amp;lt;math&amp;gt;E_{min_{spin}} = \frac{-NDJ}{N} = -DJ = -2&amp;lt;/math&amp;gt; and exhibits the maximum magnitude of magnetisation per spin: &amp;lt;math&amp;gt;|M_{spin}| = 1&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:2T=1.0.png]]&lt;br /&gt;
[[File:T=1.0.png]]&lt;br /&gt;
[[File:3T=1.0.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
An unknown system error prevented the statistics() function from printing the average values.&lt;br /&gt;
&lt;br /&gt;
=Accelerating the Code=&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Initial Method Speeds===&lt;br /&gt;
Taking 10 repeat measurements for the time taken to perform 2000 Monte Carlo steps resulted in&lt;br /&gt;
&lt;br /&gt;
* An average time of  &amp;lt;math&amp;gt;11.7s&amp;lt;/math&amp;gt; &lt;br /&gt;
* A standard error of &amp;lt;math&amp;gt;0.020s&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Updating Measurement===&lt;br /&gt;
&lt;br /&gt;
NOTE: ILtimetrial.py has been modified to:&lt;br /&gt;
* Perform a requested number of &#039;2000 Monte Carlo Step&#039; measurements&lt;br /&gt;
* Record these measurements in a CSV file&lt;br /&gt;
* Return the mean measuremd time and the Standard Error i.e.   &amp;lt;math&amp;gt; \frac{\sigma}{n} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:TimeTrialMethod.PNG]]&lt;br /&gt;
&lt;br /&gt;
===Updating Energy and Magnetisation Methods===&lt;br /&gt;
[[File:New_Mag_Method.PNG]]&lt;br /&gt;
[[File:New_Ene_Method.PNG]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Updated Method Speeds===&lt;br /&gt;
[[File:TimeTrial.PNG]]&lt;br /&gt;
&lt;br /&gt;
Taking 30 measurements of the time taken to perform 2000 Monte Carlo Steps resulted in:&lt;br /&gt;
&lt;br /&gt;
* An average time of &amp;lt;math&amp;gt;\displaystyle{0.87s}&amp;lt;/math&amp;gt;&lt;br /&gt;
* A standard error of &amp;lt;math&amp;gt;2.5 \times 10^{-3}s&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This represents a 93% decrease in the average computation time from the initial methods.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=The Effect of Temperature=&lt;br /&gt;
&lt;br /&gt;
==Correcting the Averaging  Code==&lt;br /&gt;
&lt;br /&gt;
===Finding a Delay Value===&lt;br /&gt;
To quickly find a value for &amp;lt;math&amp;gt; N_{d}&amp;lt;/math&amp;gt;, the minimum number of cycles typically needed for the equilibration of a system of within the lattice and temperature ranges of interest, it was assumed that:&lt;br /&gt;
&lt;br /&gt;
* Larger lattices would require more Monte Carlo steps to reach equilibrium from their initial, random configurations&lt;br /&gt;
&lt;br /&gt;
* Lattices at lower temperatures would require more Monte Carlo steps to reach equilibrium from their initial, random configurations.&lt;br /&gt;
&lt;br /&gt;
Therefore, an initial value for &amp;lt;math&amp;gt; N_{d}&amp;lt;/math&amp;gt; was found for a &amp;lt;math&amp;gt; 128\times128 &amp;lt;/math&amp;gt; lattice at a temperature of &amp;lt;math&amp;gt;0.5&amp;lt;/math&amp;gt; reduced temperature units.&lt;br /&gt;
*&amp;lt;math&amp;gt; N_{d} = 185000 &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
By this number of steps, all smaller lattices at all higher temperatures were found to have equilibrated also. Thus, this value of&amp;lt;math&amp;gt; N_{d}&amp;lt;/math&amp;gt; was accepted as an appropriate delay.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:AFinFrame 128 3e5 T= 0.5line.png|400px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
For the 128x128 lattices at T=0.5, equilibration was ensured from 185000 steps onwards.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Smaller lattices at the same temperature did indeed equilibrate more slowly, but all equilibrated within &amp;lt;math&amp;gt; N_{d}&amp;lt;/math&amp;gt; MC steps.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:AFinFrame 64 3e5 T= 0.5line.png|400px]]&lt;br /&gt;
[[File:AFinFrame 32 3e5 T= 0.5line2.png|400px]]&lt;br /&gt;
[[File:AFinFrame 16 3e5 T= 0.5line2.png|400px]]&lt;br /&gt;
[[File:AFinFrame 8 3e5 T= 0.5line.png|400px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The figure below shows the modifications made to IsingLattice.py to incorporate the &amp;lt;math&amp;gt; N_{d} &amp;lt;/math&amp;gt; step delay.&lt;br /&gt;
&lt;br /&gt;
==Running over a Range of Temperatures==&lt;br /&gt;
&lt;br /&gt;
To examine the effect of temperature on the average energy &amp;lt;math&amp;gt; \left\langle E\right\rangle &amp;lt;/math&amp;gt; and average magnetisation &amp;lt;math&amp;gt; \left\langle M\right\rangle &amp;lt;/math&amp;gt; of Ising lattices at equilibrium, the following parameters were used:&lt;br /&gt;
&lt;br /&gt;
* Temperature Range: &amp;lt;math&amp;gt;  0.5 - 5 &amp;lt;/math&amp;gt; reduced units&lt;br /&gt;
* Temperature Interval: &amp;lt;math&amp;gt;0.01&amp;lt;/math&amp;gt; reduced units (&amp;lt;math&amp;gt;450&amp;lt;/math&amp;gt; temperature values)&lt;br /&gt;
* Number of MMC Steps per Temperature value: &amp;lt;math&amp;gt; 2 \times 10^5 &amp;lt;/math&amp;gt; with the aforementioned value of &amp;lt;math&amp;gt; N_{d} = 1.85 \times 10^5 &amp;lt;/math&amp;gt; Monte Carlo steps&lt;br /&gt;
* Lattice Sizes:  &amp;lt;math&amp;gt; 2 \times 2 &amp;lt;/math&amp;gt;, &amp;lt;math&amp;gt; 4 \times 4 &amp;lt;/math&amp;gt; , &amp;lt;math&amp;gt; 8 \times 8 &amp;lt;/math&amp;gt; , &amp;lt;math&amp;gt; 16 \times 16 &amp;lt;/math&amp;gt; , &amp;lt;math&amp;gt; 32 \times 32 &amp;lt;/math&amp;gt; , &amp;lt;math&amp;gt; 64 \times 64 &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Plots of  &amp;lt;math&amp;gt; \left\langle E\right\rangle &amp;lt;/math&amp;gt; and  &amp;lt;math&amp;gt; \left\langle M\right\rangle &amp;lt;/math&amp;gt; per spin as versus temperature are presented below for each lattice size. Errorbars have been implemented to demonstrate how &#039;&#039;well-behaved&#039;&#039; lattice systems of each size are at each temperature, that is, how temperature and lattice size affect the size of the variations in the expected values. For the error calculations, the standard errors, &amp;lt;math&amp;gt; \sigma_\bar{X} &amp;lt;/math&amp;gt;,  in &amp;lt;math&amp;gt; \left\langle E\right\rangle &amp;lt;/math&amp;gt; and  &amp;lt;math&amp;gt; \left\langle M\right\rangle &amp;lt;/math&amp;gt; per spin have been used:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====8x8====&lt;br /&gt;
&lt;br /&gt;
[[File:8x8e+error.png]] [[File:8x8m+error.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
A Python script has been written to generate a plot of &amp;lt;math&amp;gt;\left\langle E\right\rangle&amp;lt;/math&amp;gt; or &amp;lt;math&amp;gt;\left\langle M\right\rangle&amp;lt;/math&amp;gt; against temperature based upon user input. A screenshot of this code has been inserted below.&lt;br /&gt;
&lt;br /&gt;
[[File:ExpectedvsTemp.PNG|200px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=The Effect of System Size=&lt;br /&gt;
&lt;br /&gt;
==Scaling the System Size==&lt;br /&gt;
&lt;br /&gt;
===More Lattice Sizes===&lt;br /&gt;
&lt;br /&gt;
====2x2====&lt;br /&gt;
[[File:2x2e+error.png]] [[File:2x2m+error.png]]&lt;br /&gt;
&lt;br /&gt;
====4x4====&lt;br /&gt;
[[File:4x4e+error.png]] [[File:4x4m+error.png]]&lt;br /&gt;
&lt;br /&gt;
====16x16====&lt;br /&gt;
[[File:16x16e+error.png]] [[File:16x16m+error.png]]&lt;br /&gt;
&lt;br /&gt;
====32x32====&lt;br /&gt;
[[File:32x32e+error.png]] [[File:32x32m+error.png]]&lt;br /&gt;
&lt;br /&gt;
====64x64====&lt;br /&gt;
[[File:64x64e+error.png]] [[File:64x64m+error.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Scrutiny of the plots of average energy per spin for each lattice size reveals an increase in the errorbar width with increasing lattice size. This is most notable in the low temperature region of the plots. Between the &amp;lt;math&amp;gt; 8x8 &amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt; 16x16 &amp;lt;/math&amp;gt; lattices, the long range fluctuations become suddenly prominent. The 16x16 lattice is the first (in the range of sizes tested)to clearly capture these fluctuations. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=Determining the Heat Capacity=&lt;br /&gt;
&lt;br /&gt;
==Calculating the Heat Capacity==&lt;br /&gt;
&lt;br /&gt;
===Heat Capacity Derivation===&lt;br /&gt;
Working in the canonical ensemble (constant volume), the heat capacity &amp;lt;math&amp;gt; C_V &amp;lt;/math&amp;gt; is given by:&lt;br /&gt;
&lt;br /&gt;
:&amp;lt;math&amp;gt;C_V = \frac{\partial \left\langle E\right\rangle}{\partial T}_V&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
where &amp;lt;math&amp;gt;\left\langle E\right\rangle&amp;lt;/math&amp;gt; is the average total energy or expected value of the internal energy of the system.&lt;br /&gt;
&lt;br /&gt;
: &amp;lt;math&amp;gt; \left\langle E\right\rangle = - \frac{\partial ln Q}{\partial \beta} = -\frac{1}{Q}\frac{\partial Q}{\partial \beta} &amp;lt;/math&amp;gt;&lt;br /&gt;
where &amp;lt;math&amp;gt; Q&amp;lt;/math&amp;gt; is the partition function for the system of N interacting spins.&lt;br /&gt;
&lt;br /&gt;
By evaluating the second form of the partial derivative with respect to &amp;lt;math&amp;gt; \beta&amp;lt;/math&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \left\langle E\right\rangle = -\frac{1}{Q}\frac{\partial Q}{\partial \beta} = \frac{\Sigma \epsilon_{i} e^{-\beta \epsilon_{i}}}{\Sigma e^{-\beta \epsilon_{i}}} &amp;lt;/math&amp;gt; &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Applying the product rule enables the differentiation of this expression for &amp;lt;math&amp;gt;\left\langle E\right\rangle&amp;lt;/math&amp;gt; with respect to temperature, giving:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\frac{\partial \left\langle E\right\rangle}{\partial T} = \frac{\Sigma \epsilon_{i} \frac{\epsilon_i}{k_BT^2}e^{-\beta \epsilon_{i}}}{\Sigma e^{-\beta \epsilon_{i}}} - \frac{\Sigma \epsilon_i e^{-\beta \epsilon_i}\cdot \frac{\epsilon_i}{k_BT^2}e^{-\beta \epsilon_i}}{(\Sigma e^{-\beta \epsilon_{i}})^2}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\frac{\partial \left\langle E\right\rangle}{\partial T}  = \frac{1}{k_BT^2}\left[\frac{\Sigma \epsilon_i^2 e^{-\beta \epsilon_i}}{\Sigma e^{-\beta \epsilon_i}} - \left(\frac{\Sigma \epsilon_{i} e^{-\beta \epsilon_{i}}}{\Sigma e^{-\beta \epsilon_{i}}}\right)^2\right] &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\frac{\partial \left\langle E\right\rangle}{\partial T}  = \frac{1}{k_BT^2}\left[\left\langle E^2\right\rangle - \left\langle E\right\rangle^2 \right] &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Thus,&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\frac{\partial \left\langle E\right\rangle}{\partial T} = \frac{Var[E]}{k_BT^2} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Heat Capacity versus Temperature===&lt;br /&gt;
Below, a screenshot of the Python script written to produce plots of &amp;lt;math&amp;gt; C_V &amp;lt;/math&amp;gt; against &amp;lt;math&amp;gt; T &amp;lt;/math&amp;gt;, together with the output images of this script.&lt;br /&gt;
 &lt;br /&gt;
[[File:HeatCapScript.PNG]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====2x2====&lt;br /&gt;
[[File:HC2.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====4x4====&lt;br /&gt;
[[File:HC4.png]]&lt;br /&gt;
&lt;br /&gt;
====8x8====&lt;br /&gt;
[[File:HC8.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====16x16====&lt;br /&gt;
[[File:HC16.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====32x32====&lt;br /&gt;
[[File:HC32.png]]&lt;br /&gt;
&lt;br /&gt;
== Locating the Curie Temperature ==&lt;br /&gt;
&lt;br /&gt;
===C++ Data Comparison===&lt;br /&gt;
&lt;br /&gt;
[[File:CHC2.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Polyfitting of C++ Data===&lt;br /&gt;
&lt;br /&gt;
====Fitting a Polynomial to the Entire Range====&lt;br /&gt;
&lt;br /&gt;
[[File:15Polyc2x2.png]]&lt;br /&gt;
Polynomials with 5 terms and above were found to match the data in the vicinity of the critical region considerably well. Below 7 terms, the &#039;&#039;tails&#039;&#039; of the plot were matched poorly. In the above example, a polynomial of 15 terms was fit to the data.&lt;br /&gt;
&lt;br /&gt;
=== Python Scripts ===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
* Frenkel, Daan, et al. Understanding Molecular Simulation : From Algorithms to Applications, Elsevier Science &amp;amp; Technology, 2001&lt;/div&gt;</summary>
		<author><name>Jj1516</name></author>
	</entry>
	<entry>
		<id>https://chemwiki.ch.ic.ac.uk/index.php?title=File:HeatCapScript.PNG&amp;diff=736545</id>
		<title>File:HeatCapScript.PNG</title>
		<link rel="alternate" type="text/html" href="https://chemwiki.ch.ic.ac.uk/index.php?title=File:HeatCapScript.PNG&amp;diff=736545"/>
		<updated>2018-11-20T22:01:41Z</updated>

		<summary type="html">&lt;p&gt;Jj1516: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Jj1516</name></author>
	</entry>
	<entry>
		<id>https://chemwiki.ch.ic.ac.uk/index.php?title=Rep:JJ1516Ising&amp;diff=736534</id>
		<title>Rep:JJ1516Ising</title>
		<link rel="alternate" type="text/html" href="https://chemwiki.ch.ic.ac.uk/index.php?title=Rep:JJ1516Ising&amp;diff=736534"/>
		<updated>2018-11-20T21:40:44Z</updated>

		<summary type="html">&lt;p&gt;Jj1516: /* Accelerating the Code */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Ex Script Link:&lt;br /&gt;
https://wiki.ch.ic.ac.uk/wiki/index.php?title=Third_year_CMP_compulsory_experiment&lt;br /&gt;
&lt;br /&gt;
= Introduction to the Ising Model =&lt;br /&gt;
&lt;br /&gt;
== The Model ==&lt;br /&gt;
&lt;br /&gt;
=== Minimum Energy State ===&lt;br /&gt;
====Minimum Interaction Energy====&lt;br /&gt;
The interaction energy of an Ising lattice is given by:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;E = -\frac{1}{2}J\displaystyle\sum_{i}^{N} \displaystyle\sum_{j\;\in\;{neighbours}\;(i)} \!\!\!\!\!\!\!\!\!\!\!\!s_{i}s_{j}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In an Ising lattice with D dimensions and periodic boundary conditions, a given spin &amp;lt;math&amp;gt; s_i&amp;lt;/math&amp;gt; has 2D neighbours.&lt;br /&gt;
&lt;br /&gt;
The minimum interaction energy is achieved when all spins in the lattice are aligned (all ↑ or all ↓). As  such, any spin &amp;lt;math&amp;gt; s_i&amp;lt;/math&amp;gt; must be aligned with all 2D of its neighbours. That is, &amp;lt;math&amp;gt;s_{i}s_{j} = 1&amp;lt;/math&amp;gt; for all &amp;lt;math&amp;gt;j&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Therefore, for any &amp;lt;math&amp;gt; s_i&amp;lt;/math&amp;gt;, the sum of its interactions is &amp;lt;math&amp;gt;\displaystyle\sum_{j\;\in\;{neighbours}\;(i)} \!\!\!\!\!\!\!\!\!\!\!\!s_{i}s_{j} = 2D &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
As this is true for all N spins in the lattice, it follows that &amp;lt;math&amp;gt;\displaystyle\sum_{i}^{N} 2D = 2DN&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Thus the minimum interaction energy is given by:&lt;br /&gt;
&lt;br /&gt;
:&amp;lt;math&amp;gt;E_{min} = -\frac{1}{2}J\cdot2DN = - DNJ &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Entropy of the Minimum Energy State====&lt;br /&gt;
&lt;br /&gt;
The entropy of a state is given by:&lt;br /&gt;
&lt;br /&gt;
:&amp;lt;math&amp;gt;S = k\; ln\; \Omega &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Where &amp;lt;math&amp;gt; \Omega &amp;lt;/math&amp;gt; is the multiplicity of the state, the number of degenerate configurations of said state. The minimum energy state is achievable with all spins ↑ or with all spins ↓. In the absence of an external magnetic field, these configurations are degenerate and indistinguishable giving &amp;lt;math&amp;gt; \Omega = 2 &amp;lt;/math&amp;gt; for this state. Therefore,&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; S_{E_{min}}  = k_{B}\; ln\; 2 = 0.693k_{B} = 9.57 \times 10^{-24} J\!\cdot\!\! K^{-1}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Phase Transitions ==&lt;br /&gt;
&lt;br /&gt;
=== Changes to Minimum Energy Configuration ===&lt;br /&gt;
&lt;br /&gt;
====Energy Change ====&lt;br /&gt;
The energy change &amp;lt;math&amp;gt; \Delta E&amp;lt;/math&amp;gt; associated with a single spin &#039;flip&#039; from the lowest energy onfiguration may be calculated by considering the change in the interaction energy with the spin&#039;s neighbours.&lt;br /&gt;
&lt;br /&gt;
Let &amp;lt;math&amp;gt; D = 3, N = 1000 &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\Delta{E} = E_1 - E_0&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;E_1&amp;lt;/math&amp;gt; Interaction energy after one spin has been &#039;flipped&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;E_0&amp;lt;/math&amp;gt; Lowest energy configuration&lt;br /&gt;
&lt;br /&gt;
[[Image:Task 2 table.PNG]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\displaystyle\sum_{interactions} = -2D + 2D(2D-2) + 2D[N-(2D+1)] &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; = 2DN - 8D &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;E_1 = \displaystyle-\frac{1}{2}J\;\sum_{interactions} = 4DJ - DNJ&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\Delta{E} = E_1 - E_0 = 4DJ - DNJ + DNJ = +4DJ = +12J&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This energy change is independent of &amp;lt;math&amp;gt; N&amp;lt;/math&amp;gt; and depends only on the dimension size and the coupling constant &amp;lt;math&amp;gt; J &amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
In this calculation, the following assumption has been made.&lt;br /&gt;
&lt;br /&gt;
* The lattice dimensions are infinite relative to the size of each cell&lt;br /&gt;
&lt;br /&gt;
This allows &#039;&#039;&#039;any&#039;&#039;&#039; cell to be treated as the centre of the lattice. As every cell interacts with 2D neighbours, flipping any cell in the minimum energy configuration results in the same energy change. Alternatively, the periodic boundary conditions of the Ising model remove the necessity for such an assumption. As a consequence, the absence of &amp;lt;math&amp;gt; N &amp;lt;/math&amp;gt; from the resulting energy change is justified.&lt;br /&gt;
&lt;br /&gt;
====Entropy Change====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; S = k_{B}\; ln\; \Omega &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\Omega = \displaystyle\frac{N!}{{N_{\uparrow}!}{N_{\downarrow}!}}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Where &amp;lt;math&amp;gt;N_{x}!&amp;lt;/math&amp;gt; denotes the factorial of the number of spins in spin state &amp;lt;math&amp;gt;x&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\Delta{S} = k_{B}\;ln\;\left(\displaystyle\frac{\Omega_{2}}{\Omega_{1}}\right)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\Omega_{2} = \frac{1000!}{999!1!} = 1000&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \Omega_{1} = \frac{1000!}{1000!} = 1&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\Delta{S} = k_{B}\;ln\;1000 = 9.54 \times 10^{-23} JK^{-1}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\Delta{S_{mol}} = N_{A}k_{B}\;ln\;1000 = 57.4 \,JK^{-1}mol^{-1}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Magnetisation Values of 1D and 2D Lattices===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;M = \sum_i s_i&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====1D Lattice Magnetisation====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;M_{1D} =\;\;+1&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====2D Lattice Magnetisation====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;M_{2D} =\;\;+1&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Magnetisation at 0K====&lt;br /&gt;
&lt;br /&gt;
At 0K, no thermal energy is available to overcome the energetic barriers to spin flipping. Considering the Hemholtz free energy:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; A = E - TS &amp;lt;/math&amp;gt; &lt;br /&gt;
&lt;br /&gt;
A temperature of 0K nullifies the entropic contribution to the free energy. Thus the energetic driving force (which maximises parallel spin interactions) dominates the entropic driving force (which maximises multiplicity of lattice states). For an Ising Lattice with D =  3, N = 1000 at 0K, the alignment of all spins results in the minimum energy configuration  and an overall magnetisation of &amp;lt;math&amp;gt; M = \pm 1000 &amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
= Calculating the Energy and Magnetisation =&lt;br /&gt;
==Modifying the Files==&lt;br /&gt;
&lt;br /&gt;
===Energy and Magnetisation Functions===&lt;br /&gt;
&lt;br /&gt;
====Energy===&lt;br /&gt;
[[File:First_Ene_Method.PNG]]&lt;br /&gt;
&lt;br /&gt;
The above energy method segments a given lattice into lattice cells on the edges, corners or in the bulk of the lattice and calculates the energy interactions with its neighbours as appropriate.&lt;br /&gt;
&lt;br /&gt;
====Magnetisation====&lt;br /&gt;
[[File:First_Mag_Method.PNG]]&lt;br /&gt;
&lt;br /&gt;
The magnetisation method loops over all elements in the array representing the Ising lattice and adds the value of the spin to the magnetisation variable.&lt;br /&gt;
&lt;br /&gt;
==Testing the Files==&lt;br /&gt;
&lt;br /&gt;
===ILCheck.py===&lt;br /&gt;
&lt;br /&gt;
[[File:ILChecks.PNG]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Above, the results of the ILcheck.py script are presented.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= Introduction to the Monte Carlo Simulation =&lt;br /&gt;
==Average Energy and Magnetisation==&lt;br /&gt;
===Configurations of a 100 Spin System===&lt;br /&gt;
For a system of two spins, 4 configurations are possible (↑↑, ↓↓, ↑↓, ↓↑) i.e. &amp;lt;math&amp;gt;2^{2}&amp;lt;/math&amp;gt;. For a system of 100 spins, there are &amp;lt;math&amp;gt;2^{100}&amp;lt;/math&amp;gt; configurations. In the first example, the ↑↑ and ↓↓ are degenerate, as are the ↑↓ and ↓↑ configurations. Therefore, dividing the number of possible configurations by the multiplicity of each configuration (&amp;lt;math&amp;gt;2&amp;lt;/math&amp;gt;) gives the number of non-degenerate configurations. As previously stated, degenerate configurations are indistinguishable in the absence of an external magnetic field.&lt;br /&gt;
&lt;br /&gt;
For 100 spins, this gives &amp;lt;math&amp;gt;\displaystyle\frac{2^{100}}{2} = 6.338 \times 10^{29} &amp;lt;/math&amp;gt; distinguishable configurations.&lt;br /&gt;
&lt;br /&gt;
If processing speed permits &amp;lt;math&amp;gt; 1 \times 10^{9}&amp;lt;/math&amp;gt; calculations each second, the evaluation of a single value of &amp;lt;math&amp;gt;\left\langle M\right\rangle_T&amp;lt;/math&amp;gt; would last &amp;lt;math&amp;gt; 6.338 \times 10^{20} &amp;lt;/math&amp;gt; seconds or &amp;lt;math&amp;gt; 1458 &amp;lt;/math&amp;gt; times the age of the Universe!&lt;br /&gt;
&lt;br /&gt;
==Modifying IsingLattice.py==&lt;br /&gt;
&lt;br /&gt;
===Monte Carlo and Statistics Methods===&lt;br /&gt;
[[File:Monte_Carlo.PNG]]&lt;br /&gt;
&lt;br /&gt;
[[File:stats.PNG]]&lt;br /&gt;
&lt;br /&gt;
The Metropolis Monte Carlo (MMC) algorithm provides a computationally inexpensive path from random initial states to the minimum free energy states of the Ising lattices generated. First, a random 2D Ising lattice is generated. A single random spin within this lattice is &amp;quot;flipped&amp;quot; and the resulting (internal) energy change between these states is measured. Recalling the relationship between the Hemholtz free energy, internal energy and entropy, it follows that a decrease in internal energy also lowers the free energy of the system: thus the configuration change is accepted.&lt;br /&gt;
&lt;br /&gt;
In the case that the spin &amp;quot;flip&amp;quot; does not lower the internal energy, the MMC algorithm tests this configuration change against the Boltzman factor. In the canonical (NVT) ensemble, the free energy of the system is given by:&lt;br /&gt;
&lt;br /&gt;
:&amp;lt;math&amp;gt;A = -k_{B}T\,lnZ_{NVT} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
where Z is the canonical partition function which depends upon &amp;lt;math&amp;gt; e^{-\frac{\Delta E}{k_BT}} &amp;lt;/math&amp;gt;, the Boltzman factor. By choosing a random value in the interval [0,1)from a continuous uniformm probability distribution and rejecting any value of the Boltzman factor less than this value, ###&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Spontaneous Magnetisation===&lt;br /&gt;
&lt;br /&gt;
Below the Curie Temperature, &amp;lt;math&amp;gt; T_{C} &amp;lt;/math&amp;gt;, the energetic driving force dominates the entropic driving force, resulting in a highly ordered system and an overall magnetisation. The spins of the system align in order to maximise favourable coupling interactions rather than adopting a less ordered configuration of higher multiplicity. Therefore, when &amp;lt;math&amp;gt;T &amp;lt; T_C&amp;lt;/math&amp;gt;, the most probable configurations have an overall magnetisation resulting in &amp;lt;math&amp;gt;\left\langle M\right\rangle \neq 0&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
The plots of magnetisation per spin and energy per spin obtained from ILanim.py support this prediction. Below, the plots show that upon equilibration, the system adopts the minimum energy per spin: &amp;lt;math&amp;gt;E_{min_{spin}} = \frac{-NDJ}{N} = -DJ = -2&amp;lt;/math&amp;gt; and exhibits the maximum magnitude of magnetisation per spin: &amp;lt;math&amp;gt;|M_{spin}| = 1&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:2T=1.0.png]]&lt;br /&gt;
[[File:T=1.0.png]]&lt;br /&gt;
[[File:3T=1.0.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
An unknown system error prevented the statistics() function from printing the average values.&lt;br /&gt;
&lt;br /&gt;
==Accelerating the Code==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Initial Method Speeds===&lt;br /&gt;
Taking 10 repeat measurements for the time taken to perform 2000 Monte Carlo steps resulted in&lt;br /&gt;
&lt;br /&gt;
* An average time of  &amp;lt;math&amp;gt;11.7s&amp;lt;/math&amp;gt; &lt;br /&gt;
* A standard error of &amp;lt;math&amp;gt;0.020s&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Updating Measurement===&lt;br /&gt;
&lt;br /&gt;
NOTE: ILtimetrial.py has been modified to:&lt;br /&gt;
* Perform a requested number of &#039;2000 Monte Carlo Step&#039; measurements&lt;br /&gt;
* Record these measurements in a CSV file&lt;br /&gt;
* Return the mean measuremd time and the Standard Error i.e.   &amp;lt;math&amp;gt; \frac{\sigma}{n} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:TimeTrialMethod.PNG]]&lt;br /&gt;
&lt;br /&gt;
===Updating Energy and Magnetisation Methods===&lt;br /&gt;
[[File:New_Mag_Method.PNG]]&lt;br /&gt;
[[File:New_Ene_Method.PNG]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Updated Method Speeds===&lt;br /&gt;
[[File:TimeTrial.PNG]]&lt;br /&gt;
&lt;br /&gt;
Taking 30 measurements of the time taken to perform 2000 Monte Carlo Steps resulted in:&lt;br /&gt;
&lt;br /&gt;
* An average time of &amp;lt;math&amp;gt;\displaystyle{0.87s}&amp;lt;/math&amp;gt;&lt;br /&gt;
* A standard error of &amp;lt;math&amp;gt;2.5 \times 10^{-3}s&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This represents a 93% decrease in the average computation time from the initial methods.&lt;br /&gt;
&lt;br /&gt;
==The Effect of Temperature==&lt;br /&gt;
&lt;br /&gt;
===Correcting the Averaging  Code===&lt;br /&gt;
&lt;br /&gt;
To quickly find a value for &amp;lt;math&amp;gt; N_{d}&amp;lt;/math&amp;gt;, the minimum number of cycles typically needed for the equilibration of a system of within the lattice and temperature ranges of interest, it was assumed that:&lt;br /&gt;
&lt;br /&gt;
* Larger lattices would require more Monte Carlo steps to reach equilibrium from their initial, random configurations&lt;br /&gt;
&lt;br /&gt;
* Lattices at lower temperatures would require more Monte Carlo steps to reach equilibrium from their initial, random configurations.&lt;br /&gt;
&lt;br /&gt;
Therefore, an initial value for &amp;lt;math&amp;gt; N_{d}&amp;lt;/math&amp;gt; was found for a &amp;lt;math&amp;gt; 128\times128 &amp;lt;/math&amp;gt; lattice at a temperature of &amp;lt;math&amp;gt;0.5&amp;lt;/math&amp;gt; reduced temperature units.&lt;br /&gt;
*&amp;lt;math&amp;gt; N_{d} = 185000 &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
By this number of steps, all smaller lattices at all higher temperatures were found to have equilibrated also. Thus, this value of&amp;lt;math&amp;gt; N_{d}&amp;lt;/math&amp;gt; was accepted as an appropriate delay.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:AFinFrame 128 3e5 T= 0.5line.png|400px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
For the 128x128 lattices at T=0.5, equilibration was ensured from 185000 steps onwards.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Smaller lattices at the same temperature did indeed equilibrate more slowly, but all equilibrated within &amp;lt;math&amp;gt; N_{d}&amp;lt;/math&amp;gt; MC steps.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:AFinFrame 64 3e5 T= 0.5line.png|400px]]&lt;br /&gt;
[[File:AFinFrame 32 3e5 T= 0.5line2.png|400px]]&lt;br /&gt;
[[File:AFinFrame 16 3e5 T= 0.5line2.png|400px]]&lt;br /&gt;
[[File:AFinFrame 8 3e5 T= 0.5line.png|400px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The figure below shows the modifications made to IsingLattice.py to incorporate the &amp;lt;math&amp;gt; N_{d} &amp;lt;/math&amp;gt; step delay.&lt;br /&gt;
&lt;br /&gt;
===Running over a Range of Temperatures===&lt;br /&gt;
&lt;br /&gt;
To examine the effect of temperature on the average energy &amp;lt;math&amp;gt; \left\langle E\right\rangle &amp;lt;/math&amp;gt; and average magnetisation &amp;lt;math&amp;gt; \left\langle M\right\rangle &amp;lt;/math&amp;gt; of Ising lattices at equilibrium, the following parameters were used:&lt;br /&gt;
&lt;br /&gt;
* Temperature Range: &amp;lt;math&amp;gt;  0.5 - 5 &amp;lt;/math&amp;gt; reduced units&lt;br /&gt;
* Temperature Interval: &amp;lt;math&amp;gt;0.01&amp;lt;/math&amp;gt; reduced units (&amp;lt;math&amp;gt;450&amp;lt;/math&amp;gt; temperature values)&lt;br /&gt;
* Number of MMC Steps per Temperature value: &amp;lt;math&amp;gt; 2 \times 10^5 &amp;lt;/math&amp;gt; with the aforementioned value of &amp;lt;math&amp;gt; N_{d} = 1.85 \times 10^5 &amp;lt;/math&amp;gt; Monte Carlo steps&lt;br /&gt;
* Lattice Sizes:  &amp;lt;math&amp;gt; 2 \times 2 &amp;lt;/math&amp;gt;, &amp;lt;math&amp;gt; 4 \times 4 &amp;lt;/math&amp;gt; , &amp;lt;math&amp;gt; 8 \times 8 &amp;lt;/math&amp;gt; , &amp;lt;math&amp;gt; 16 \times 16 &amp;lt;/math&amp;gt; , &amp;lt;math&amp;gt; 32 \times 32 &amp;lt;/math&amp;gt; , &amp;lt;math&amp;gt; 64 \times 64 &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Plots of  &amp;lt;math&amp;gt; \left\langle E\right\rangle &amp;lt;/math&amp;gt; and  &amp;lt;math&amp;gt; \left\langle M\right\rangle &amp;lt;/math&amp;gt; per spin as versus temperature are presented below for each lattice size. Errorbars have been implemented to demonstrate how &#039;&#039;well-behaved&#039;&#039; lattice systems of each size are at each temperature, that is, how temperature and lattice size affect the size of the variations in the expected values. For the error calculations, the standard errors, &amp;lt;math&amp;gt; \sigma_\bar{X} &amp;lt;/math&amp;gt;,  in &amp;lt;math&amp;gt; \left\langle E\right\rangle &amp;lt;/math&amp;gt; and  &amp;lt;math&amp;gt; \left\langle M\right\rangle &amp;lt;/math&amp;gt; per spin have been used:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====8x8====&lt;br /&gt;
&lt;br /&gt;
[[File:8x8e+error.png]] [[File:8x8m+error.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
A Python script has been written to generate a plot of &amp;lt;math&amp;gt;\left\langle E\right\rangle&amp;lt;/math&amp;gt; or &amp;lt;math&amp;gt;\left\langle M\right\rangle&amp;lt;/math&amp;gt; against temperature based upon user input. A screenshot of this code has been inserted below.&lt;br /&gt;
&lt;br /&gt;
[[File:ExpectedvsTemp.PNG|200px]]&lt;br /&gt;
&lt;br /&gt;
===Scaling the System Size===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====2x2====&lt;br /&gt;
[[File:2x2e+error.png]] [[File:2x2m+error.png]]&lt;br /&gt;
&lt;br /&gt;
====4x4====&lt;br /&gt;
[[File:4x4e+error.png]] [[File:4x4m+error.png]]&lt;br /&gt;
&lt;br /&gt;
====16x16====&lt;br /&gt;
[[File:16x16e+error.png]] [[File:16x16m+error.png]]&lt;br /&gt;
&lt;br /&gt;
====32x32====&lt;br /&gt;
[[File:32x32e+error.png]] [[File:32x32m+error.png]]&lt;br /&gt;
&lt;br /&gt;
====64x64====&lt;br /&gt;
[[File:64x64e+error.png]] [[File:64x64m+error.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Determining the Heat Capacity==&lt;br /&gt;
&lt;br /&gt;
===Calculating the Heat Capacity===&lt;br /&gt;
Working in the canonical ensemble (constant volume), the heat capacity &amp;lt;math&amp;gt; C_V &amp;lt;/math&amp;gt; is given by:&lt;br /&gt;
&lt;br /&gt;
:&amp;lt;math&amp;gt;C_V = \frac{\partial \left\langle E\right\rangle}{\partial T}_V&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
where &amp;lt;math&amp;gt;\left\langle E\right\rangle&amp;lt;/math&amp;gt; is the average total energy or expected value of the internal energy of the system.&lt;br /&gt;
&lt;br /&gt;
: &amp;lt;math&amp;gt; \left\langle E\right\rangle = - \frac{\partial ln Q}{\partial \beta} = -\frac{1}{Q}\frac{\partial Q}{\partial \beta} &amp;lt;/math&amp;gt;&lt;br /&gt;
where &amp;lt;math&amp;gt; Q&amp;lt;/math&amp;gt; is the partition function for the system of N interacting spins.&lt;br /&gt;
&lt;br /&gt;
By evaluating the second form of the partial derivative with respect to &amp;lt;math&amp;gt; \beta&amp;lt;/math&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \left\langle E\right\rangle = -\frac{1}{Q}\frac{\partial Q}{\partial \beta} = \frac{\Sigma \epsilon_{i} e^{-\beta \epsilon_{i}}}{\Sigma e^{-\beta \epsilon_{i}}} &amp;lt;/math&amp;gt; &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Applying the product rule enables the differentiation of this expression for &amp;lt;math&amp;gt;\left\langle E\right\rangle&amp;lt;/math&amp;gt; with respect to temperature, giving:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\frac{\partial \left\langle E\right\rangle}{\partial T} = \frac{\Sigma \epsilon_{i} \frac{\epsilon_i}{k_BT^2}e^{-\beta \epsilon_{i}}}{\Sigma e^{-\beta \epsilon_{i}}} - \frac{\Sigma \epsilon_i e^{-\beta \epsilon_i}\cdot \frac{\epsilon_i}{k_BT^2}e^{-\beta \epsilon_i}}{(\Sigma e^{-\beta \epsilon_{i}})^2}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\frac{\partial \left\langle E\right\rangle}{\partial T}  = \frac{1}{k_BT^2}\left[\frac{\Sigma \epsilon_i^2 e^{-\beta \epsilon_i}}{\Sigma e^{-\beta \epsilon_i}} - \left(\frac{\Sigma \epsilon_{i} e^{-\beta \epsilon_{i}}}{\Sigma e^{-\beta \epsilon_{i}}}\right)^2\right] &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\frac{\partial \left\langle E\right\rangle}{\partial T}  = \frac{1}{k_BT^2}\left[\left\langle E^2\right\rangle - \left\langle E\right\rangle^2 \right] &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Thus,&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\frac{\partial \left\langle E\right\rangle}{\partial T} = \frac{Var[E]}{k_BT^2} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Heat Capacity versus Temperature===&lt;br /&gt;
&lt;br /&gt;
====2x2====&lt;br /&gt;
[[File:HC2.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====4x4====&lt;br /&gt;
[[File:HC4.png]]&lt;br /&gt;
&lt;br /&gt;
====8x8====&lt;br /&gt;
[[File:HC8.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====16x16====&lt;br /&gt;
[[File:HC16.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====32x32====&lt;br /&gt;
[[File:HC32.png]]&lt;br /&gt;
&lt;br /&gt;
== Locating the Curie Temperature ==&lt;br /&gt;
&lt;br /&gt;
===C++ Data Comparison===&lt;br /&gt;
&lt;br /&gt;
[[File:CHC2.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Polyfitting of C++ Data===&lt;br /&gt;
&lt;br /&gt;
====Fitting a Polynomial to the Entire Range====&lt;br /&gt;
&lt;br /&gt;
[[File:15Polyc2x2.png]]&lt;br /&gt;
Polynomials with 5 terms and above were found to match the data in the vicinity of the critical region considerably well. Below 7 terms, the &#039;&#039;tails&#039;&#039; of the plot were matched poorly. In the above example, a polynomial of 15 terms was fit to the data.&lt;br /&gt;
&lt;br /&gt;
=== Python Scripts ===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
* Frenkel, Daan, et al. Understanding Molecular Simulation : From Algorithms to Applications, Elsevier Science &amp;amp; Technology, 2001&lt;/div&gt;</summary>
		<author><name>Jj1516</name></author>
	</entry>
	<entry>
		<id>https://chemwiki.ch.ic.ac.uk/index.php?title=Rep:JJ1516Ising&amp;diff=736533</id>
		<title>Rep:JJ1516Ising</title>
		<link rel="alternate" type="text/html" href="https://chemwiki.ch.ic.ac.uk/index.php?title=Rep:JJ1516Ising&amp;diff=736533"/>
		<updated>2018-11-20T21:37:28Z</updated>

		<summary type="html">&lt;p&gt;Jj1516: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Ex Script Link:&lt;br /&gt;
https://wiki.ch.ic.ac.uk/wiki/index.php?title=Third_year_CMP_compulsory_experiment&lt;br /&gt;
&lt;br /&gt;
= Introduction to the Ising Model =&lt;br /&gt;
&lt;br /&gt;
== The Model ==&lt;br /&gt;
&lt;br /&gt;
=== Minimum Energy State ===&lt;br /&gt;
====Minimum Interaction Energy====&lt;br /&gt;
The interaction energy of an Ising lattice is given by:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;E = -\frac{1}{2}J\displaystyle\sum_{i}^{N} \displaystyle\sum_{j\;\in\;{neighbours}\;(i)} \!\!\!\!\!\!\!\!\!\!\!\!s_{i}s_{j}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In an Ising lattice with D dimensions and periodic boundary conditions, a given spin &amp;lt;math&amp;gt; s_i&amp;lt;/math&amp;gt; has 2D neighbours.&lt;br /&gt;
&lt;br /&gt;
The minimum interaction energy is achieved when all spins in the lattice are aligned (all ↑ or all ↓). As  such, any spin &amp;lt;math&amp;gt; s_i&amp;lt;/math&amp;gt; must be aligned with all 2D of its neighbours. That is, &amp;lt;math&amp;gt;s_{i}s_{j} = 1&amp;lt;/math&amp;gt; for all &amp;lt;math&amp;gt;j&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Therefore, for any &amp;lt;math&amp;gt; s_i&amp;lt;/math&amp;gt;, the sum of its interactions is &amp;lt;math&amp;gt;\displaystyle\sum_{j\;\in\;{neighbours}\;(i)} \!\!\!\!\!\!\!\!\!\!\!\!s_{i}s_{j} = 2D &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
As this is true for all N spins in the lattice, it follows that &amp;lt;math&amp;gt;\displaystyle\sum_{i}^{N} 2D = 2DN&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Thus the minimum interaction energy is given by:&lt;br /&gt;
&lt;br /&gt;
:&amp;lt;math&amp;gt;E_{min} = -\frac{1}{2}J\cdot2DN = - DNJ &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Entropy of the Minimum Energy State====&lt;br /&gt;
&lt;br /&gt;
The entropy of a state is given by:&lt;br /&gt;
&lt;br /&gt;
:&amp;lt;math&amp;gt;S = k\; ln\; \Omega &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Where &amp;lt;math&amp;gt; \Omega &amp;lt;/math&amp;gt; is the multiplicity of the state, the number of degenerate configurations of said state. The minimum energy state is achievable with all spins ↑ or with all spins ↓. In the absence of an external magnetic field, these configurations are degenerate and indistinguishable giving &amp;lt;math&amp;gt; \Omega = 2 &amp;lt;/math&amp;gt; for this state. Therefore,&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; S_{E_{min}}  = k_{B}\; ln\; 2 = 0.693k_{B} = 9.57 \times 10^{-24} J\!\cdot\!\! K^{-1}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Phase Transitions ==&lt;br /&gt;
&lt;br /&gt;
=== Changes to Minimum Energy Configuration ===&lt;br /&gt;
&lt;br /&gt;
====Energy Change ====&lt;br /&gt;
The energy change &amp;lt;math&amp;gt; \Delta E&amp;lt;/math&amp;gt; associated with a single spin &#039;flip&#039; from the lowest energy onfiguration may be calculated by considering the change in the interaction energy with the spin&#039;s neighbours.&lt;br /&gt;
&lt;br /&gt;
Let &amp;lt;math&amp;gt; D = 3, N = 1000 &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\Delta{E} = E_1 - E_0&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;E_1&amp;lt;/math&amp;gt; Interaction energy after one spin has been &#039;flipped&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;E_0&amp;lt;/math&amp;gt; Lowest energy configuration&lt;br /&gt;
&lt;br /&gt;
[[Image:Task 2 table.PNG]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\displaystyle\sum_{interactions} = -2D + 2D(2D-2) + 2D[N-(2D+1)] &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; = 2DN - 8D &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;E_1 = \displaystyle-\frac{1}{2}J\;\sum_{interactions} = 4DJ - DNJ&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\Delta{E} = E_1 - E_0 = 4DJ - DNJ + DNJ = +4DJ = +12J&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This energy change is independent of &amp;lt;math&amp;gt; N&amp;lt;/math&amp;gt; and depends only on the dimension size and the coupling constant &amp;lt;math&amp;gt; J &amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
In this calculation, the following assumption has been made.&lt;br /&gt;
&lt;br /&gt;
* The lattice dimensions are infinite relative to the size of each cell&lt;br /&gt;
&lt;br /&gt;
This allows &#039;&#039;&#039;any&#039;&#039;&#039; cell to be treated as the centre of the lattice. As every cell interacts with 2D neighbours, flipping any cell in the minimum energy configuration results in the same energy change. Alternatively, the periodic boundary conditions of the Ising model remove the necessity for such an assumption. As a consequence, the absence of &amp;lt;math&amp;gt; N &amp;lt;/math&amp;gt; from the resulting energy change is justified.&lt;br /&gt;
&lt;br /&gt;
====Entropy Change====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; S = k_{B}\; ln\; \Omega &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\Omega = \displaystyle\frac{N!}{{N_{\uparrow}!}{N_{\downarrow}!}}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Where &amp;lt;math&amp;gt;N_{x}!&amp;lt;/math&amp;gt; denotes the factorial of the number of spins in spin state &amp;lt;math&amp;gt;x&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\Delta{S} = k_{B}\;ln\;\left(\displaystyle\frac{\Omega_{2}}{\Omega_{1}}\right)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\Omega_{2} = \frac{1000!}{999!1!} = 1000&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \Omega_{1} = \frac{1000!}{1000!} = 1&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\Delta{S} = k_{B}\;ln\;1000 = 9.54 \times 10^{-23} JK^{-1}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\Delta{S_{mol}} = N_{A}k_{B}\;ln\;1000 = 57.4 \,JK^{-1}mol^{-1}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Magnetisation Values of 1D and 2D Lattices===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;M = \sum_i s_i&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====1D Lattice Magnetisation====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;M_{1D} =\;\;+1&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====2D Lattice Magnetisation====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;M_{2D} =\;\;+1&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Magnetisation at 0K====&lt;br /&gt;
&lt;br /&gt;
At 0K, no thermal energy is available to overcome the energetic barriers to spin flipping. Considering the Hemholtz free energy:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; A = E - TS &amp;lt;/math&amp;gt; &lt;br /&gt;
&lt;br /&gt;
A temperature of 0K nullifies the entropic contribution to the free energy. Thus the energetic driving force (which maximises parallel spin interactions) dominates the entropic driving force (which maximises multiplicity of lattice states). For an Ising Lattice with D =  3, N = 1000 at 0K, the alignment of all spins results in the minimum energy configuration  and an overall magnetisation of &amp;lt;math&amp;gt; M = \pm 1000 &amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
= Calculating the Energy and Magnetisation =&lt;br /&gt;
==Modifying the Files==&lt;br /&gt;
&lt;br /&gt;
===Energy and Magnetisation Functions===&lt;br /&gt;
&lt;br /&gt;
====Energy===&lt;br /&gt;
[[File:First_Ene_Method.PNG]]&lt;br /&gt;
&lt;br /&gt;
The above energy method segments a given lattice into lattice cells on the edges, corners or in the bulk of the lattice and calculates the energy interactions with its neighbours as appropriate.&lt;br /&gt;
&lt;br /&gt;
====Magnetisation====&lt;br /&gt;
[[File:First_Mag_Method.PNG]]&lt;br /&gt;
&lt;br /&gt;
The magnetisation method loops over all elements in the array representing the Ising lattice and adds the value of the spin to the magnetisation variable.&lt;br /&gt;
&lt;br /&gt;
==Testing the Files==&lt;br /&gt;
&lt;br /&gt;
===ILCheck.py===&lt;br /&gt;
&lt;br /&gt;
[[File:ILChecks.PNG]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Above, the results of the ILcheck.py script are presented.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= Introduction to the Monte Carlo Simulation =&lt;br /&gt;
==Average Energy and Magnetisation==&lt;br /&gt;
===Configurations of a 100 Spin System===&lt;br /&gt;
For a system of two spins, 4 configurations are possible (↑↑, ↓↓, ↑↓, ↓↑) i.e. &amp;lt;math&amp;gt;2^{2}&amp;lt;/math&amp;gt;. For a system of 100 spins, there are &amp;lt;math&amp;gt;2^{100}&amp;lt;/math&amp;gt; configurations. In the first example, the ↑↑ and ↓↓ are degenerate, as are the ↑↓ and ↓↑ configurations. Therefore, dividing the number of possible configurations by the multiplicity of each configuration (&amp;lt;math&amp;gt;2&amp;lt;/math&amp;gt;) gives the number of non-degenerate configurations. As previously stated, degenerate configurations are indistinguishable in the absence of an external magnetic field.&lt;br /&gt;
&lt;br /&gt;
For 100 spins, this gives &amp;lt;math&amp;gt;\displaystyle\frac{2^{100}}{2} = 6.338 \times 10^{29} &amp;lt;/math&amp;gt; distinguishable configurations.&lt;br /&gt;
&lt;br /&gt;
If processing speed permits &amp;lt;math&amp;gt; 1 \times 10^{9}&amp;lt;/math&amp;gt; calculations each second, the evaluation of a single value of &amp;lt;math&amp;gt;\left\langle M\right\rangle_T&amp;lt;/math&amp;gt; would last &amp;lt;math&amp;gt; 6.338 \times 10^{20} &amp;lt;/math&amp;gt; seconds or &amp;lt;math&amp;gt; 1458 &amp;lt;/math&amp;gt; times the age of the Universe!&lt;br /&gt;
&lt;br /&gt;
==Modifying IsingLattice.py==&lt;br /&gt;
&lt;br /&gt;
===Monte Carlo and Statistics Methods===&lt;br /&gt;
[[File:Monte_Carlo.PNG]]&lt;br /&gt;
&lt;br /&gt;
[[File:stats.PNG]]&lt;br /&gt;
&lt;br /&gt;
The Metropolis Monte Carlo (MMC) algorithm provides a computationally inexpensive path from random initial states to the minimum free energy states of the Ising lattices generated. First, a random 2D Ising lattice is generated. A single random spin within this lattice is &amp;quot;flipped&amp;quot; and the resulting (internal) energy change between these states is measured. Recalling the relationship between the Hemholtz free energy, internal energy and entropy, it follows that a decrease in internal energy also lowers the free energy of the system: thus the configuration change is accepted.&lt;br /&gt;
&lt;br /&gt;
In the case that the spin &amp;quot;flip&amp;quot; does not lower the internal energy, the MMC algorithm tests this configuration change against the Boltzman factor. In the canonical (NVT) ensemble, the free energy of the system is given by:&lt;br /&gt;
&lt;br /&gt;
:&amp;lt;math&amp;gt;A = -k_{B}T\,lnZ_{NVT} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
where Z is the canonical partition function which depends upon &amp;lt;math&amp;gt; e^{-\frac{\Delta E}{k_BT}} &amp;lt;/math&amp;gt;, the Boltzman factor. By choosing a random value in the interval [0,1)from a continuous uniformm probability distribution and rejecting any value of the Boltzman factor less than this value, ###&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Spontaneous Magnetisation===&lt;br /&gt;
&lt;br /&gt;
Below the Curie Temperature, &amp;lt;math&amp;gt; T_{C} &amp;lt;/math&amp;gt;, the energetic driving force dominates the entropic driving force, resulting in a highly ordered system and an overall magnetisation. The spins of the system align in order to maximise favourable coupling interactions rather than adopting a less ordered configuration of higher multiplicity. Therefore, when &amp;lt;math&amp;gt;T &amp;lt; T_C&amp;lt;/math&amp;gt;, the most probable configurations have an overall magnetisation resulting in &amp;lt;math&amp;gt;\left\langle M\right\rangle \neq 0&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
The plots of magnetisation per spin and energy per spin obtained from ILanim.py support this prediction. Below, the plots show that upon equilibration, the system adopts the minimum energy per spin: &amp;lt;math&amp;gt;E_{min_{spin}} = \frac{-NDJ}{N} = -DJ = -2&amp;lt;/math&amp;gt; and exhibits the maximum magnitude of magnetisation per spin: &amp;lt;math&amp;gt;|M_{spin}| = 1&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:2T=1.0.png]]&lt;br /&gt;
[[File:T=1.0.png]]&lt;br /&gt;
[[File:3T=1.0.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
An unknown system error prevented the statistics() function from printing the average values.&lt;br /&gt;
&lt;br /&gt;
==Accelerating the Code==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Initial Method Speeds===&lt;br /&gt;
Taking 10 repeat measurements for the time taken to perform 2000 Monte Carlo steps resulted in&lt;br /&gt;
&lt;br /&gt;
* An average time of  &amp;lt;math&amp;gt;11.7s&amp;lt;/math&amp;gt; &lt;br /&gt;
* A standard error of &amp;lt;math&amp;gt;0.020s&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Updating Measurement===&lt;br /&gt;
&lt;br /&gt;
NOTE: ILtimetrial.py has been modified to:&lt;br /&gt;
* Perform a requested number of &#039;2000 Monte Carlo Step&#039; measurements&lt;br /&gt;
* Record these measurements in a CSV file&lt;br /&gt;
* Return the mean measuremd time and the Standard Error i.e.   &amp;lt;math&amp;gt; \frac{\sigma}{n} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:TimeTrialMethod.PNG]]&lt;br /&gt;
&lt;br /&gt;
===Updating Energy and Magnetisation Methods===&lt;br /&gt;
[[File:New_Mag_Method.PNG]]&lt;br /&gt;
[[File:New_Ene_Method.PNG]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Updated Method Speeds===&lt;br /&gt;
[[File:TimeTrial.PNG]]&lt;br /&gt;
&lt;br /&gt;
Taking 30 measurements of the time taken to perform 2000 Monte Carlo Steps resulted in:&lt;br /&gt;
&lt;br /&gt;
* An average time of &amp;lt;math&amp;gt;\displaystyle{0.87s}&amp;lt;/math&amp;gt;&lt;br /&gt;
* A standard error of &amp;lt;math&amp;gt;2.5 \times 10^{-3}s&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This represents a &#039;&#039;&#039;INSERT&#039;&#039;&#039;% decrease in computation time from the initial methods.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==The Effect of Temperature==&lt;br /&gt;
&lt;br /&gt;
===Correcting the Averaging  Code===&lt;br /&gt;
&lt;br /&gt;
To quickly find a value for &amp;lt;math&amp;gt; N_{d}&amp;lt;/math&amp;gt;, the minimum number of cycles typically needed for the equilibration of a system of within the lattice and temperature ranges of interest, it was assumed that:&lt;br /&gt;
&lt;br /&gt;
* Larger lattices would require more Monte Carlo steps to reach equilibrium from their initial, random configurations&lt;br /&gt;
&lt;br /&gt;
* Lattices at lower temperatures would require more Monte Carlo steps to reach equilibrium from their initial, random configurations.&lt;br /&gt;
&lt;br /&gt;
Therefore, an initial value for &amp;lt;math&amp;gt; N_{d}&amp;lt;/math&amp;gt; was found for a &amp;lt;math&amp;gt; 128\times128 &amp;lt;/math&amp;gt; lattice at a temperature of &amp;lt;math&amp;gt;0.5&amp;lt;/math&amp;gt; reduced temperature units.&lt;br /&gt;
*&amp;lt;math&amp;gt; N_{d} = 185000 &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
By this number of steps, all smaller lattices at all higher temperatures were found to have equilibrated also. Thus, this value of&amp;lt;math&amp;gt; N_{d}&amp;lt;/math&amp;gt; was accepted as an appropriate delay.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:AFinFrame 128 3e5 T= 0.5line.png|400px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
For the 128x128 lattices at T=0.5, equilibration was ensured from 185000 steps onwards.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Smaller lattices at the same temperature did indeed equilibrate more slowly, but all equilibrated within &amp;lt;math&amp;gt; N_{d}&amp;lt;/math&amp;gt; MC steps.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:AFinFrame 64 3e5 T= 0.5line.png|400px]]&lt;br /&gt;
[[File:AFinFrame 32 3e5 T= 0.5line2.png|400px]]&lt;br /&gt;
[[File:AFinFrame 16 3e5 T= 0.5line2.png|400px]]&lt;br /&gt;
[[File:AFinFrame 8 3e5 T= 0.5line.png|400px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The figure below shows the modifications made to IsingLattice.py to incorporate the &amp;lt;math&amp;gt; N_{d} &amp;lt;/math&amp;gt; step delay.&lt;br /&gt;
&lt;br /&gt;
===Running over a Range of Temperatures===&lt;br /&gt;
&lt;br /&gt;
To examine the effect of temperature on the average energy &amp;lt;math&amp;gt; \left\langle E\right\rangle &amp;lt;/math&amp;gt; and average magnetisation &amp;lt;math&amp;gt; \left\langle M\right\rangle &amp;lt;/math&amp;gt; of Ising lattices at equilibrium, the following parameters were used:&lt;br /&gt;
&lt;br /&gt;
* Temperature Range: &amp;lt;math&amp;gt;  0.5 - 5 &amp;lt;/math&amp;gt; reduced units&lt;br /&gt;
* Temperature Interval: &amp;lt;math&amp;gt;0.01&amp;lt;/math&amp;gt; reduced units (&amp;lt;math&amp;gt;450&amp;lt;/math&amp;gt; temperature values)&lt;br /&gt;
* Number of MMC Steps per Temperature value: &amp;lt;math&amp;gt; 2 \times 10^5 &amp;lt;/math&amp;gt; with the aforementioned value of &amp;lt;math&amp;gt; N_{d} = 1.85 \times 10^5 &amp;lt;/math&amp;gt; Monte Carlo steps&lt;br /&gt;
* Lattice Sizes:  &amp;lt;math&amp;gt; 2 \times 2 &amp;lt;/math&amp;gt;, &amp;lt;math&amp;gt; 4 \times 4 &amp;lt;/math&amp;gt; , &amp;lt;math&amp;gt; 8 \times 8 &amp;lt;/math&amp;gt; , &amp;lt;math&amp;gt; 16 \times 16 &amp;lt;/math&amp;gt; , &amp;lt;math&amp;gt; 32 \times 32 &amp;lt;/math&amp;gt; , &amp;lt;math&amp;gt; 64 \times 64 &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Plots of  &amp;lt;math&amp;gt; \left\langle E\right\rangle &amp;lt;/math&amp;gt; and  &amp;lt;math&amp;gt; \left\langle M\right\rangle &amp;lt;/math&amp;gt; per spin as versus temperature are presented below for each lattice size. Errorbars have been implemented to demonstrate how &#039;&#039;well-behaved&#039;&#039; lattice systems of each size are at each temperature, that is, how temperature and lattice size affect the size of the variations in the expected values. For the error calculations, the standard errors, &amp;lt;math&amp;gt; \sigma_\bar{X} &amp;lt;/math&amp;gt;,  in &amp;lt;math&amp;gt; \left\langle E\right\rangle &amp;lt;/math&amp;gt; and  &amp;lt;math&amp;gt; \left\langle M\right\rangle &amp;lt;/math&amp;gt; per spin have been used:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====8x8====&lt;br /&gt;
&lt;br /&gt;
[[File:8x8e+error.png]] [[File:8x8m+error.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
A Python script has been written to generate a plot of &amp;lt;math&amp;gt;\left\langle E\right\rangle&amp;lt;/math&amp;gt; or &amp;lt;math&amp;gt;\left\langle M\right\rangle&amp;lt;/math&amp;gt; against temperature based upon user input. A screenshot of this code has been inserted below.&lt;br /&gt;
&lt;br /&gt;
[[File:ExpectedvsTemp.PNG|200px]]&lt;br /&gt;
&lt;br /&gt;
===Scaling the System Size===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====2x2====&lt;br /&gt;
[[File:2x2e+error.png]] [[File:2x2m+error.png]]&lt;br /&gt;
&lt;br /&gt;
====4x4====&lt;br /&gt;
[[File:4x4e+error.png]] [[File:4x4m+error.png]]&lt;br /&gt;
&lt;br /&gt;
====16x16====&lt;br /&gt;
[[File:16x16e+error.png]] [[File:16x16m+error.png]]&lt;br /&gt;
&lt;br /&gt;
====32x32====&lt;br /&gt;
[[File:32x32e+error.png]] [[File:32x32m+error.png]]&lt;br /&gt;
&lt;br /&gt;
====64x64====&lt;br /&gt;
[[File:64x64e+error.png]] [[File:64x64m+error.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Determining the Heat Capacity==&lt;br /&gt;
&lt;br /&gt;
===Calculating the Heat Capacity===&lt;br /&gt;
Working in the canonical ensemble (constant volume), the heat capacity &amp;lt;math&amp;gt; C_V &amp;lt;/math&amp;gt; is given by:&lt;br /&gt;
&lt;br /&gt;
:&amp;lt;math&amp;gt;C_V = \frac{\partial \left\langle E\right\rangle}{\partial T}_V&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
where &amp;lt;math&amp;gt;\left\langle E\right\rangle&amp;lt;/math&amp;gt; is the average total energy or expected value of the internal energy of the system.&lt;br /&gt;
&lt;br /&gt;
: &amp;lt;math&amp;gt; \left\langle E\right\rangle = - \frac{\partial ln Q}{\partial \beta} = -\frac{1}{Q}\frac{\partial Q}{\partial \beta} &amp;lt;/math&amp;gt;&lt;br /&gt;
where &amp;lt;math&amp;gt; Q&amp;lt;/math&amp;gt; is the partition function for the system of N interacting spins.&lt;br /&gt;
&lt;br /&gt;
By evaluating the second form of the partial derivative with respect to &amp;lt;math&amp;gt; \beta&amp;lt;/math&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \left\langle E\right\rangle = -\frac{1}{Q}\frac{\partial Q}{\partial \beta} = \frac{\Sigma \epsilon_{i} e^{-\beta \epsilon_{i}}}{\Sigma e^{-\beta \epsilon_{i}}} &amp;lt;/math&amp;gt; &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Applying the product rule enables the differentiation of this expression for &amp;lt;math&amp;gt;\left\langle E\right\rangle&amp;lt;/math&amp;gt; with respect to temperature, giving:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\frac{\partial \left\langle E\right\rangle}{\partial T} = \frac{\Sigma \epsilon_{i} \frac{\epsilon_i}{k_BT^2}e^{-\beta \epsilon_{i}}}{\Sigma e^{-\beta \epsilon_{i}}} - \frac{\Sigma \epsilon_i e^{-\beta \epsilon_i}\cdot \frac{\epsilon_i}{k_BT^2}e^{-\beta \epsilon_i}}{(\Sigma e^{-\beta \epsilon_{i}})^2}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\frac{\partial \left\langle E\right\rangle}{\partial T}  = \frac{1}{k_BT^2}\left[\frac{\Sigma \epsilon_i^2 e^{-\beta \epsilon_i}}{\Sigma e^{-\beta \epsilon_i}} - \left(\frac{\Sigma \epsilon_{i} e^{-\beta \epsilon_{i}}}{\Sigma e^{-\beta \epsilon_{i}}}\right)^2\right] &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\frac{\partial \left\langle E\right\rangle}{\partial T}  = \frac{1}{k_BT^2}\left[\left\langle E^2\right\rangle - \left\langle E\right\rangle^2 \right] &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Thus,&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\frac{\partial \left\langle E\right\rangle}{\partial T} = \frac{Var[E]}{k_BT^2} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Heat Capacity versus Temperature===&lt;br /&gt;
&lt;br /&gt;
====2x2====&lt;br /&gt;
[[File:HC2.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====4x4====&lt;br /&gt;
[[File:HC4.png]]&lt;br /&gt;
&lt;br /&gt;
====8x8====&lt;br /&gt;
[[File:HC8.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====16x16====&lt;br /&gt;
[[File:HC16.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====32x32====&lt;br /&gt;
[[File:HC32.png]]&lt;br /&gt;
&lt;br /&gt;
== Locating the Curie Temperature ==&lt;br /&gt;
&lt;br /&gt;
===C++ Data Comparison===&lt;br /&gt;
&lt;br /&gt;
[[File:CHC2.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Polyfitting of C++ Data===&lt;br /&gt;
&lt;br /&gt;
====Fitting a Polynomial to the Entire Range====&lt;br /&gt;
&lt;br /&gt;
[[File:15Polyc2x2.png]]&lt;br /&gt;
Polynomials with 5 terms and above were found to match the data in the vicinity of the critical region considerably well. Below 7 terms, the &#039;&#039;tails&#039;&#039; of the plot were matched poorly. In the above example, a polynomial of 15 terms was fit to the data.&lt;br /&gt;
&lt;br /&gt;
=== Python Scripts ===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
* Frenkel, Daan, et al. Understanding Molecular Simulation : From Algorithms to Applications, Elsevier Science &amp;amp; Technology, 2001&lt;/div&gt;</summary>
		<author><name>Jj1516</name></author>
	</entry>
	<entry>
		<id>https://chemwiki.ch.ic.ac.uk/index.php?title=Rep:JJ1516Ising&amp;diff=736532</id>
		<title>Rep:JJ1516Ising</title>
		<link rel="alternate" type="text/html" href="https://chemwiki.ch.ic.ac.uk/index.php?title=Rep:JJ1516Ising&amp;diff=736532"/>
		<updated>2018-11-20T21:36:13Z</updated>

		<summary type="html">&lt;p&gt;Jj1516: /* Modifying IsingLattice.py */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Ex Script Link:&lt;br /&gt;
https://wiki.ch.ic.ac.uk/wiki/index.php?title=Third_year_CMP_compulsory_experiment&lt;br /&gt;
&lt;br /&gt;
= Introduction to the Ising Model =&lt;br /&gt;
&lt;br /&gt;
== The Model ==&lt;br /&gt;
&lt;br /&gt;
=== Minimum Energy State ===&lt;br /&gt;
====Minimum Interaction Energy====&lt;br /&gt;
The interaction energy of an Ising lattice is given by:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;E = -\frac{1}{2}J\displaystyle\sum_{i}^{N} \displaystyle\sum_{j\;\in\;{neighbours}\;(i)} \!\!\!\!\!\!\!\!\!\!\!\!s_{i}s_{j}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In an Ising lattice with D dimensions and periodic boundary conditions, a given spin &amp;lt;math&amp;gt; s_i&amp;lt;/math&amp;gt; has 2D neighbours.&lt;br /&gt;
&lt;br /&gt;
The minimum interaction energy is achieved when all spins in the lattice are aligned (all ↑ or all ↓). As  such, any spin &amp;lt;math&amp;gt; s_i&amp;lt;/math&amp;gt; must be aligned with all 2D of its neighbours. That is, &amp;lt;math&amp;gt;s_{i}s_{j} = 1&amp;lt;/math&amp;gt; for all &amp;lt;math&amp;gt;j&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Therefore, for any &amp;lt;math&amp;gt; s_i&amp;lt;/math&amp;gt;, the sum of its interactions is &amp;lt;math&amp;gt;\displaystyle\sum_{j\;\in\;{neighbours}\;(i)} \!\!\!\!\!\!\!\!\!\!\!\!s_{i}s_{j} = 2D &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
As this is true for all N spins in the lattice, it follows that &amp;lt;math&amp;gt;\displaystyle\sum_{i}^{N} 2D = 2DN&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Thus the minimum interaction energy is given by:&lt;br /&gt;
&lt;br /&gt;
:&amp;lt;math&amp;gt;E_{min} = -\frac{1}{2}J\cdot2DN = - DNJ &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Entropy of the Minimum Energy State====&lt;br /&gt;
&lt;br /&gt;
The entropy of a state is given by:&lt;br /&gt;
&lt;br /&gt;
:&amp;lt;math&amp;gt;S = k\; ln\; \Omega &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Where &amp;lt;math&amp;gt; \Omega &amp;lt;/math&amp;gt; is the multiplicity of the state, the number of degenerate configurations of said state. The minimum energy state is achievable with all spins ↑ or with all spins ↓. In the absence of an external magnetic field, these configurations are degenerate and indistinguishable giving &amp;lt;math&amp;gt; \Omega = 2 &amp;lt;/math&amp;gt; for this state. Therefore,&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; S_{E_{min}}  = k_{B}\; ln\; 2 = 0.693k_{B} = 9.57 \times 10^{-24} J\!\cdot\!\! K^{-1}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Phase Transitions ==&lt;br /&gt;
&lt;br /&gt;
=== Changes to Minimum Energy Configuration ===&lt;br /&gt;
&lt;br /&gt;
====Energy Change ====&lt;br /&gt;
The energy change &amp;lt;math&amp;gt; \Delta E&amp;lt;/math&amp;gt; associated with a single spin &#039;flip&#039; from the lowest energy onfiguration may be calculated by considering the change in the interaction energy with the spin&#039;s neighbours.&lt;br /&gt;
&lt;br /&gt;
Let &amp;lt;math&amp;gt; D = 3, N = 1000 &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\Delta{E} = E_1 - E_0&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;E_1&amp;lt;/math&amp;gt; Interaction energy after one spin has been &#039;flipped&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;E_0&amp;lt;/math&amp;gt; Lowest energy configuration&lt;br /&gt;
&lt;br /&gt;
[[Image:Task 2 table.PNG]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\displaystyle\sum_{interactions} = -2D + 2D(2D-2) + 2D[N-(2D+1)] &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; = 2DN - 8D &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;E_1 = \displaystyle-\frac{1}{2}J\;\sum_{interactions} = 4DJ - DNJ&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\Delta{E} = E_1 - E_0 = 4DJ - DNJ + DNJ = +4DJ = +12J&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This energy change is independent of &amp;lt;math&amp;gt; N&amp;lt;/math&amp;gt; and depends only on the dimension size and the coupling constant &amp;lt;math&amp;gt; J &amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
In this calculation, the following assumption has been made.&lt;br /&gt;
&lt;br /&gt;
* The lattice dimensions are infinite relative to the size of each cell&lt;br /&gt;
&lt;br /&gt;
This allows &#039;&#039;&#039;any&#039;&#039;&#039; cell to be treated as the centre of the lattice. As every cell interacts with 2D neighbours, flipping any cell in the minimum energy configuration results in the same energy change. Alternatively, the periodic boundary conditions of the Ising model remove the necessity for such an assumption. As a consequence, the absence of &amp;lt;math&amp;gt; N &amp;lt;/math&amp;gt; from the resulting energy change is justified.&lt;br /&gt;
&lt;br /&gt;
====Entropy Change====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; S = k_{B}\; ln\; \Omega &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\Omega = \displaystyle\frac{N!}{{N_{\uparrow}!}{N_{\downarrow}!}}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Where &amp;lt;math&amp;gt;N_{x}!&amp;lt;/math&amp;gt; denotes the factorial of the number of spins in spin state &amp;lt;math&amp;gt;x&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\Delta{S} = k_{B}\;ln\;\left(\displaystyle\frac{\Omega_{2}}{\Omega_{1}}\right)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\Omega_{2} = \frac{1000!}{999!1!} = 1000&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \Omega_{1} = \frac{1000!}{1000!} = 1&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\Delta{S} = k_{B}\;ln\;1000 = 9.54 \times 10^{-23} JK^{-1}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\Delta{S_{mol}} = N_{A}k_{B}\;ln\;1000 = 57.4 \,JK^{-1}mol^{-1}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Magnetisation Values of 1D and 2D Lattices===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;M = \sum_i s_i&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====1D Lattice Magnetisation====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;M_{1D} =\;\;+1&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====2D Lattice Magnetisation====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;M_{2D} =\;\;+1&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Magnetisation at 0K====&lt;br /&gt;
&lt;br /&gt;
At 0K, no thermal energy is available to overcome the energetic barriers to spin flipping. Considering the Hemholtz free energy:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; A = E - TS &amp;lt;/math&amp;gt; &lt;br /&gt;
&lt;br /&gt;
A temperature of 0K nullifies the entropic contribution to the free energy. Thus the energetic driving force (which maximises parallel spin interactions) dominates the entropic driving force (which maximises multiplicity of lattice states). For an Ising Lattice with D =  3, N = 1000 at 0K, the alignment of all spins results in the minimum energy configuration  and an overall magnetisation of &amp;lt;math&amp;gt; M = \pm 1000 &amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
= Calculating the Energy and Magnetisation =&lt;br /&gt;
==Modifying the Files==&lt;br /&gt;
&lt;br /&gt;
===Energy and Magnetisation Functions===&lt;br /&gt;
&lt;br /&gt;
====Energy===&lt;br /&gt;
[[File:First_Ene_Method.PNG]]&lt;br /&gt;
&lt;br /&gt;
The above energy method segments a given lattice into lattice cells on the edges, corners or in the bulk of the lattice and calculates the energy interactions with its neighbours as appropriate.&lt;br /&gt;
&lt;br /&gt;
====Magnetisation====&lt;br /&gt;
[[File:First_Mag_Method.PNG]]&lt;br /&gt;
&lt;br /&gt;
The magnetisation method loops over all elements in the array representing the Ising lattice and adds the value of the spin to the magnetisation variable.&lt;br /&gt;
&lt;br /&gt;
==Testing the Files==&lt;br /&gt;
&lt;br /&gt;
===ILCheck.py===&lt;br /&gt;
&lt;br /&gt;
[[File:ILChecks.PNG]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Above, the results of the ILcheck.py script are presented.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= Introduction to the Monte Carlo Simulation =&lt;br /&gt;
==Average Energy and Magnetisation==&lt;br /&gt;
===Configurations of a 100 Spin System===&lt;br /&gt;
For a system of two spins, 4 configurations are possible (↑↑, ↓↓, ↑↓, ↓↑) i.e. &amp;lt;math&amp;gt;2^{2}&amp;lt;/math&amp;gt;. For a system of 100 spins, there are &amp;lt;math&amp;gt;2^{100}&amp;lt;/math&amp;gt; configurations. In the first example, the ↑↑ and ↓↓ are degenerate, as are the ↑↓ and ↓↑ configurations. Therefore, dividing the number of possible configurations by the multiplicity of each configuration (&amp;lt;math&amp;gt;2&amp;lt;/math&amp;gt;) gives the number of non-degenerate configurations. As previously stated, degenerate configurations are indistinguishable in the absence of an external magnetic field.&lt;br /&gt;
&lt;br /&gt;
For 100 spins, this gives &amp;lt;math&amp;gt;\displaystyle\frac{2^{100}}{2} = 6.338 \times 10^{29} &amp;lt;/math&amp;gt; distinguishable configurations.&lt;br /&gt;
&lt;br /&gt;
If processing speed permits &amp;lt;math&amp;gt; 1 \times 10^{9}&amp;lt;/math&amp;gt; calculations each second, the evaluation of a single value of &amp;lt;math&amp;gt;\left\langle M\right\rangle_T&amp;lt;/math&amp;gt; would last &amp;lt;math&amp;gt; 6.338 \times 10^{20} &amp;lt;/math&amp;gt; seconds or &amp;lt;math&amp;gt; 1458 &amp;lt;/math&amp;gt; times the age of the Universe!&lt;br /&gt;
&lt;br /&gt;
==Modifying IsingLattice.py==&lt;br /&gt;
&lt;br /&gt;
===Monte Carlo and Statistics Methods===&lt;br /&gt;
[[File:Monte_Carlo.PNG]]&lt;br /&gt;
&lt;br /&gt;
[[File:stats.PNG]]&lt;br /&gt;
&lt;br /&gt;
The Metropolis Monte Carlo (MMC) algorithm provides a computationally inexpensive path from random initial states to the minimum free energy states of the Ising lattices generated. First, a random 2D Ising lattice is generated. A single random spin within this lattice is &amp;quot;flipped&amp;quot; and the resulting (internal) energy change between these states is measured. Recalling the relationship between the Hemholtz free energy, internal energy and entropy, it follows that a decrease in internal energy also lowers the free energy of the system: thus the configuration change is accepted.&lt;br /&gt;
&lt;br /&gt;
In the case that the spin &amp;quot;flip&amp;quot; does not lower the internal energy, the MMC algorithm tests this configuration change against the Boltzman factor. In the canonical (NVT) ensemble, the free energy of the system is given by:&lt;br /&gt;
&lt;br /&gt;
:&amp;lt;math&amp;gt;A = -k_{B}T\,lnZ_{NVT} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
where Z is the canonical partition function which depends upon &amp;lt;math&amp;gt; e^{-\frac{\Delta E}{k_BT}}, the Boltzman factor. By choosing a random value in the interval [0,1)from a continuous uniformm probability distribution and rejecting any value of the Boltzman factor less than this value, ###&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Spontaneous Magnetisation===&lt;br /&gt;
&lt;br /&gt;
Below the Curie Temperature, &amp;lt;math&amp;gt; T_{C} &amp;lt;/math&amp;gt;, the energetic driving force dominates the entropic driving force, resulting in a highly ordered system and an overall magnetisation. The spins of the system align in order to maximise favourable coupling interactions rather than adopting a less ordered configuration of higher multiplicity. Therefore, when &amp;lt;math&amp;gt;T &amp;lt; T_C&amp;lt;/math&amp;gt;, the most probable configurations have an overall magnetisation resulting in &amp;lt;math&amp;gt;\left\langle M\right\rangle \neq 0&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
The plots of magnetisation per spin and energy per spin obtained from ILanim.py support this prediction. Below, the plots show that upon equilibration, the system adopts the minimum energy per spin: &amp;lt;math&amp;gt;E_{min_{spin}} = \frac{-NDJ}{N} = -DJ = -2&amp;lt;/math&amp;gt; and exhibits the maximum magnitude of magnetisation per spin: &amp;lt;math&amp;gt;|M_{spin}| = 1&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:2T=1.0.png]]&lt;br /&gt;
[[File:T=1.0.png]]&lt;br /&gt;
[[File:3T=1.0.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
An unknown system error prevented the statistics() function from printing the average values.&lt;br /&gt;
&lt;br /&gt;
==Accelerating the Code==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Initial Method Speeds===&lt;br /&gt;
Taking 10 repeat measurements for the time taken to perform 2000 Monte Carlo steps resulted in&lt;br /&gt;
&lt;br /&gt;
* An average time of  &amp;lt;math&amp;gt;11.7s&amp;lt;/math&amp;gt; &lt;br /&gt;
* A standard error of &amp;lt;math&amp;gt;0.020s&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Updating Measurement===&lt;br /&gt;
&lt;br /&gt;
NOTE: ILtimetrial.py has been modified to:&lt;br /&gt;
* Perform a requested number of &#039;2000 Monte Carlo Step&#039; measurements&lt;br /&gt;
* Record these measurements in a CSV file&lt;br /&gt;
* Return the mean measuremd time and the Standard Error i.e.   &amp;lt;math&amp;gt; \frac{\sigma}{n} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:TimeTrialMethod.PNG]]&lt;br /&gt;
&lt;br /&gt;
===Updating Energy and Magnetisation Methods===&lt;br /&gt;
[[File:New_Mag_Method.PNG]]&lt;br /&gt;
[[File:New_Ene_Method.PNG]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Updated Method Speeds===&lt;br /&gt;
[[File:TimeTrial.PNG]]&lt;br /&gt;
&lt;br /&gt;
Taking 30 measurements of the time taken to perform 2000 Monte Carlo Steps resulted in:&lt;br /&gt;
&lt;br /&gt;
* An average time of &amp;lt;math&amp;gt;\displaystyle{0.87s}&amp;lt;/math&amp;gt;&lt;br /&gt;
* A standard error of &amp;lt;math&amp;gt;2.5 \times 10^{-3}s&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This represents a &#039;&#039;&#039;INSERT&#039;&#039;&#039;% decrease in computation time from the initial methods.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==The Effect of Temperature==&lt;br /&gt;
&lt;br /&gt;
===Correcting the Averaging  Code===&lt;br /&gt;
&lt;br /&gt;
To quickly find a value for &amp;lt;math&amp;gt; N_{d}&amp;lt;/math&amp;gt;, the minimum number of cycles typically needed for the equilibration of a system of within the lattice and temperature ranges of interest, it was assumed that:&lt;br /&gt;
&lt;br /&gt;
* Larger lattices would require more Monte Carlo steps to reach equilibrium from their initial, random configurations&lt;br /&gt;
&lt;br /&gt;
* Lattices at lower temperatures would require more Monte Carlo steps to reach equilibrium from their initial, random configurations.&lt;br /&gt;
&lt;br /&gt;
Therefore, an initial value for &amp;lt;math&amp;gt; N_{d}&amp;lt;/math&amp;gt; was found for a &amp;lt;math&amp;gt; 128\times128 &amp;lt;/math&amp;gt; lattice at a temperature of &amp;lt;math&amp;gt;0.5&amp;lt;/math&amp;gt; reduced temperature units.&lt;br /&gt;
*&amp;lt;math&amp;gt; N_{d} = 185000 &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
By this number of steps, all smaller lattices at all higher temperatures were found to have equilibrated also. Thus, this value of&amp;lt;math&amp;gt; N_{d}&amp;lt;/math&amp;gt; was accepted as an appropriate delay.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:AFinFrame 128 3e5 T= 0.5line.png|400px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
For the 128x128 lattices at T=0.5, equilibration was ensured from 185000 steps onwards.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Smaller lattices at the same temperature did indeed equilibrate more slowly, but all equilibrated within &amp;lt;math&amp;gt; N_{d}&amp;lt;/math&amp;gt; MC steps.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:AFinFrame 64 3e5 T= 0.5line.png|400px]]&lt;br /&gt;
[[File:AFinFrame 32 3e5 T= 0.5line2.png|400px]]&lt;br /&gt;
[[File:AFinFrame 16 3e5 T= 0.5line2.png|400px]]&lt;br /&gt;
[[File:AFinFrame 8 3e5 T= 0.5line.png|400px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The figure below shows the modifications made to IsingLattice.py to incorporate the &amp;lt;math&amp;gt; N_{d} &amp;lt;/math&amp;gt; step delay.&lt;br /&gt;
&lt;br /&gt;
===Running over a Range of Temperatures===&lt;br /&gt;
&lt;br /&gt;
To examine the effect of temperature on the average energy &amp;lt;math&amp;gt; \left\langle E\right\rangle &amp;lt;/math&amp;gt; and average magnetisation &amp;lt;math&amp;gt; \left\langle M\right\rangle &amp;lt;/math&amp;gt; of Ising lattices at equilibrium, the following parameters were used:&lt;br /&gt;
&lt;br /&gt;
* Temperature Range: &amp;lt;math&amp;gt;  0.5 - 5 &amp;lt;/math&amp;gt; reduced units&lt;br /&gt;
* Temperature Interval: &amp;lt;math&amp;gt;0.01&amp;lt;/math&amp;gt; reduced units (&amp;lt;math&amp;gt;450&amp;lt;/math&amp;gt; temperature values)&lt;br /&gt;
* Number of MMC Steps per Temperature value: &amp;lt;math&amp;gt; 2 \times 10^5 &amp;lt;/math&amp;gt; with the aforementioned value of &amp;lt;math&amp;gt; N_{d} = 1.85 \times 10^5 &amp;lt;/math&amp;gt; Monte Carlo steps&lt;br /&gt;
* Lattice Sizes:  &amp;lt;math&amp;gt; 2 \times 2 &amp;lt;/math&amp;gt;, &amp;lt;math&amp;gt; 4 \times 4 &amp;lt;/math&amp;gt; , &amp;lt;math&amp;gt; 8 \times 8 &amp;lt;/math&amp;gt; , &amp;lt;math&amp;gt; 16 \times 16 &amp;lt;/math&amp;gt; , &amp;lt;math&amp;gt; 32 \times 32 &amp;lt;/math&amp;gt; , &amp;lt;math&amp;gt; 64 \times 64 &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Plots of  &amp;lt;math&amp;gt; \left\langle E\right\rangle &amp;lt;/math&amp;gt; and  &amp;lt;math&amp;gt; \left\langle M\right\rangle &amp;lt;/math&amp;gt; per spin as versus temperature are presented below for each lattice size. Errorbars have been implemented to demonstrate how &#039;&#039;well-behaved&#039;&#039; lattice systems of each size are at each temperature, that is, how temperature and lattice size affect the size of the variations in the expected values. For the error calculations, the standard errors, &amp;lt;math&amp;gt; \sigma_\bar{X} &amp;lt;/math&amp;gt;,  in &amp;lt;math&amp;gt; \left\langle E\right\rangle &amp;lt;/math&amp;gt; and  &amp;lt;math&amp;gt; \left\langle M\right\rangle &amp;lt;/math&amp;gt; per spin have been used:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====8x8====&lt;br /&gt;
&lt;br /&gt;
[[File:8x8e+error.png]] [[File:8x8m+error.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
A Python script has been written to generate a plot of &amp;lt;math&amp;gt;\left\langle E\right\rangle&amp;lt;/math&amp;gt; or &amp;lt;math&amp;gt;\left\langle M\right\rangle&amp;lt;/math&amp;gt; against temperature based upon user input. A screenshot of this code has been inserted below.&lt;br /&gt;
&lt;br /&gt;
[[File:ExpectedvsTemp.PNG|200px]]&lt;br /&gt;
&lt;br /&gt;
===Scaling the System Size===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====2x2====&lt;br /&gt;
[[File:2x2e+error.png]] [[File:2x2m+error.png]]&lt;br /&gt;
&lt;br /&gt;
====4x4====&lt;br /&gt;
[[File:4x4e+error.png]] [[File:4x4m+error.png]]&lt;br /&gt;
&lt;br /&gt;
====16x16====&lt;br /&gt;
[[File:16x16e+error.png]] [[File:16x16m+error.png]]&lt;br /&gt;
&lt;br /&gt;
====32x32====&lt;br /&gt;
[[File:32x32e+error.png]] [[File:32x32m+error.png]]&lt;br /&gt;
&lt;br /&gt;
====64x64====&lt;br /&gt;
[[File:64x64e+error.png]] [[File:64x64m+error.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Determining the Heat Capacity==&lt;br /&gt;
&lt;br /&gt;
===Calculating the Heat Capacity===&lt;br /&gt;
Working in the canonical ensemble (constant volume), the heat capacity &amp;lt;math&amp;gt; C_V &amp;lt;/math&amp;gt; is given by:&lt;br /&gt;
&lt;br /&gt;
:&amp;lt;math&amp;gt;C_V = \frac{\partial \left\langle E\right\rangle}{\partial T}_V&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
where &amp;lt;math&amp;gt;\left\langle E\right\rangle&amp;lt;/math&amp;gt; is the average total energy or expected value of the internal energy of the system.&lt;br /&gt;
&lt;br /&gt;
: &amp;lt;math&amp;gt; \left\langle E\right\rangle = - \frac{\partial ln Q}{\partial \beta} = -\frac{1}{Q}\frac{\partial Q}{\partial \beta} &amp;lt;/math&amp;gt;&lt;br /&gt;
where &amp;lt;math&amp;gt; Q&amp;lt;/math&amp;gt; is the partition function for the system of N interacting spins.&lt;br /&gt;
&lt;br /&gt;
By evaluating the second form of the partial derivative with respect to &amp;lt;math&amp;gt; \beta&amp;lt;/math&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \left\langle E\right\rangle = -\frac{1}{Q}\frac{\partial Q}{\partial \beta} = \frac{\Sigma \epsilon_{i} e^{-\beta \epsilon_{i}}}{\Sigma e^{-\beta \epsilon_{i}}} &amp;lt;/math&amp;gt; &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Applying the product rule enables the differentiation of this expression for &amp;lt;math&amp;gt;\left\langle E\right\rangle&amp;lt;/math&amp;gt; with respect to temperature, giving:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\frac{\partial \left\langle E\right\rangle}{\partial T} = \frac{\Sigma \epsilon_{i} \frac{\epsilon_i}{k_BT^2}e^{-\beta \epsilon_{i}}}{\Sigma e^{-\beta \epsilon_{i}}} - \frac{\Sigma \epsilon_i e^{-\beta \epsilon_i}\cdot \frac{\epsilon_i}{k_BT^2}e^{-\beta \epsilon_i}}{(\Sigma e^{-\beta \epsilon_{i}})^2}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\frac{\partial \left\langle E\right\rangle}{\partial T}  = \frac{1}{k_BT^2}\left[\frac{\Sigma \epsilon_i^2 e^{-\beta \epsilon_i}}{\Sigma e^{-\beta \epsilon_i}} - \left(\frac{\Sigma \epsilon_{i} e^{-\beta \epsilon_{i}}}{\Sigma e^{-\beta \epsilon_{i}}}\right)^2\right] &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\frac{\partial \left\langle E\right\rangle}{\partial T}  = \frac{1}{k_BT^2}\left[\left\langle E^2\right\rangle - \left\langle E\right\rangle^2 \right] &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Thus,&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\frac{\partial \left\langle E\right\rangle}{\partial T} = \frac{Var[E]}{k_BT^2} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Heat Capacity versus Temperature===&lt;br /&gt;
&lt;br /&gt;
====2x2====&lt;br /&gt;
[[File:HC2.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====4x4====&lt;br /&gt;
[[File:HC4.png]]&lt;br /&gt;
&lt;br /&gt;
====8x8====&lt;br /&gt;
[[File:HC8.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====16x16====&lt;br /&gt;
[[File:HC16.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====32x32====&lt;br /&gt;
[[File:HC32.png]]&lt;br /&gt;
&lt;br /&gt;
== Locating the Curie Temperature ==&lt;br /&gt;
&lt;br /&gt;
===C++ Data Comparison===&lt;br /&gt;
&lt;br /&gt;
[[File:CHC2.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Polyfitting of C++ Data===&lt;br /&gt;
&lt;br /&gt;
====Fitting a Polynomial to the Entire Range====&lt;br /&gt;
&lt;br /&gt;
[[File:15Polyc2x2.png]]&lt;br /&gt;
Polynomials with 5 terms and above were found to match the data in the vicinity of the critical region considerably well. Below 7 terms, the &#039;&#039;tails&#039;&#039; of the plot were matched poorly. In the above example, a polynomial of 15 terms was fit to the data.&lt;br /&gt;
&lt;br /&gt;
=== Python Scripts ===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
* Frenkel, Daan, et al. Understanding Molecular Simulation : From Algorithms to Applications, Elsevier Science &amp;amp; Technology, 2001&lt;/div&gt;</summary>
		<author><name>Jj1516</name></author>
	</entry>
	<entry>
		<id>https://chemwiki.ch.ic.ac.uk/index.php?title=Rep:JJ1516Ising&amp;diff=736508</id>
		<title>Rep:JJ1516Ising</title>
		<link rel="alternate" type="text/html" href="https://chemwiki.ch.ic.ac.uk/index.php?title=Rep:JJ1516Ising&amp;diff=736508"/>
		<updated>2018-11-20T20:39:06Z</updated>

		<summary type="html">&lt;p&gt;Jj1516: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Ex Script Link:&lt;br /&gt;
https://wiki.ch.ic.ac.uk/wiki/index.php?title=Third_year_CMP_compulsory_experiment&lt;br /&gt;
&lt;br /&gt;
= Introduction to the Ising Model =&lt;br /&gt;
&lt;br /&gt;
== The Model ==&lt;br /&gt;
&lt;br /&gt;
=== Minimum Energy State ===&lt;br /&gt;
====Minimum Interaction Energy====&lt;br /&gt;
The interaction energy of an Ising lattice is given by:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;E = -\frac{1}{2}J\displaystyle\sum_{i}^{N} \displaystyle\sum_{j\;\in\;{neighbours}\;(i)} \!\!\!\!\!\!\!\!\!\!\!\!s_{i}s_{j}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In an Ising lattice with D dimensions and periodic boundary conditions, a given spin &amp;lt;math&amp;gt; s_i&amp;lt;/math&amp;gt; has 2D neighbours.&lt;br /&gt;
&lt;br /&gt;
The minimum interaction energy is achieved when all spins in the lattice are aligned (all ↑ or all ↓). As  such, any spin &amp;lt;math&amp;gt; s_i&amp;lt;/math&amp;gt; must be aligned with all 2D of its neighbours. That is, &amp;lt;math&amp;gt;s_{i}s_{j} = 1&amp;lt;/math&amp;gt; for all &amp;lt;math&amp;gt;j&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Therefore, for any &amp;lt;math&amp;gt; s_i&amp;lt;/math&amp;gt;, the sum of its interactions is &amp;lt;math&amp;gt;\displaystyle\sum_{j\;\in\;{neighbours}\;(i)} \!\!\!\!\!\!\!\!\!\!\!\!s_{i}s_{j} = 2D &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
As this is true for all N spins in the lattice, it follows that &amp;lt;math&amp;gt;\displaystyle\sum_{i}^{N} 2D = 2DN&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Thus the minimum interaction energy is given by:&lt;br /&gt;
&lt;br /&gt;
:&amp;lt;math&amp;gt;E_{min} = -\frac{1}{2}J\cdot2DN = - DNJ &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Entropy of the Minimum Energy State====&lt;br /&gt;
&lt;br /&gt;
The entropy of a state is given by:&lt;br /&gt;
&lt;br /&gt;
:&amp;lt;math&amp;gt;S = k\; ln\; \Omega &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Where &amp;lt;math&amp;gt; \Omega &amp;lt;/math&amp;gt; is the multiplicity of the state, the number of degenerate configurations of said state. The minimum energy state is achievable with all spins ↑ or with all spins ↓. In the absence of an external magnetic field, these configurations are degenerate and indistinguishable giving &amp;lt;math&amp;gt; \Omega = 2 &amp;lt;/math&amp;gt; for this state. Therefore,&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; S_{E_{min}}  = k_{B}\; ln\; 2 = 0.693k_{B} = 9.57 \times 10^{-24} J\!\cdot\!\! K^{-1}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Phase Transitions ==&lt;br /&gt;
&lt;br /&gt;
=== Changes to Minimum Energy Configuration ===&lt;br /&gt;
&lt;br /&gt;
====Energy Change ====&lt;br /&gt;
The energy change &amp;lt;math&amp;gt; \Delta E&amp;lt;/math&amp;gt; associated with a single spin &#039;flip&#039; from the lowest energy onfiguration may be calculated by considering the change in the interaction energy with the spin&#039;s neighbours.&lt;br /&gt;
&lt;br /&gt;
Let &amp;lt;math&amp;gt; D = 3, N = 1000 &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\Delta{E} = E_1 - E_0&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;E_1&amp;lt;/math&amp;gt; Interaction energy after one spin has been &#039;flipped&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;E_0&amp;lt;/math&amp;gt; Lowest energy configuration&lt;br /&gt;
&lt;br /&gt;
[[Image:Task 2 table.PNG]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\displaystyle\sum_{interactions} = -2D + 2D(2D-2) + 2D[N-(2D+1)] &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; = 2DN - 8D &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;E_1 = \displaystyle-\frac{1}{2}J\;\sum_{interactions} = 4DJ - DNJ&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\Delta{E} = E_1 - E_0 = 4DJ - DNJ + DNJ = +4DJ = +12J&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This energy change is independent of &amp;lt;math&amp;gt; N&amp;lt;/math&amp;gt; and depends only on the dimension size and the coupling constant &amp;lt;math&amp;gt; J &amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
In this calculation, the following assumption has been made.&lt;br /&gt;
&lt;br /&gt;
* The lattice dimensions are infinite relative to the size of each cell&lt;br /&gt;
&lt;br /&gt;
This allows &#039;&#039;&#039;any&#039;&#039;&#039; cell to be treated as the centre of the lattice. As every cell interacts with 2D neighbours, flipping any cell in the minimum energy configuration results in the same energy change. Alternatively, the periodic boundary conditions of the Ising model remove the necessity for such an assumption. As a consequence, the absence of &amp;lt;math&amp;gt; N &amp;lt;/math&amp;gt; from the resulting energy change is justified.&lt;br /&gt;
&lt;br /&gt;
====Entropy Change====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; S = k_{B}\; ln\; \Omega &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\Omega = \displaystyle\frac{N!}{{N_{\uparrow}!}{N_{\downarrow}!}}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Where &amp;lt;math&amp;gt;N_{x}!&amp;lt;/math&amp;gt; denotes the factorial of the number of spins in spin state &amp;lt;math&amp;gt;x&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\Delta{S} = k_{B}\;ln\;\left(\displaystyle\frac{\Omega_{2}}{\Omega_{1}}\right)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\Omega_{2} = \frac{1000!}{999!1!} = 1000&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \Omega_{1} = \frac{1000!}{1000!} = 1&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\Delta{S} = k_{B}\;ln\;1000 = 9.54 \times 10^{-23} JK^{-1}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\Delta{S_{mol}} = N_{A}k_{B}\;ln\;1000 = 57.4 \,JK^{-1}mol^{-1}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Magnetisation Values of 1D and 2D Lattices===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;M = \sum_i s_i&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====1D Lattice Magnetisation====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;M_{1D} =\;\;+1&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====2D Lattice Magnetisation====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;M_{2D} =\;\;+1&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Magnetisation at 0K====&lt;br /&gt;
&lt;br /&gt;
At 0K, no thermal energy is available to overcome the energetic barriers to spin flipping. Considering the Hemholtz free energy:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; A = E - TS &amp;lt;/math&amp;gt; &lt;br /&gt;
&lt;br /&gt;
A temperature of 0K nullifies the entropic contribution to the free energy. Thus the energetic driving force (which maximises parallel spin interactions) dominates the entropic driving force (which maximises multiplicity of lattice states). For an Ising Lattice with D =  3, N = 1000 at 0K, the alignment of all spins results in the minimum energy configuration  and an overall magnetisation of &amp;lt;math&amp;gt; M = \pm 1000 &amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
= Calculating the Energy and Magnetisation =&lt;br /&gt;
==Modifying the Files==&lt;br /&gt;
&lt;br /&gt;
===Energy and Magnetisation Functions===&lt;br /&gt;
&lt;br /&gt;
====Energy===&lt;br /&gt;
[[File:First_Ene_Method.PNG]]&lt;br /&gt;
&lt;br /&gt;
The above energy method segments a given lattice into lattice cells on the edges, corners or in the bulk of the lattice and calculates the energy interactions with its neighbours as appropriate.&lt;br /&gt;
&lt;br /&gt;
====Magnetisation====&lt;br /&gt;
[[File:First_Mag_Method.PNG]]&lt;br /&gt;
&lt;br /&gt;
The magnetisation method loops over all elements in the array representing the Ising lattice and adds the value of the spin to the magnetisation variable.&lt;br /&gt;
&lt;br /&gt;
==Testing the Files==&lt;br /&gt;
&lt;br /&gt;
===ILCheck.py===&lt;br /&gt;
&lt;br /&gt;
[[File:ILChecks.PNG]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Above, the results of the ILcheck.py script are presented.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= Introduction to the Monte Carlo Simulation =&lt;br /&gt;
==Average Energy and Magnetisation==&lt;br /&gt;
===Configurations of a 100 Spin System===&lt;br /&gt;
For a system of two spins, 4 configurations are possible (↑↑, ↓↓, ↑↓, ↓↑) i.e. &amp;lt;math&amp;gt;2^{2}&amp;lt;/math&amp;gt;. For a system of 100 spins, there are &amp;lt;math&amp;gt;2^{100}&amp;lt;/math&amp;gt; configurations. In the first example, the ↑↑ and ↓↓ are degenerate, as are the ↑↓ and ↓↑ configurations. Therefore, dividing the number of possible configurations by the multiplicity of each configuration (&amp;lt;math&amp;gt;2&amp;lt;/math&amp;gt;) gives the number of non-degenerate configurations. As previously stated, degenerate configurations are indistinguishable in the absence of an external magnetic field.&lt;br /&gt;
&lt;br /&gt;
For 100 spins, this gives &amp;lt;math&amp;gt;\displaystyle\frac{2^{100}}{2} = 6.338 \times 10^{29} &amp;lt;/math&amp;gt; distinguishable configurations.&lt;br /&gt;
&lt;br /&gt;
If processing speed permits &amp;lt;math&amp;gt; 1 \times 10^{9}&amp;lt;/math&amp;gt; calculations each second, the evaluation of a single value of &amp;lt;math&amp;gt;\left\langle M\right\rangle_T&amp;lt;/math&amp;gt; would last &amp;lt;math&amp;gt; 6.338 \times 10^{20} &amp;lt;/math&amp;gt; seconds or &amp;lt;math&amp;gt; 1458 &amp;lt;/math&amp;gt; times the age of the Universe!&lt;br /&gt;
&lt;br /&gt;
==Modifying IsingLattice.py==&lt;br /&gt;
&lt;br /&gt;
[[File:Monte_Carlo.PNG]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The Metropolis Monte Carlo (MMC) algorithm provides a computationally inexpensive path from random initial states to the minimum free energy states of the Ising lattices generated. First, a random 2D Ising lattice is generated. A single random spin within this lattice is &amp;quot;flipped&amp;quot; and the resulting (internal) energy change between these states is measured. Recalling the relationship between the Hemholtz free energy, internal energy and entropy, it follows that a decrease in internal energy also lowers the free energy of the system: thus the configuration change is accepted.&lt;br /&gt;
&lt;br /&gt;
In the case that the spin &amp;quot;flip&amp;quot; does not lower the internal energy, the MMC algorithm tests this configuration change against the Boltzman factor. In the canonical (NVT) ensemble, the free energy of the system is given by:&lt;br /&gt;
&lt;br /&gt;
:&amp;lt;math&amp;gt;A = -k_{B}T\,lnZ_{NVT} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
where Z is the canonical partition function which depends upon &amp;lt;math&amp;gt; e^{-\frac{\Delta E}{k_BT}}, the Boltzman factor. By choosing a random value in the interval [0,1)from a continuous uniformm probability distribution and rejecting any value of the Boltzman factor less than this value, ________________________&lt;br /&gt;
&lt;br /&gt;
###&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:stats.PNG]]&lt;br /&gt;
&lt;br /&gt;
===Spontaneous Magnetisation===&lt;br /&gt;
&lt;br /&gt;
Below the Curie Temperature, &amp;lt;math&amp;gt; T_{C} &amp;lt;/math&amp;gt;, energetic driving forces dominate entropic driving forces. Therefore, the spins of the system align in order to maximise favourable interactions rather than adopting a less ordered configuration, which would maximise multiplicity (and thus entropy).&lt;br /&gt;
Below &amp;lt;math&amp;gt;T &amp;lt; T_C&amp;lt;/math&amp;gt;, the most probable configurations have an overall magnetisation resulting in &amp;lt;math&amp;gt;\left\langle M\right\rangle \neq 0&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
The plots of magnetisation per spin and energy per spin obtained from ILanim.py upon system equilibration show that at minimum energy per spin &amp;lt;math&amp;gt;E_{min_{spin}} = \frac{-NDJ}{N} = -DJ = -2&amp;lt;/math&amp;gt;, the magnitude of the overall magnetisation per spin is at a maximum &amp;lt;math&amp;gt;|M_{spin}| = 1&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:2T=1.0.png]]&lt;br /&gt;
[[File:T=1.0.png]]&lt;br /&gt;
[[File:3T=1.0.png]]&lt;br /&gt;
&lt;br /&gt;
==Accelerating the Code==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Initial Method Speeds===&lt;br /&gt;
Taking 10 repeat measurements for the time taken to perform 2000 Monte Carlo steps resulted in&lt;br /&gt;
&lt;br /&gt;
* An average time of  &amp;lt;math&amp;gt;11.7s&amp;lt;/math&amp;gt; &lt;br /&gt;
* A standard error of &amp;lt;math&amp;gt;0.020s&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Updating Measurement===&lt;br /&gt;
&lt;br /&gt;
NOTE: ILtimetrial.py has been modified to:&lt;br /&gt;
* Perform a requested number of &#039;2000 Monte Carlo Step&#039; measurements&lt;br /&gt;
* Record these measurements in a CSV file&lt;br /&gt;
* Return the mean measuremd time and the Standard Error i.e.   &amp;lt;math&amp;gt; \frac{\sigma}{n} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:TimeTrialMethod.PNG]]&lt;br /&gt;
&lt;br /&gt;
===Updating Energy and Magnetisation Methods===&lt;br /&gt;
[[File:New_Mag_Method.PNG]]&lt;br /&gt;
[[File:New_Ene_Method.PNG]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Updated Method Speeds===&lt;br /&gt;
[[File:TimeTrial.PNG]]&lt;br /&gt;
&lt;br /&gt;
Taking 30 measurements of the time taken to perform 2000 Monte Carlo Steps resulted in:&lt;br /&gt;
&lt;br /&gt;
* An average time of &amp;lt;math&amp;gt;\displaystyle{0.87s}&amp;lt;/math&amp;gt;&lt;br /&gt;
* A standard error of &amp;lt;math&amp;gt;2.5 \times 10^{-3}s&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This represents a &#039;&#039;&#039;INSERT&#039;&#039;&#039;% decrease in computation time from the initial methods.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==The Effect of Temperature==&lt;br /&gt;
&lt;br /&gt;
===Correcting the Averaging  Code===&lt;br /&gt;
&lt;br /&gt;
To quickly find a value for &amp;lt;math&amp;gt; N_{d}&amp;lt;/math&amp;gt;, the minimum number of cycles typically needed for the equilibration of a system of within the lattice and temperature ranges of interest, it was assumed that:&lt;br /&gt;
&lt;br /&gt;
* Larger lattices would require more Monte Carlo steps to reach equilibrium from their initial, random configurations&lt;br /&gt;
&lt;br /&gt;
* Lattices at lower temperatures would require more Monte Carlo steps to reach equilibrium from their initial, random configurations.&lt;br /&gt;
&lt;br /&gt;
Therefore, an initial value for &amp;lt;math&amp;gt; N_{d}&amp;lt;/math&amp;gt; was found for a &amp;lt;math&amp;gt; 128\times128 &amp;lt;/math&amp;gt; lattice at a temperature of &amp;lt;math&amp;gt;0.5&amp;lt;/math&amp;gt; reduced temperature units.&lt;br /&gt;
*&amp;lt;math&amp;gt; N_{d} = 185000 &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
By this number of steps, all smaller lattices at all higher temperatures were found to have equilibrated also. Thus, this value of&amp;lt;math&amp;gt; N_{d}&amp;lt;/math&amp;gt; was accepted as an appropriate delay.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:AFinFrame 128 3e5 T= 0.5line.png|400px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
For the 128x128 lattices at T=0.5, equilibration was ensured from 185000 steps onwards.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Smaller lattices at the same temperature did indeed equilibrate more slowly, but all equilibrated within &amp;lt;math&amp;gt; N_{d}&amp;lt;/math&amp;gt; MC steps.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:AFinFrame 64 3e5 T= 0.5line.png|400px]]&lt;br /&gt;
[[File:AFinFrame 32 3e5 T= 0.5line2.png|400px]]&lt;br /&gt;
[[File:AFinFrame 16 3e5 T= 0.5line2.png|400px]]&lt;br /&gt;
[[File:AFinFrame 8 3e5 T= 0.5line.png|400px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The figure below shows the modifications made to IsingLattice.py to incorporate the &amp;lt;math&amp;gt; N_{d} &amp;lt;/math&amp;gt; step delay.&lt;br /&gt;
&lt;br /&gt;
===Running over a Range of Temperatures===&lt;br /&gt;
&lt;br /&gt;
To examine the effect of temperature on the average energy &amp;lt;math&amp;gt; \left\langle E\right\rangle &amp;lt;/math&amp;gt; and average magnetisation &amp;lt;math&amp;gt; \left\langle M\right\rangle &amp;lt;/math&amp;gt; of Ising lattices at equilibrium, the following parameters were used:&lt;br /&gt;
&lt;br /&gt;
* Temperature Range: &amp;lt;math&amp;gt;  0.5 - 5 &amp;lt;/math&amp;gt; reduced units&lt;br /&gt;
* Temperature Interval: &amp;lt;math&amp;gt;0.01&amp;lt;/math&amp;gt; reduced units (&amp;lt;math&amp;gt;450&amp;lt;/math&amp;gt; temperature values)&lt;br /&gt;
* Number of MMC Steps per Temperature value: &amp;lt;math&amp;gt; 2 \times 10^5 &amp;lt;/math&amp;gt; with the aforementioned value of &amp;lt;math&amp;gt; N_{d} = 1.85 \times 10^5 &amp;lt;/math&amp;gt; Monte Carlo steps&lt;br /&gt;
* Lattice Sizes:  &amp;lt;math&amp;gt; 2 \times 2 &amp;lt;/math&amp;gt;, &amp;lt;math&amp;gt; 4 \times 4 &amp;lt;/math&amp;gt; , &amp;lt;math&amp;gt; 8 \times 8 &amp;lt;/math&amp;gt; , &amp;lt;math&amp;gt; 16 \times 16 &amp;lt;/math&amp;gt; , &amp;lt;math&amp;gt; 32 \times 32 &amp;lt;/math&amp;gt; , &amp;lt;math&amp;gt; 64 \times 64 &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Plots of  &amp;lt;math&amp;gt; \left\langle E\right\rangle &amp;lt;/math&amp;gt; and  &amp;lt;math&amp;gt; \left\langle M\right\rangle &amp;lt;/math&amp;gt; per spin as versus temperature are presented below for each lattice size. Errorbars have been implemented to demonstrate how &#039;&#039;well-behaved&#039;&#039; lattice systems of each size are at each temperature, that is, how temperature and lattice size affect the size of the variations in the expected values. For the error calculations, the standard errors, &amp;lt;math&amp;gt; \sigma_\bar{X} &amp;lt;/math&amp;gt;,  in &amp;lt;math&amp;gt; \left\langle E\right\rangle &amp;lt;/math&amp;gt; and  &amp;lt;math&amp;gt; \left\langle M\right\rangle &amp;lt;/math&amp;gt; per spin have been used:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====8x8====&lt;br /&gt;
&lt;br /&gt;
[[File:8x8e+error.png]] [[File:8x8m+error.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
A Python script has been written to generate a plot of &amp;lt;math&amp;gt;\left\langle E\right\rangle&amp;lt;/math&amp;gt; or &amp;lt;math&amp;gt;\left\langle M\right\rangle&amp;lt;/math&amp;gt; against temperature based upon user input. A screenshot of this code has been inserted below.&lt;br /&gt;
&lt;br /&gt;
[[File:ExpectedvsTemp.PNG|200px]]&lt;br /&gt;
&lt;br /&gt;
===Scaling the System Size===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====2x2====&lt;br /&gt;
[[File:2x2e+error.png]] [[File:2x2m+error.png]]&lt;br /&gt;
&lt;br /&gt;
====4x4====&lt;br /&gt;
[[File:4x4e+error.png]] [[File:4x4m+error.png]]&lt;br /&gt;
&lt;br /&gt;
====16x16====&lt;br /&gt;
[[File:16x16e+error.png]] [[File:16x16m+error.png]]&lt;br /&gt;
&lt;br /&gt;
====32x32====&lt;br /&gt;
[[File:32x32e+error.png]] [[File:32x32m+error.png]]&lt;br /&gt;
&lt;br /&gt;
====64x64====&lt;br /&gt;
[[File:64x64e+error.png]] [[File:64x64m+error.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Determining the Heat Capacity==&lt;br /&gt;
&lt;br /&gt;
===Calculating the Heat Capacity===&lt;br /&gt;
Working in the canonical ensemble (constant volume), the heat capacity &amp;lt;math&amp;gt; C_V &amp;lt;/math&amp;gt; is given by:&lt;br /&gt;
&lt;br /&gt;
:&amp;lt;math&amp;gt;C_V = \frac{\partial \left\langle E\right\rangle}{\partial T}_V&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
where &amp;lt;math&amp;gt;\left\langle E\right\rangle&amp;lt;/math&amp;gt; is the average total energy or expected value of the internal energy of the system.&lt;br /&gt;
&lt;br /&gt;
: &amp;lt;math&amp;gt; \left\langle E\right\rangle = - \frac{\partial ln Q}{\partial \beta} = -\frac{1}{Q}\frac{\partial Q}{\partial \beta} &amp;lt;/math&amp;gt;&lt;br /&gt;
where &amp;lt;math&amp;gt; Q&amp;lt;/math&amp;gt; is the partition function for the system of N interacting spins.&lt;br /&gt;
&lt;br /&gt;
By evaluating the second form of the partial derivative with respect to &amp;lt;math&amp;gt; \beta&amp;lt;/math&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \left\langle E\right\rangle = -\frac{1}{Q}\frac{\partial Q}{\partial \beta} = \frac{\Sigma \epsilon_{i} e^{-\beta \epsilon_{i}}}{\Sigma e^{-\beta \epsilon_{i}}} &amp;lt;/math&amp;gt; &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Applying the product rule enables the differentiation of this expression for &amp;lt;math&amp;gt;\left\langle E\right\rangle&amp;lt;/math&amp;gt; with respect to temperature, giving:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\frac{\partial \left\langle E\right\rangle}{\partial T} = \frac{\Sigma \epsilon_{i} \frac{\epsilon_i}{k_BT^2}e^{-\beta \epsilon_{i}}}{\Sigma e^{-\beta \epsilon_{i}}} - \frac{\Sigma \epsilon_i e^{-\beta \epsilon_i}\cdot \frac{\epsilon_i}{k_BT^2}e^{-\beta \epsilon_i}}{(\Sigma e^{-\beta \epsilon_{i}})^2}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\frac{\partial \left\langle E\right\rangle}{\partial T}  = \frac{1}{k_BT^2}\left[\frac{\Sigma \epsilon_i^2 e^{-\beta \epsilon_i}}{\Sigma e^{-\beta \epsilon_i}} - \left(\frac{\Sigma \epsilon_{i} e^{-\beta \epsilon_{i}}}{\Sigma e^{-\beta \epsilon_{i}}}\right)^2\right] &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\frac{\partial \left\langle E\right\rangle}{\partial T}  = \frac{1}{k_BT^2}\left[\left\langle E^2\right\rangle - \left\langle E\right\rangle^2 \right] &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Thus,&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\frac{\partial \left\langle E\right\rangle}{\partial T} = \frac{Var[E]}{k_BT^2} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Heat Capacity versus Temperature===&lt;br /&gt;
&lt;br /&gt;
====2x2====&lt;br /&gt;
[[File:HC2.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====4x4====&lt;br /&gt;
[[File:HC4.png]]&lt;br /&gt;
&lt;br /&gt;
====8x8====&lt;br /&gt;
[[File:HC8.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====16x16====&lt;br /&gt;
[[File:HC16.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====32x32====&lt;br /&gt;
[[File:HC32.png]]&lt;br /&gt;
&lt;br /&gt;
== Locating the Curie Temperature ==&lt;br /&gt;
&lt;br /&gt;
===C++ Data Comparison===&lt;br /&gt;
&lt;br /&gt;
[[File:CHC2.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Polyfitting of C++ Data===&lt;br /&gt;
&lt;br /&gt;
====Fitting a Polynomial to the Entire Range====&lt;br /&gt;
&lt;br /&gt;
[[File:15Polyc2x2.png]]&lt;br /&gt;
Polynomials with 5 terms and above were found to match the data in the vicinity of the critical region considerably well. Below 7 terms, the &#039;&#039;tails&#039;&#039; of the plot were matched poorly. In the above example, a polynomial of 15 terms was fit to the data.&lt;br /&gt;
&lt;br /&gt;
=== Python Scripts ===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
* Frenkel, Daan, et al. Understanding Molecular Simulation : From Algorithms to Applications, Elsevier Science &amp;amp; Technology, 2001&lt;/div&gt;</summary>
		<author><name>Jj1516</name></author>
	</entry>
	<entry>
		<id>https://chemwiki.ch.ic.ac.uk/index.php?title=Rep:JJ1516Ising&amp;diff=736507</id>
		<title>Rep:JJ1516Ising</title>
		<link rel="alternate" type="text/html" href="https://chemwiki.ch.ic.ac.uk/index.php?title=Rep:JJ1516Ising&amp;diff=736507"/>
		<updated>2018-11-20T20:36:01Z</updated>

		<summary type="html">&lt;p&gt;Jj1516: /* Introduction to the Monte Carlo Simulation */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Ex Script Link:&lt;br /&gt;
https://wiki.ch.ic.ac.uk/wiki/index.php?title=Third_year_CMP_compulsory_experiment&lt;br /&gt;
&lt;br /&gt;
= Introduction to the Ising Model =&lt;br /&gt;
&lt;br /&gt;
== The Model ==&lt;br /&gt;
&lt;br /&gt;
=== Minimum Energy State ===&lt;br /&gt;
====Minimum Interaction Energy====&lt;br /&gt;
The interaction energy of an Ising lattice is given by:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;E = -\frac{1}{2}J\displaystyle\sum_{i}^{N} \displaystyle\sum_{j\;\in\;{neighbours}\;(i)} \!\!\!\!\!\!\!\!\!\!\!\!s_{i}s_{j}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In an Ising lattice with D dimensions and periodic boundary conditions, a given spin &amp;lt;math&amp;gt; s_i&amp;lt;/math&amp;gt; has 2D neighbours.&lt;br /&gt;
&lt;br /&gt;
The minimum interaction energy is achieved when all spins in the lattice are aligned (all ↑ or all ↓). As  such, any spin &amp;lt;math&amp;gt; s_i&amp;lt;/math&amp;gt; must be aligned with all 2D of its neighbours. That is, &amp;lt;math&amp;gt;s_{i}s_{j} = 1&amp;lt;/math&amp;gt; for all &amp;lt;math&amp;gt;j&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Therefore, for any &amp;lt;math&amp;gt; s_i&amp;lt;/math&amp;gt;, the sum of its interactions is &amp;lt;math&amp;gt;\displaystyle\sum_{j\;\in\;{neighbours}\;(i)} \!\!\!\!\!\!\!\!\!\!\!\!s_{i}s_{j} = 2D &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
As this is true for all N spins in the lattice, it follows that &amp;lt;math&amp;gt;\displaystyle\sum_{i}^{N} 2D = 2DN&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Thus the minimum interaction energy is given by:&lt;br /&gt;
&lt;br /&gt;
:&amp;lt;math&amp;gt;E_{min} = -\frac{1}{2}J\cdot2DN = - DNJ &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Entropy of the Minimum Energy State====&lt;br /&gt;
&lt;br /&gt;
The entropy of a state is given by:&lt;br /&gt;
&lt;br /&gt;
:&amp;lt;math&amp;gt;S = k\; ln\; \Omega &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Where &amp;lt;math&amp;gt; \Omega &amp;lt;/math&amp;gt; is the multiplicity of the state, the number of degenerate configurations of said state. The minimum energy state is achievable with all spins ↑ or with all spins ↓. In the absence of an external magnetic field, these configurations are degenerate and indistinguishable giving &amp;lt;math&amp;gt; \Omega = 2 &amp;lt;/math&amp;gt; for this state. Therefore,&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; S_{E_{min}}  = k_{B}\; ln\; 2 = 0.693k_{B} = 9.57 \times 10^{-24} J\!\cdot\!\! K^{-1}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Phase Transitions ==&lt;br /&gt;
&lt;br /&gt;
=== Changes to Minimum Energy Configuration ===&lt;br /&gt;
&lt;br /&gt;
====Energy Change ====&lt;br /&gt;
The energy change &amp;lt;math&amp;gt; \Delta E&amp;lt;/math&amp;gt; associated with a single spin &#039;flip&#039; from the lowest energy onfiguration may be calculated by considering the change in the interaction energy with the spin&#039;s neighbours.&lt;br /&gt;
&lt;br /&gt;
Let &amp;lt;math&amp;gt; D = 3, N = 1000 &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\Delta{E} = E_1 - E_0&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;E_1&amp;lt;/math&amp;gt; Interaction energy after one spin has been &#039;flipped&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;E_0&amp;lt;/math&amp;gt; Lowest energy configuration&lt;br /&gt;
&lt;br /&gt;
[[Image:Task 2 table.PNG]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\displaystyle\sum_{interactions} = -2D + 2D(2D-2) + 2D[N-(2D+1)] &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; = 2DN - 8D &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;E_1 = \displaystyle-\frac{1}{2}J\;\sum_{interactions} = 4DJ - DNJ&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\Delta{E} = E_1 - E_0 = 4DJ - DNJ + DNJ = +4DJ = +12J&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This energy change is independent of &amp;lt;math&amp;gt; N&amp;lt;/math&amp;gt; and depends only on the dimension size and the coupling constant &amp;lt;math&amp;gt; J &amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
In this calculation, the following assumption has been made.&lt;br /&gt;
&lt;br /&gt;
* The lattice dimensions are infinite relative to the size of each cell&lt;br /&gt;
&lt;br /&gt;
This allows &#039;&#039;&#039;any&#039;&#039;&#039; cell to be treated as the centre of the lattice. As every cell interacts with 2D neighbours, flipping any cell in the minimum energy configuration results in the same energy change. Alternatively, the periodic boundary conditions of the Ising model remove the necessity for such an assumption. As a consequence, the absence of &amp;lt;math&amp;gt; N &amp;lt;/math&amp;gt; from the resulting energy change is justified.&lt;br /&gt;
&lt;br /&gt;
====Entropy Change====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; S = k_{B}\; ln\; \Omega &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\Omega = \displaystyle\frac{N!}{{N_{\uparrow}!}{N_{\downarrow}!}}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Where &amp;lt;math&amp;gt;N_{x}!&amp;lt;/math&amp;gt; denotes the factorial of the number of spins in spin state &amp;lt;math&amp;gt;x&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\Delta{S} = k_{B}\;ln\;\left(\displaystyle\frac{\Omega_{2}}{\Omega_{1}}\right)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\Omega_{2} = \frac{1000!}{999!1!} = 1000&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \Omega_{1} = \frac{1000!}{1000!} = 1&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\Delta{S} = k_{B}\;ln\;1000 = 9.54 \times 10^{-23} JK^{-1}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\Delta{S_{mol}} = N_{A}k_{B}\;ln\;1000 = 57.4 \,JK^{-1}mol^{-1}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Magnetisation Values of 1D and 2D Lattices===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;M = \sum_i s_i&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====1D Lattice Magnetisation====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;M_{1D} =\;\;+1&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====2D Lattice Magnetisation====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;M_{2D} =\;\;+1&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Magnetisation at 0K====&lt;br /&gt;
&lt;br /&gt;
At 0K, no thermal energy is available to overcome the energetic barriers to spin flipping. Considering the Hemholtz free energy:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; A = E - TS &amp;lt;/math&amp;gt; &lt;br /&gt;
&lt;br /&gt;
A temperature of 0K nullifies the entropic contribution to the free energy. Thus the energetic driving force (which maximises parallel spin interactions) dominates the entropic driving force (which maximises multiplicity of lattice states). For an Ising Lattice with D =  3, N = 1000 at 0K, the alignment of all spins results in the minimum energy configuration  and an overall magnetisation of &amp;lt;math&amp;gt; M = \pm 1000 &amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
= Calculating the Energy and Magnetisation =&lt;br /&gt;
==Modifying the Files==&lt;br /&gt;
&lt;br /&gt;
===Energy and Magnetisation Functions===&lt;br /&gt;
&lt;br /&gt;
====Energy===&lt;br /&gt;
[[File:First_Ene_Method.PNG]]&lt;br /&gt;
&lt;br /&gt;
The above energy method segments a given lattice into lattice cells on the edges, corners or in the bulk of the lattice and calculates the energy interactions with its neighbours as appropriate.&lt;br /&gt;
&lt;br /&gt;
====Magnetisation====&lt;br /&gt;
[[File:First_Mag_Method.PNG]]&lt;br /&gt;
&lt;br /&gt;
The magnetisation method loops over all elements in the array representing the Ising lattice and adds the value of the spin to the magnetisation variable.&lt;br /&gt;
&lt;br /&gt;
==Testing the Files==&lt;br /&gt;
&lt;br /&gt;
===ILCheck.py===&lt;br /&gt;
&lt;br /&gt;
[[File:ILChecks.PNG]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Above, the results of the ILcheck.py script are presented.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= Introduction to the Monte Carlo Simulation =&lt;br /&gt;
==Average Energy and Magnetisation==&lt;br /&gt;
===Configurations of a 100 Spin System===&lt;br /&gt;
For a system of two spins, 4 configurations are possible (↑↑, ↓↓, ↑↓, ↓↑) i.e. &amp;lt;math&amp;gt;2^{2}&amp;lt;/math&amp;gt;. For a system of 100 spins, there are &amp;lt;math&amp;gt;2^{100}&amp;lt;/math&amp;gt; configurations. In the first example, the ↑↑ and ↓↓ are degenerate, as are the ↑↓ and ↓↑ configurations. Therefore, dividing the number of possible configurations by the multiplicity of each configuration (&amp;lt;math&amp;gt;2&amp;lt;/math&amp;gt;) gives the number of non-degenerate configurations. As previously stated, degenerate configurations are indistinguishable in the absence of an external magnetic field.&lt;br /&gt;
&lt;br /&gt;
For 100 spins, this gives &amp;lt;math&amp;gt;\displaystyle\frac{2^{100}}{2} = 6.338 \times 10^{29} &amp;lt;/math&amp;gt; distinguishable configurations.&lt;br /&gt;
&lt;br /&gt;
If processing speed permits &amp;lt;math&amp;gt; 1 \times 10^{9}&amp;lt;/math&amp;gt; calculations each second, the evaluation of a single value of &amp;lt;math&amp;gt;\left\langle M\right\rangle_T&amp;lt;/math&amp;gt; would last &amp;lt;math&amp;gt; 6.338 \times 10^{20} &amp;lt;/math&amp;gt; seconds or &amp;lt;math&amp;gt; 1458 &amp;lt;/math&amp;gt; times the age of the Universe!&lt;br /&gt;
&lt;br /&gt;
==Modifying IsingLattice.py==&lt;br /&gt;
&lt;br /&gt;
[[File:Monte_Carlo.PNG]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The Metropolis Monte Carlo (MMC) algorithm provides a computationally inexpensive path from random initial states to the minimum free energy states of the Ising lattices generated. First, a random 2D Ising lattice is generated. A single random spin within this lattice is &amp;quot;flipped&amp;quot; and the resulting (internal) energy change between these states is measured. Recalling the relationship between the Hemholtz free energy, internal energy and entropy, it follows that a decrease in internal energy also lowers the free energy of the system: thus the configuration change is accepted.&lt;br /&gt;
&lt;br /&gt;
In the case that the spin &amp;quot;flip&amp;quot; does not lower the internal energy, the MMC algorithm tests this configuration change against the Boltzman factor. In the canonical (NVT) ensemble, the free energy of the system is given by:&lt;br /&gt;
&lt;br /&gt;
:&amp;lt;math&amp;gt;A = -k_{B}T\,lnZ_{NVT} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
where Z is the canonical partition function which depends upon &amp;lt;math&amp;gt; e^{-\frac{\Delta E}{k_BT}}, the Boltzman factor. By choosing a random value in the interval [0,1)from a continuous uniformm probability distribution and rejecting any value of the Boltzman factor less than this value, ________________________&lt;br /&gt;
&lt;br /&gt;
###&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:stats.PNG]]&lt;br /&gt;
&lt;br /&gt;
===Spontaneous Magnetisation===&lt;br /&gt;
&lt;br /&gt;
Below the Curie Temperature, &amp;lt;math&amp;gt; T_{C} &amp;lt;/math&amp;gt;, energetic driving forces dominate entropic driving forces. Therefore, the spins of the system align in order to maximise favourable interactions rather than adopting a less ordered configuration, which would maximise multiplicity (and thus entropy).&lt;br /&gt;
Below &amp;lt;math&amp;gt;T &amp;lt; T_C&amp;lt;/math&amp;gt;, the most probable configurations have an overall magnetisation resulting in &amp;lt;math&amp;gt;\left\langle M\right\rangle \neq 0&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
The plots of magnetisation per spin and energy per spin obtained from ILanim.py upon system equilibration show that at minimum energy per spin &amp;lt;math&amp;gt;E_{min_{spin}} = \frac{-NDJ}{N} = -DJ = -2&amp;lt;/math&amp;gt;, the magnitude of the overall magnetisation per spin is at a maximum &amp;lt;math&amp;gt;|M_{spin}| = 1&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:2T=1.0.png]]&lt;br /&gt;
[[File:T=1.0.png]]&lt;br /&gt;
[[File:3T=1.0.png]]&lt;br /&gt;
&lt;br /&gt;
==Accelerating the Code==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Initial Method Speeds===&lt;br /&gt;
Taking 10 repeat measurements for the time taken to perform 2000 Monte Carlo steps resulted in&lt;br /&gt;
&lt;br /&gt;
* An average time of  &amp;lt;math&amp;gt;11.7s&amp;lt;/math&amp;gt; &lt;br /&gt;
* A standard error of &amp;lt;math&amp;gt;0.020s&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Updating Measurement===&lt;br /&gt;
&lt;br /&gt;
NOTE: ILtimetrial.py has been modified to:&lt;br /&gt;
* Perform a requested number of &#039;2000 Monte Carlo Step&#039; measurements&lt;br /&gt;
* Record these measurements in a CSV file&lt;br /&gt;
* Return the mean measuremd time and the Standard Error i.e.   &amp;lt;math&amp;gt; \frac{\sigma}{n} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:TimeTrialMethod.PNG]]&lt;br /&gt;
&lt;br /&gt;
===Updating Energy and Magnetisation Methods===&lt;br /&gt;
[[File:New_Mag_Method.PNG]]&lt;br /&gt;
[[File:New_Ene_Method.PNG]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Updated Method Speeds===&lt;br /&gt;
[[File:TimeTrial.PNG]]&lt;br /&gt;
&lt;br /&gt;
Taking 30 measurements of the time taken to perform 2000 Monte Carlo Steps resulted in:&lt;br /&gt;
&lt;br /&gt;
* An average time of &amp;lt;math&amp;gt;\displaystyle{0.87s}&amp;lt;/math&amp;gt;&lt;br /&gt;
* A standard error of &amp;lt;math&amp;gt;2.5 \times 10^{-3}s&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This represents a &#039;&#039;&#039;INSERT&#039;&#039;&#039;% decrease in computation time from the initial methods.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==The Effect of Temperature==&lt;br /&gt;
&lt;br /&gt;
===Correcting the Averaging  Code===&lt;br /&gt;
&lt;br /&gt;
To quickly find a value for &amp;lt;math&amp;gt; N_{d}&amp;lt;/math&amp;gt;, the minimum number of cycles typically needed for the equilibration of a system of within the lattice and temperature ranges of interest, it was assumed that:&lt;br /&gt;
&lt;br /&gt;
* Larger lattices would require more Monte Carlo steps to reach equilibrium from their initial, random configurations&lt;br /&gt;
&lt;br /&gt;
* Lattices at lower temperatures would require more Monte Carlo steps to reach equilibrium from their initial, random configurations.&lt;br /&gt;
&lt;br /&gt;
Therefore, an initial value for &amp;lt;math&amp;gt; N_{d}&amp;lt;/math&amp;gt; was found for a &amp;lt;math&amp;gt; 128\times128 &amp;lt;/math&amp;gt; lattice at a temperature of &amp;lt;math&amp;gt;0.5&amp;lt;/math&amp;gt; reduced temperature units.&lt;br /&gt;
*&amp;lt;math&amp;gt; N_{d} = 185000 &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
By this number of steps, all smaller lattices at all higher temperatures were found to have equilibrated also. Thus, this value of&amp;lt;math&amp;gt; N_{d}&amp;lt;/math&amp;gt; was accepted as an appropriate delay.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:AFinFrame 128 3e5 T= 0.5line.png|400px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
For the 128x128 lattices at T=0.5, equilibration was ensured from 185000 steps onwards.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Smaller lattices at the same temperature did indeed equilibrate more slowly, but all equilibrated within &amp;lt;math&amp;gt; N_{d}&amp;lt;/math&amp;gt; MC steps.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:AFinFrame 64 3e5 T= 0.5line.png|400px]]&lt;br /&gt;
[[File:AFinFrame 32 3e5 T= 0.5line2.png|400px]]&lt;br /&gt;
[[File:AFinFrame 16 3e5 T= 0.5line2.png|400px]]&lt;br /&gt;
[[File:AFinFrame 8 3e5 T= 0.5line.png|400px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The figure below shows the modifications made to IsingLattice.py to incorporate the &amp;lt;math&amp;gt; N_{d} &amp;lt;/math&amp;gt; step delay.&lt;br /&gt;
&lt;br /&gt;
===Running over a Range of Temperatures===&lt;br /&gt;
&lt;br /&gt;
To examine the effect of temperature on the average energy &amp;lt;math&amp;gt; \left\langle E\right\rangle &amp;lt;/math&amp;gt; and average magnetisation &amp;lt;math&amp;gt; \left\langle M\right\rangle &amp;lt;/math&amp;gt; of Ising lattices at equilibrium, the following parameters were used:&lt;br /&gt;
&lt;br /&gt;
* Temperature Range: &amp;lt;math&amp;gt;  0.5 - 5 &amp;lt;/math&amp;gt; reduced units&lt;br /&gt;
* Temperature Interval: &amp;lt;math&amp;gt;0.01&amp;lt;/math&amp;gt; reduced units (&amp;lt;math&amp;gt;450&amp;lt;/math&amp;gt; temperature values)&lt;br /&gt;
* Number of MMC Steps per Temperature value: &amp;lt;math&amp;gt; 2 \times 10^5 &amp;lt;/math&amp;gt; with the aforementioned value of &amp;lt;math&amp;gt; N_{d} = 1.85 \times 10^5 &amp;lt;/math&amp;gt; Monte Carlo steps&lt;br /&gt;
* Lattice Sizes:  &amp;lt;math&amp;gt; 2 \times 2 &amp;lt;/math&amp;gt;, &amp;lt;math&amp;gt; 4 \times 4 &amp;lt;/math&amp;gt; , &amp;lt;math&amp;gt; 8 \times 8 &amp;lt;/math&amp;gt; , &amp;lt;math&amp;gt; 16 \times 16 &amp;lt;/math&amp;gt; , &amp;lt;math&amp;gt; 32 \times 32 &amp;lt;/math&amp;gt; , &amp;lt;math&amp;gt; 64 \times 64 &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Plots of  &amp;lt;math&amp;gt; \left\langle E\right\rangle &amp;lt;/math&amp;gt; and  &amp;lt;math&amp;gt; \left\langle M\right\rangle &amp;lt;/math&amp;gt; per spin as versus temperature are presented below for each lattice size. Errorbars have been implemented to demonstrate how &#039;&#039;well-behaved&#039;&#039; lattice systems of each size are at each temperature, that is, how temperature and lattice size affect the size of the variations in the expected values. For the error calculations, the standard errors, &amp;lt;math&amp;gt; \sigma_\bar{X} &amp;lt;/math&amp;gt;,  in &amp;lt;math&amp;gt; \left\langle E\right\rangle &amp;lt;/math&amp;gt; and  &amp;lt;math&amp;gt; \left\langle M\right\rangle &amp;lt;/math&amp;gt; per spin have been used:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====8x8====&lt;br /&gt;
&lt;br /&gt;
[[File:8x8e+error.png]] [[File:8x8m+error.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
A Python script has been written to generate a plot of &amp;lt;math&amp;gt;\left\langle E\right\rangle&amp;lt;/math&amp;gt; or &amp;lt;math&amp;gt;\left\langle M\right\rangle&amp;lt;/math&amp;gt; against temperature based upon user input. A screenshot of this code has been inserted below.&lt;br /&gt;
&lt;br /&gt;
[[File:ExpectedvsTemp.PNG|200px]]&lt;br /&gt;
&lt;br /&gt;
===Scaling the System Size===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====2x2====&lt;br /&gt;
[[File:2x2e+error.png]] [[File:2x2m+error.png]]&lt;br /&gt;
&lt;br /&gt;
====4x4====&lt;br /&gt;
[[File:4x4e+error.png]] [[File:4x4m+error.png]]&lt;br /&gt;
&lt;br /&gt;
====16x16====&lt;br /&gt;
[[File:16x16e+error.png]] [[File:16x16m+error.png]]&lt;br /&gt;
&lt;br /&gt;
====32x32====&lt;br /&gt;
[[File:32x32e+error.png]] [[File:32x32m+error.png]]&lt;br /&gt;
&lt;br /&gt;
====64x64====&lt;br /&gt;
[[File:64x64e+error.png]] [[File:64x64m+error.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Determining the Heat Capacity==&lt;br /&gt;
&lt;br /&gt;
===Calculating the Heat Capacity===&lt;br /&gt;
Working in the canonical ensemble (constant volume), the heat capacity &amp;lt;math&amp;gt; C_V &amp;lt;/math&amp;gt; is given by:&lt;br /&gt;
&lt;br /&gt;
:&amp;lt;math&amp;gt;C_V = \frac{\partial \left\langle E\right\rangle}{\partial T}_V&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
where &amp;lt;math&amp;gt;\left\langle E\right\rangle&amp;lt;/math&amp;gt; is the average total energy or expected value of the internal energy of the system.&lt;br /&gt;
&lt;br /&gt;
: &amp;lt;math&amp;gt; \left\langle E\right\rangle = - \frac{\partial ln Q}{\partial \beta} = -\frac{1}{Q}\frac{\partial Q}{\partial \beta} &amp;lt;/math&amp;gt;&lt;br /&gt;
where &amp;lt;math&amp;gt; Q&amp;lt;/math&amp;gt; is the partition function for the system of N interacting spins.&lt;br /&gt;
&lt;br /&gt;
By evaluating the second form of the partial derivative with respect to &amp;lt;math&amp;gt; \beta&amp;lt;/math&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \left\langle E\right\rangle = -\frac{1}{Q}\frac{\partial Q}{\partial \beta} = \frac{\Sigma \epsilon_{i} e^{-\beta \epsilon_{i}}}{\Sigma e^{-\beta \epsilon_{i}}} &amp;lt;/math&amp;gt; &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Applying the product rule enables the differentiation of this expression for &amp;lt;math&amp;gt;\left\langle E\right\rangle&amp;lt;/math&amp;gt; with respect to temperature, giving:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\frac{\partial \left\langle E\right\rangle}{\partial T} = \frac{\Sigma \epsilon_{i} \frac{\epsilon_i}{k_BT^2}e^{-\beta \epsilon_{i}}}{\Sigma e^{-\beta \epsilon_{i}}} - \frac{\Sigma \epsilon_i e^{-\beta \epsilon_i}\cdot \frac{\epsilon_i}{k_BT^2}e^{-\beta \epsilon_i}}{(\Sigma e^{-\beta \epsilon_{i}})^2}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\frac{\partial \left\langle E\right\rangle}{\partial T}  = \frac{1}{k_BT^2}\left[\frac{\Sigma \epsilon_i^2 e^{-\beta \epsilon_i}}{\Sigma e^{-\beta \epsilon_i}} - \left(\frac{\Sigma \epsilon_{i} e^{-\beta \epsilon_{i}}}{\Sigma e^{-\beta \epsilon_{i}}}\right)^2\right] &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\frac{\partial \left\langle E\right\rangle}{\partial T}  = \frac{1}{k_BT^2}\left[\left\langle E^2\right\rangle - \left\langle E\right\rangle^2 \right] &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Thus,&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\frac{\partial \left\langle E\right\rangle}{\partial T} = \frac{Var[E]}{k_BT^2} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Heat Capacity versus Temperature===&lt;br /&gt;
&lt;br /&gt;
====2x2====&lt;br /&gt;
[[File:HC2.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====4x4====&lt;br /&gt;
[[File:HC4.png]]&lt;br /&gt;
&lt;br /&gt;
====8x8====&lt;br /&gt;
[[File:HC8.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====16x16====&lt;br /&gt;
[[File:HC16.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====32x32====&lt;br /&gt;
[[File:HC32.png]]&lt;br /&gt;
&lt;br /&gt;
== Locating the Curie Temperature ==&lt;br /&gt;
&lt;br /&gt;
===C++ Data Comparison===&lt;br /&gt;
&lt;br /&gt;
[[File:CHC2.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Polyfitting of C++ Data===&lt;br /&gt;
&lt;br /&gt;
====Fitting a Polynomial to the Entire Range====&lt;br /&gt;
&lt;br /&gt;
[[File:15Polyc2x2.png]]&lt;br /&gt;
Polynomials with 5 terms and above were found to match the data in the vicinity of the critical region considerably well. Below 7 terms, the &#039;&#039;tails&#039;&#039; of the plot were matched poorly. In the above example, a polynomial of 15 terms was fit to the data.&lt;br /&gt;
&lt;br /&gt;
=== Python Scripts ===&lt;/div&gt;</summary>
		<author><name>Jj1516</name></author>
	</entry>
	<entry>
		<id>https://chemwiki.ch.ic.ac.uk/index.php?title=Rep:JJ1516Ising&amp;diff=736472</id>
		<title>Rep:JJ1516Ising</title>
		<link rel="alternate" type="text/html" href="https://chemwiki.ch.ic.ac.uk/index.php?title=Rep:JJ1516Ising&amp;diff=736472"/>
		<updated>2018-11-20T19:42:27Z</updated>

		<summary type="html">&lt;p&gt;Jj1516: /* Magnetisation */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Ex Script Link:&lt;br /&gt;
https://wiki.ch.ic.ac.uk/wiki/index.php?title=Third_year_CMP_compulsory_experiment&lt;br /&gt;
&lt;br /&gt;
= Introduction to the Ising Model =&lt;br /&gt;
&lt;br /&gt;
== The Model ==&lt;br /&gt;
&lt;br /&gt;
=== Minimum Energy State ===&lt;br /&gt;
====Minimum Interaction Energy====&lt;br /&gt;
The interaction energy of an Ising lattice is given by:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;E = -\frac{1}{2}J\displaystyle\sum_{i}^{N} \displaystyle\sum_{j\;\in\;{neighbours}\;(i)} \!\!\!\!\!\!\!\!\!\!\!\!s_{i}s_{j}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In an Ising lattice with D dimensions and periodic boundary conditions, a given spin &amp;lt;math&amp;gt; s_i&amp;lt;/math&amp;gt; has 2D neighbours.&lt;br /&gt;
&lt;br /&gt;
The minimum interaction energy is achieved when all spins in the lattice are aligned (all ↑ or all ↓). As  such, any spin &amp;lt;math&amp;gt; s_i&amp;lt;/math&amp;gt; must be aligned with all 2D of its neighbours. That is, &amp;lt;math&amp;gt;s_{i}s_{j} = 1&amp;lt;/math&amp;gt; for all &amp;lt;math&amp;gt;j&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Therefore, for any &amp;lt;math&amp;gt; s_i&amp;lt;/math&amp;gt;, the sum of its interactions is &amp;lt;math&amp;gt;\displaystyle\sum_{j\;\in\;{neighbours}\;(i)} \!\!\!\!\!\!\!\!\!\!\!\!s_{i}s_{j} = 2D &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
As this is true for all N spins in the lattice, it follows that &amp;lt;math&amp;gt;\displaystyle\sum_{i}^{N} 2D = 2DN&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Thus the minimum interaction energy is given by:&lt;br /&gt;
&lt;br /&gt;
:&amp;lt;math&amp;gt;E_{min} = -\frac{1}{2}J\cdot2DN = - DNJ &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Entropy of the Minimum Energy State====&lt;br /&gt;
&lt;br /&gt;
The entropy of a state is given by:&lt;br /&gt;
&lt;br /&gt;
:&amp;lt;math&amp;gt;S = k\; ln\; \Omega &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Where &amp;lt;math&amp;gt; \Omega &amp;lt;/math&amp;gt; is the multiplicity of the state, the number of degenerate configurations of said state. The minimum energy state is achievable with all spins ↑ or with all spins ↓. In the absence of an external magnetic field, these configurations are degenerate and indistinguishable giving &amp;lt;math&amp;gt; \Omega = 2 &amp;lt;/math&amp;gt; for this state. Therefore,&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; S_{E_{min}}  = k_{B}\; ln\; 2 = 0.693k_{B} = 9.57 \times 10^{-24} J\!\cdot\!\! K^{-1}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Phase Transitions ==&lt;br /&gt;
&lt;br /&gt;
=== Changes to Minimum Energy Configuration ===&lt;br /&gt;
&lt;br /&gt;
====Energy Change ====&lt;br /&gt;
The energy change &amp;lt;math&amp;gt; \Delta E&amp;lt;/math&amp;gt; associated with a single spin &#039;flip&#039; from the lowest energy onfiguration may be calculated by considering the change in the interaction energy with the spin&#039;s neighbours.&lt;br /&gt;
&lt;br /&gt;
Let &amp;lt;math&amp;gt; D = 3, N = 1000 &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\Delta{E} = E_1 - E_0&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;E_1&amp;lt;/math&amp;gt; Interaction energy after one spin has been &#039;flipped&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;E_0&amp;lt;/math&amp;gt; Lowest energy configuration&lt;br /&gt;
&lt;br /&gt;
[[Image:Task 2 table.PNG]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\displaystyle\sum_{interactions} = -2D + 2D(2D-2) + 2D[N-(2D+1)] &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; = 2DN - 8D &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;E_1 = \displaystyle-\frac{1}{2}J\;\sum_{interactions} = 4DJ - DNJ&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\Delta{E} = E_1 - E_0 = 4DJ - DNJ + DNJ = +4DJ = +12J&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This energy change is independent of &amp;lt;math&amp;gt; N&amp;lt;/math&amp;gt; and depends only on the dimension size and the coupling constant &amp;lt;math&amp;gt; J &amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
In this calculation, the following assumption has been made.&lt;br /&gt;
&lt;br /&gt;
* The lattice dimensions are infinite relative to the size of each cell&lt;br /&gt;
&lt;br /&gt;
This allows &#039;&#039;&#039;any&#039;&#039;&#039; cell to be treated as the centre of the lattice. As every cell interacts with 2D neighbours, flipping any cell in the minimum energy configuration results in the same energy change. Alternatively, the periodic boundary conditions of the Ising model remove the necessity for such an assumption. As a consequence, the absence of &amp;lt;math&amp;gt; N &amp;lt;/math&amp;gt; from the resulting energy change is justified.&lt;br /&gt;
&lt;br /&gt;
====Entropy Change====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; S = k_{B}\; ln\; \Omega &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\Omega = \displaystyle\frac{N!}{{N_{\uparrow}!}{N_{\downarrow}!}}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Where &amp;lt;math&amp;gt;N_{x}!&amp;lt;/math&amp;gt; denotes the factorial of the number of spins in spin state &amp;lt;math&amp;gt;x&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\Delta{S} = k_{B}\;ln\;\left(\displaystyle\frac{\Omega_{2}}{\Omega_{1}}\right)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\Omega_{2} = \frac{1000!}{999!1!} = 1000&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \Omega_{1} = \frac{1000!}{1000!} = 1&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\Delta{S} = k_{B}\;ln\;1000 = 9.54 \times 10^{-23} JK^{-1}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\Delta{S_{mol}} = N_{A}k_{B}\;ln\;1000 = 57.4 \,JK^{-1}mol^{-1}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Magnetisation Values of 1D and 2D Lattices===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;M = \sum_i s_i&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====1D Lattice Magnetisation====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;M_{1D} =\;\;+1&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====2D Lattice Magnetisation====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;M_{2D} =\;\;+1&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Magnetisation at 0K====&lt;br /&gt;
&lt;br /&gt;
At 0K, no thermal energy is available to overcome the energetic barriers to spin flipping. Considering the Hemholtz free energy:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; A = E - TS &amp;lt;/math&amp;gt; &lt;br /&gt;
&lt;br /&gt;
A temperature of 0K nullifies the entropic contribution to the free energy. Thus the energetic driving force (which maximises parallel spin interactions) dominates the entropic driving force (which maximises multiplicity of lattice states). For an Ising Lattice with D =  3, N = 1000 at 0K, the alignment of all spins results in the minimum energy configuration  and an overall magnetisation of &amp;lt;math&amp;gt; M = \pm 1000 &amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
= Calculating the Energy and Magnetisation =&lt;br /&gt;
==Modifying the Files==&lt;br /&gt;
&lt;br /&gt;
===Energy and Magnetisation Functions===&lt;br /&gt;
&lt;br /&gt;
====Energy===&lt;br /&gt;
[[File:First_Ene_Method.PNG]]&lt;br /&gt;
&lt;br /&gt;
The above energy method segments a given lattice into lattice cells on the edges, corners or in the bulk of the lattice and calculates the energy interactions with its neighbours as appropriate.&lt;br /&gt;
&lt;br /&gt;
====Magnetisation====&lt;br /&gt;
[[File:First_Mag_Method.PNG]]&lt;br /&gt;
&lt;br /&gt;
The magnetisation method loops over all elements in the array representing the Ising lattice and adds the value of the spin to the magnetisation variable.&lt;br /&gt;
&lt;br /&gt;
==Testing the Files==&lt;br /&gt;
&lt;br /&gt;
===ILCheck.py===&lt;br /&gt;
&lt;br /&gt;
[[File:ILChecks.PNG]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Above, the results of the ILcheck.py script are presented.&lt;br /&gt;
&lt;br /&gt;
= Introduction to the Monte Carlo Simulation =&lt;br /&gt;
===Configurations Available to a 100 Spin System===&lt;br /&gt;
For a system of two spins, 4 configurations are possible (↑↑, ↓↓, ↑↓, ↓↑) i.e. &amp;lt;math&amp;gt;2^{2}&amp;lt;/math&amp;gt;. For a system of 100 spins, &amp;lt;math&amp;gt;2^{100}&amp;lt;/math&amp;gt; configurations are expected. In the first example, the ↑↑ and ↓↓ are degenerate, as are the ↑↓ and ↓↑ configurations. Therefore, dividing the number of possible configurations by the multiplicity of each configuration (&amp;lt;math&amp;gt;2&amp;lt;/math&amp;gt;) gives the number of distinguishable configurations.&lt;br /&gt;
For 100 spins, this gives &amp;lt;math&amp;gt;\displaystyle\frac{2^{100}}{2} = 6.338 \times 10^{29} &amp;lt;/math&amp;gt; distinguishable configurations or states.&lt;br /&gt;
&lt;br /&gt;
If our computational speed allowed for &amp;lt;math&amp;gt; 1 \times 10^{9}&amp;lt;/math&amp;gt; calculations each second, the evaluation of a single value of &amp;lt;math&amp;gt;\left\langle M\right\rangle_T&amp;lt;/math&amp;gt; would last &amp;lt;math&amp;gt; 6.338 \times 10^{20} &amp;lt;/math&amp;gt; seconds or &amp;lt;math&amp;gt; 1458 &amp;lt;/math&amp;gt; times the age of the Universe!&lt;br /&gt;
&lt;br /&gt;
===Modifying IsingLattice.py===&lt;br /&gt;
&lt;br /&gt;
[[File:Monte_Carlo.PNG]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The Metropolis Monte Carlo (MMC) algorithm provides a computationally inexpensive path from random initial states to the minimum free energy states of the Ising lattices generated. First, a random 2D Ising lattice is generated. A single random spin within this lattice is &amp;quot;flipped&amp;quot; and the resulting energy change between these states is measured. If the energy change is negative, this represents a decrease in the internal energy of the system which lowers the free energy: this configuration change is accepted.&lt;br /&gt;
&lt;br /&gt;
In the case that the spin &amp;quot;flip&amp;quot; does not lower the free energy, the MMC algorithm tests this configuration change against the Boltzman factor, enabling a determination of the resulting entropy change. In the canonical (NVT) ensemble, the entropy of the system is given by&lt;br /&gt;
&lt;br /&gt;
###&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:stats.PNG]]&lt;br /&gt;
&lt;br /&gt;
===Spontaneous Magnetisation===&lt;br /&gt;
&lt;br /&gt;
Below the Curie Temperature, &amp;lt;math&amp;gt; T_{C} &amp;lt;/math&amp;gt;, energetic driving forces dominate entropic driving forces. Therefore, the spins of the system align in order to maximise favourable interactions rather than adopting a less ordered configuration, which would maximise multiplicity (and thus entropy).&lt;br /&gt;
Below &amp;lt;math&amp;gt;T &amp;lt; T_C&amp;lt;/math&amp;gt;, the most probable configurations have an overall magnetisation resulting in &amp;lt;math&amp;gt;\left\langle M\right\rangle \neq 0&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
The plots of magnetisation per spin and energy per spin obtained from ILanim.py upon system equilibration show that at minimum energy per spin &amp;lt;math&amp;gt;E_{min_{spin}} = \frac{-NDJ}{N} = -DJ = -2&amp;lt;/math&amp;gt;, the magnitude of the overall magnetisation per spin is at a maximum &amp;lt;math&amp;gt;|M_{spin}| = 1&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:2T=1.0.png]]&lt;br /&gt;
[[File:T=1.0.png]]&lt;br /&gt;
[[File:3T=1.0.png]]&lt;br /&gt;
&lt;br /&gt;
==Accelerating the Code==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Initial Method Speeds===&lt;br /&gt;
Taking 10 repeat measurements for the time taken to perform 2000 Monte Carlo steps resulted in&lt;br /&gt;
&lt;br /&gt;
* An average time of  &amp;lt;math&amp;gt;11.7s&amp;lt;/math&amp;gt; &lt;br /&gt;
* A standard error of &amp;lt;math&amp;gt;0.020s&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Updating Measurement===&lt;br /&gt;
&lt;br /&gt;
NOTE: ILtimetrial.py has been modified to:&lt;br /&gt;
* Perform a requested number of &#039;2000 Monte Carlo Step&#039; measurements&lt;br /&gt;
* Record these measurements in a CSV file&lt;br /&gt;
* Return the mean measuremd time and the Standard Error i.e.   &amp;lt;math&amp;gt; \frac{\sigma}{n} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:TimeTrialMethod.PNG]]&lt;br /&gt;
&lt;br /&gt;
===Updating Energy and Magnetisation Methods===&lt;br /&gt;
[[File:New_Mag_Method.PNG]]&lt;br /&gt;
[[File:New_Ene_Method.PNG]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Updated Method Speeds===&lt;br /&gt;
[[File:TimeTrial.PNG]]&lt;br /&gt;
&lt;br /&gt;
Taking 30 measurements of the time taken to perform 2000 Monte Carlo Steps resulted in:&lt;br /&gt;
&lt;br /&gt;
* An average time of &amp;lt;math&amp;gt;\displaystyle{0.87s}&amp;lt;/math&amp;gt;&lt;br /&gt;
* A standard error of &amp;lt;math&amp;gt;2.5 \times 10^{-3}s&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This represents a &#039;&#039;&#039;INSERT&#039;&#039;&#039;% decrease in computation time from the initial methods.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==The Effect of Temperature==&lt;br /&gt;
&lt;br /&gt;
===Correcting the Averaging  Code===&lt;br /&gt;
&lt;br /&gt;
To quickly find a value for &amp;lt;math&amp;gt; N_{d}&amp;lt;/math&amp;gt;, the minimum number of cycles typically needed for the equilibration of a system of within the lattice and temperature ranges of interest, it was assumed that:&lt;br /&gt;
&lt;br /&gt;
* Larger lattices would require more Monte Carlo steps to reach equilibrium from their initial, random configurations&lt;br /&gt;
&lt;br /&gt;
* Lattices at lower temperatures would require more Monte Carlo steps to reach equilibrium from their initial, random configurations.&lt;br /&gt;
&lt;br /&gt;
Therefore, an initial value for &amp;lt;math&amp;gt; N_{d}&amp;lt;/math&amp;gt; was found for a &amp;lt;math&amp;gt; 128\times128 &amp;lt;/math&amp;gt; lattice at a temperature of &amp;lt;math&amp;gt;0.5&amp;lt;/math&amp;gt; reduced temperature units.&lt;br /&gt;
*&amp;lt;math&amp;gt; N_{d} = 185000 &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
By this number of steps, all smaller lattices at all higher temperatures were found to have equilibrated also. Thus, this value of&amp;lt;math&amp;gt; N_{d}&amp;lt;/math&amp;gt; was accepted as an appropriate delay.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:AFinFrame 128 3e5 T= 0.5line.png|400px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
For the 128x128 lattices at T=0.5, equilibration was ensured from 185000 steps onwards.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Smaller lattices at the same temperature did indeed equilibrate more slowly, but all equilibrated within &amp;lt;math&amp;gt; N_{d}&amp;lt;/math&amp;gt; MC steps.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:AFinFrame 64 3e5 T= 0.5line.png|400px]]&lt;br /&gt;
[[File:AFinFrame 32 3e5 T= 0.5line2.png|400px]]&lt;br /&gt;
[[File:AFinFrame 16 3e5 T= 0.5line2.png|400px]]&lt;br /&gt;
[[File:AFinFrame 8 3e5 T= 0.5line.png|400px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The figure below shows the modifications made to IsingLattice.py to incorporate the &amp;lt;math&amp;gt; N_{d} &amp;lt;/math&amp;gt; step delay.&lt;br /&gt;
&lt;br /&gt;
===Running over a Range of Temperatures===&lt;br /&gt;
&lt;br /&gt;
To examine the effect of temperature on the average energy &amp;lt;math&amp;gt; \left\langle E\right\rangle &amp;lt;/math&amp;gt; and average magnetisation &amp;lt;math&amp;gt; \left\langle M\right\rangle &amp;lt;/math&amp;gt; of Ising lattices at equilibrium, the following parameters were used:&lt;br /&gt;
&lt;br /&gt;
* Temperature Range: &amp;lt;math&amp;gt;  0.5 - 5 &amp;lt;/math&amp;gt; reduced units&lt;br /&gt;
* Temperature Interval: &amp;lt;math&amp;gt;0.01&amp;lt;/math&amp;gt; reduced units (&amp;lt;math&amp;gt;450&amp;lt;/math&amp;gt; temperature values)&lt;br /&gt;
* Number of MMC Steps per Temperature value: &amp;lt;math&amp;gt; 2 \times 10^5 &amp;lt;/math&amp;gt; with the aforementioned value of &amp;lt;math&amp;gt; N_{d} = 1.85 \times 10^5 &amp;lt;/math&amp;gt; Monte Carlo steps&lt;br /&gt;
* Lattice Sizes:  &amp;lt;math&amp;gt; 2 \times 2 &amp;lt;/math&amp;gt;, &amp;lt;math&amp;gt; 4 \times 4 &amp;lt;/math&amp;gt; , &amp;lt;math&amp;gt; 8 \times 8 &amp;lt;/math&amp;gt; , &amp;lt;math&amp;gt; 16 \times 16 &amp;lt;/math&amp;gt; , &amp;lt;math&amp;gt; 32 \times 32 &amp;lt;/math&amp;gt; , &amp;lt;math&amp;gt; 64 \times 64 &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Plots of  &amp;lt;math&amp;gt; \left\langle E\right\rangle &amp;lt;/math&amp;gt; and  &amp;lt;math&amp;gt; \left\langle M\right\rangle &amp;lt;/math&amp;gt; per spin as versus temperature are presented below for each lattice size. Errorbars have been implemented to demonstrate how &#039;&#039;well-behaved&#039;&#039; lattice systems of each size are at each temperature, that is, how temperature and lattice size affect the size of the variations in the expected values. For the error calculations, the standard errors, &amp;lt;math&amp;gt; \sigma_\bar{X} &amp;lt;/math&amp;gt;,  in &amp;lt;math&amp;gt; \left\langle E\right\rangle &amp;lt;/math&amp;gt; and  &amp;lt;math&amp;gt; \left\langle M\right\rangle &amp;lt;/math&amp;gt; per spin have been used:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====8x8====&lt;br /&gt;
&lt;br /&gt;
[[File:8x8e+error.png]] [[File:8x8m+error.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
A Python script has been written to generate a plot of &amp;lt;math&amp;gt;\left\langle E\right\rangle&amp;lt;/math&amp;gt; or &amp;lt;math&amp;gt;\left\langle M\right\rangle&amp;lt;/math&amp;gt; against temperature based upon user input. A screenshot of this code has been inserted below.&lt;br /&gt;
&lt;br /&gt;
[[File:ExpectedvsTemp.PNG|200px]]&lt;br /&gt;
&lt;br /&gt;
===Scaling the System Size===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====2x2====&lt;br /&gt;
[[File:2x2e+error.png]] [[File:2x2m+error.png]]&lt;br /&gt;
&lt;br /&gt;
====4x4====&lt;br /&gt;
[[File:4x4e+error.png]] [[File:4x4m+error.png]]&lt;br /&gt;
&lt;br /&gt;
====16x16====&lt;br /&gt;
[[File:16x16e+error.png]] [[File:16x16m+error.png]]&lt;br /&gt;
&lt;br /&gt;
====32x32====&lt;br /&gt;
[[File:32x32e+error.png]] [[File:32x32m+error.png]]&lt;br /&gt;
&lt;br /&gt;
====64x64====&lt;br /&gt;
[[File:64x64e+error.png]] [[File:64x64m+error.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Determining the Heat Capacity==&lt;br /&gt;
&lt;br /&gt;
===Calculating the Heat Capacity===&lt;br /&gt;
Working in the canonical ensemble (constant volume), the heat capacity &amp;lt;math&amp;gt; C_V &amp;lt;/math&amp;gt; is given by:&lt;br /&gt;
&lt;br /&gt;
:&amp;lt;math&amp;gt;C_V = \frac{\partial \left\langle E\right\rangle}{\partial T}_V&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
where &amp;lt;math&amp;gt;\left\langle E\right\rangle&amp;lt;/math&amp;gt; is the average total energy or expected value of the internal energy of the system.&lt;br /&gt;
&lt;br /&gt;
: &amp;lt;math&amp;gt; \left\langle E\right\rangle = - \frac{\partial ln Q}{\partial \beta} = -\frac{1}{Q}\frac{\partial Q}{\partial \beta} &amp;lt;/math&amp;gt;&lt;br /&gt;
where &amp;lt;math&amp;gt; Q&amp;lt;/math&amp;gt; is the partition function for the system of N interacting spins.&lt;br /&gt;
&lt;br /&gt;
By evaluating the second form of the partial derivative with respect to &amp;lt;math&amp;gt; \beta&amp;lt;/math&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \left\langle E\right\rangle = -\frac{1}{Q}\frac{\partial Q}{\partial \beta} = \frac{\Sigma \epsilon_{i} e^{-\beta \epsilon_{i}}}{\Sigma e^{-\beta \epsilon_{i}}} &amp;lt;/math&amp;gt; &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Applying the product rule enables the differentiation of this expression for &amp;lt;math&amp;gt;\left\langle E\right\rangle&amp;lt;/math&amp;gt; with respect to temperature, giving:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\frac{\partial \left\langle E\right\rangle}{\partial T} = \frac{\Sigma \epsilon_{i} \frac{\epsilon_i}{k_BT^2}e^{-\beta \epsilon_{i}}}{\Sigma e^{-\beta \epsilon_{i}}} - \frac{\Sigma \epsilon_i e^{-\beta \epsilon_i}\cdot \frac{\epsilon_i}{k_BT^2}e^{-\beta \epsilon_i}}{(\Sigma e^{-\beta \epsilon_{i}})^2}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\frac{\partial \left\langle E\right\rangle}{\partial T}  = \frac{1}{k_BT^2}\left[\frac{\Sigma \epsilon_i^2 e^{-\beta \epsilon_i}}{\Sigma e^{-\beta \epsilon_i}} - \left(\frac{\Sigma \epsilon_{i} e^{-\beta \epsilon_{i}}}{\Sigma e^{-\beta \epsilon_{i}}}\right)^2\right] &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\frac{\partial \left\langle E\right\rangle}{\partial T}  = \frac{1}{k_BT^2}\left[\left\langle E^2\right\rangle - \left\langle E\right\rangle^2 \right] &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Thus,&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\frac{\partial \left\langle E\right\rangle}{\partial T} = \frac{Var[E]}{k_BT^2} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Heat Capacity versus Temperature===&lt;br /&gt;
&lt;br /&gt;
====2x2====&lt;br /&gt;
[[File:HC2.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====4x4====&lt;br /&gt;
[[File:HC4.png]]&lt;br /&gt;
&lt;br /&gt;
====8x8====&lt;br /&gt;
[[File:HC8.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====16x16====&lt;br /&gt;
[[File:HC16.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====32x32====&lt;br /&gt;
[[File:HC32.png]]&lt;br /&gt;
&lt;br /&gt;
== Locating the Curie Temperature ==&lt;br /&gt;
&lt;br /&gt;
===C++ Data Comparison===&lt;br /&gt;
&lt;br /&gt;
[[File:CHC2.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Polyfitting of C++ Data===&lt;br /&gt;
&lt;br /&gt;
====Fitting a Polynomial to the Entire Range====&lt;br /&gt;
&lt;br /&gt;
[[File:15Polyc2x2.png]]&lt;br /&gt;
Polynomials with 5 terms and above were found to match the data in the vicinity of the critical region considerably well. Below 7 terms, the &#039;&#039;tails&#039;&#039; of the plot were matched poorly. In the above example, a polynomial of 15 terms was fit to the data.&lt;br /&gt;
&lt;br /&gt;
=== Python Scripts ===&lt;/div&gt;</summary>
		<author><name>Jj1516</name></author>
	</entry>
	<entry>
		<id>https://chemwiki.ch.ic.ac.uk/index.php?title=Rep:JJ1516Ising&amp;diff=736468</id>
		<title>Rep:JJ1516Ising</title>
		<link rel="alternate" type="text/html" href="https://chemwiki.ch.ic.ac.uk/index.php?title=Rep:JJ1516Ising&amp;diff=736468"/>
		<updated>2018-11-20T19:41:22Z</updated>

		<summary type="html">&lt;p&gt;Jj1516: /* Calculating the Energy and Magnetisation */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Ex Script Link:&lt;br /&gt;
https://wiki.ch.ic.ac.uk/wiki/index.php?title=Third_year_CMP_compulsory_experiment&lt;br /&gt;
&lt;br /&gt;
= Introduction to the Ising Model =&lt;br /&gt;
&lt;br /&gt;
== The Model ==&lt;br /&gt;
&lt;br /&gt;
=== Minimum Energy State ===&lt;br /&gt;
====Minimum Interaction Energy====&lt;br /&gt;
The interaction energy of an Ising lattice is given by:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;E = -\frac{1}{2}J\displaystyle\sum_{i}^{N} \displaystyle\sum_{j\;\in\;{neighbours}\;(i)} \!\!\!\!\!\!\!\!\!\!\!\!s_{i}s_{j}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In an Ising lattice with D dimensions and periodic boundary conditions, a given spin &amp;lt;math&amp;gt; s_i&amp;lt;/math&amp;gt; has 2D neighbours.&lt;br /&gt;
&lt;br /&gt;
The minimum interaction energy is achieved when all spins in the lattice are aligned (all ↑ or all ↓). As  such, any spin &amp;lt;math&amp;gt; s_i&amp;lt;/math&amp;gt; must be aligned with all 2D of its neighbours. That is, &amp;lt;math&amp;gt;s_{i}s_{j} = 1&amp;lt;/math&amp;gt; for all &amp;lt;math&amp;gt;j&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Therefore, for any &amp;lt;math&amp;gt; s_i&amp;lt;/math&amp;gt;, the sum of its interactions is &amp;lt;math&amp;gt;\displaystyle\sum_{j\;\in\;{neighbours}\;(i)} \!\!\!\!\!\!\!\!\!\!\!\!s_{i}s_{j} = 2D &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
As this is true for all N spins in the lattice, it follows that &amp;lt;math&amp;gt;\displaystyle\sum_{i}^{N} 2D = 2DN&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Thus the minimum interaction energy is given by:&lt;br /&gt;
&lt;br /&gt;
:&amp;lt;math&amp;gt;E_{min} = -\frac{1}{2}J\cdot2DN = - DNJ &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Entropy of the Minimum Energy State====&lt;br /&gt;
&lt;br /&gt;
The entropy of a state is given by:&lt;br /&gt;
&lt;br /&gt;
:&amp;lt;math&amp;gt;S = k\; ln\; \Omega &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Where &amp;lt;math&amp;gt; \Omega &amp;lt;/math&amp;gt; is the multiplicity of the state, the number of degenerate configurations of said state. The minimum energy state is achievable with all spins ↑ or with all spins ↓. In the absence of an external magnetic field, these configurations are degenerate and indistinguishable giving &amp;lt;math&amp;gt; \Omega = 2 &amp;lt;/math&amp;gt; for this state. Therefore,&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; S_{E_{min}}  = k_{B}\; ln\; 2 = 0.693k_{B} = 9.57 \times 10^{-24} J\!\cdot\!\! K^{-1}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Phase Transitions ==&lt;br /&gt;
&lt;br /&gt;
=== Changes to Minimum Energy Configuration ===&lt;br /&gt;
&lt;br /&gt;
====Energy Change ====&lt;br /&gt;
The energy change &amp;lt;math&amp;gt; \Delta E&amp;lt;/math&amp;gt; associated with a single spin &#039;flip&#039; from the lowest energy onfiguration may be calculated by considering the change in the interaction energy with the spin&#039;s neighbours.&lt;br /&gt;
&lt;br /&gt;
Let &amp;lt;math&amp;gt; D = 3, N = 1000 &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\Delta{E} = E_1 - E_0&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;E_1&amp;lt;/math&amp;gt; Interaction energy after one spin has been &#039;flipped&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;E_0&amp;lt;/math&amp;gt; Lowest energy configuration&lt;br /&gt;
&lt;br /&gt;
[[Image:Task 2 table.PNG]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\displaystyle\sum_{interactions} = -2D + 2D(2D-2) + 2D[N-(2D+1)] &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; = 2DN - 8D &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;E_1 = \displaystyle-\frac{1}{2}J\;\sum_{interactions} = 4DJ - DNJ&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\Delta{E} = E_1 - E_0 = 4DJ - DNJ + DNJ = +4DJ = +12J&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This energy change is independent of &amp;lt;math&amp;gt; N&amp;lt;/math&amp;gt; and depends only on the dimension size and the coupling constant &amp;lt;math&amp;gt; J &amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
In this calculation, the following assumption has been made.&lt;br /&gt;
&lt;br /&gt;
* The lattice dimensions are infinite relative to the size of each cell&lt;br /&gt;
&lt;br /&gt;
This allows &#039;&#039;&#039;any&#039;&#039;&#039; cell to be treated as the centre of the lattice. As every cell interacts with 2D neighbours, flipping any cell in the minimum energy configuration results in the same energy change. Alternatively, the periodic boundary conditions of the Ising model remove the necessity for such an assumption. As a consequence, the absence of &amp;lt;math&amp;gt; N &amp;lt;/math&amp;gt; from the resulting energy change is justified.&lt;br /&gt;
&lt;br /&gt;
====Entropy Change====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; S = k_{B}\; ln\; \Omega &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\Omega = \displaystyle\frac{N!}{{N_{\uparrow}!}{N_{\downarrow}!}}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Where &amp;lt;math&amp;gt;N_{x}!&amp;lt;/math&amp;gt; denotes the factorial of the number of spins in spin state &amp;lt;math&amp;gt;x&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\Delta{S} = k_{B}\;ln\;\left(\displaystyle\frac{\Omega_{2}}{\Omega_{1}}\right)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\Omega_{2} = \frac{1000!}{999!1!} = 1000&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \Omega_{1} = \frac{1000!}{1000!} = 1&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\Delta{S} = k_{B}\;ln\;1000 = 9.54 \times 10^{-23} JK^{-1}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\Delta{S_{mol}} = N_{A}k_{B}\;ln\;1000 = 57.4 \,JK^{-1}mol^{-1}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Magnetisation Values of 1D and 2D Lattices===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;M = \sum_i s_i&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====1D Lattice Magnetisation====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;M_{1D} =\;\;+1&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====2D Lattice Magnetisation====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;M_{2D} =\;\;+1&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Magnetisation at 0K====&lt;br /&gt;
&lt;br /&gt;
At 0K, no thermal energy is available to overcome the energetic barriers to spin flipping. Considering the Hemholtz free energy:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; A = E - TS &amp;lt;/math&amp;gt; &lt;br /&gt;
&lt;br /&gt;
A temperature of 0K nullifies the entropic contribution to the free energy. Thus the energetic driving force (which maximises parallel spin interactions) dominates the entropic driving force (which maximises multiplicity of lattice states). For an Ising Lattice with D =  3, N = 1000 at 0K, the alignment of all spins results in the minimum energy configuration  and an overall magnetisation of &amp;lt;math&amp;gt; M = \pm 1000 &amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
= Calculating the Energy and Magnetisation =&lt;br /&gt;
==Modifying the Files==&lt;br /&gt;
&lt;br /&gt;
===Energy and Magnetisation Functions===&lt;br /&gt;
&lt;br /&gt;
====Energy===&lt;br /&gt;
[[File:First_Ene_Method.PNG]]&lt;br /&gt;
&lt;br /&gt;
The above energy method segments a given lattice into lattice cells on the edges, corners or in the bulk of the lattice and calculates the energy interactions with its neighbours as appropriate.&lt;br /&gt;
&lt;br /&gt;
====Magnetisation====&lt;br /&gt;
[[File:First_Mag_Method.PNG]]&lt;br /&gt;
&lt;br /&gt;
The magnetisation method loops over all elements in the array representing the Ising lattice and adds the value of the spin to the magnetisation variable.&lt;br /&gt;
&lt;br /&gt;
[[File:ILChecks.PNG]]&lt;br /&gt;
Above, the results of the ILcheck.py script are presented.&lt;br /&gt;
&lt;br /&gt;
= Introduction to the Monte Carlo Simulation =&lt;br /&gt;
===Configurations Available to a 100 Spin System===&lt;br /&gt;
For a system of two spins, 4 configurations are possible (↑↑, ↓↓, ↑↓, ↓↑) i.e. &amp;lt;math&amp;gt;2^{2}&amp;lt;/math&amp;gt;. For a system of 100 spins, &amp;lt;math&amp;gt;2^{100}&amp;lt;/math&amp;gt; configurations are expected. In the first example, the ↑↑ and ↓↓ are degenerate, as are the ↑↓ and ↓↑ configurations. Therefore, dividing the number of possible configurations by the multiplicity of each configuration (&amp;lt;math&amp;gt;2&amp;lt;/math&amp;gt;) gives the number of distinguishable configurations.&lt;br /&gt;
For 100 spins, this gives &amp;lt;math&amp;gt;\displaystyle\frac{2^{100}}{2} = 6.338 \times 10^{29} &amp;lt;/math&amp;gt; distinguishable configurations or states.&lt;br /&gt;
&lt;br /&gt;
If our computational speed allowed for &amp;lt;math&amp;gt; 1 \times 10^{9}&amp;lt;/math&amp;gt; calculations each second, the evaluation of a single value of &amp;lt;math&amp;gt;\left\langle M\right\rangle_T&amp;lt;/math&amp;gt; would last &amp;lt;math&amp;gt; 6.338 \times 10^{20} &amp;lt;/math&amp;gt; seconds or &amp;lt;math&amp;gt; 1458 &amp;lt;/math&amp;gt; times the age of the Universe!&lt;br /&gt;
&lt;br /&gt;
===Modifying IsingLattice.py===&lt;br /&gt;
&lt;br /&gt;
[[File:Monte_Carlo.PNG]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The Metropolis Monte Carlo (MMC) algorithm provides a computationally inexpensive path from random initial states to the minimum free energy states of the Ising lattices generated. First, a random 2D Ising lattice is generated. A single random spin within this lattice is &amp;quot;flipped&amp;quot; and the resulting energy change between these states is measured. If the energy change is negative, this represents a decrease in the internal energy of the system which lowers the free energy: this configuration change is accepted.&lt;br /&gt;
&lt;br /&gt;
In the case that the spin &amp;quot;flip&amp;quot; does not lower the free energy, the MMC algorithm tests this configuration change against the Boltzman factor, enabling a determination of the resulting entropy change. In the canonical (NVT) ensemble, the entropy of the system is given by&lt;br /&gt;
&lt;br /&gt;
###&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:stats.PNG]]&lt;br /&gt;
&lt;br /&gt;
===Spontaneous Magnetisation===&lt;br /&gt;
&lt;br /&gt;
Below the Curie Temperature, &amp;lt;math&amp;gt; T_{C} &amp;lt;/math&amp;gt;, energetic driving forces dominate entropic driving forces. Therefore, the spins of the system align in order to maximise favourable interactions rather than adopting a less ordered configuration, which would maximise multiplicity (and thus entropy).&lt;br /&gt;
Below &amp;lt;math&amp;gt;T &amp;lt; T_C&amp;lt;/math&amp;gt;, the most probable configurations have an overall magnetisation resulting in &amp;lt;math&amp;gt;\left\langle M\right\rangle \neq 0&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
The plots of magnetisation per spin and energy per spin obtained from ILanim.py upon system equilibration show that at minimum energy per spin &amp;lt;math&amp;gt;E_{min_{spin}} = \frac{-NDJ}{N} = -DJ = -2&amp;lt;/math&amp;gt;, the magnitude of the overall magnetisation per spin is at a maximum &amp;lt;math&amp;gt;|M_{spin}| = 1&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:2T=1.0.png]]&lt;br /&gt;
[[File:T=1.0.png]]&lt;br /&gt;
[[File:3T=1.0.png]]&lt;br /&gt;
&lt;br /&gt;
==Accelerating the Code==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Initial Method Speeds===&lt;br /&gt;
Taking 10 repeat measurements for the time taken to perform 2000 Monte Carlo steps resulted in&lt;br /&gt;
&lt;br /&gt;
* An average time of  &amp;lt;math&amp;gt;11.7s&amp;lt;/math&amp;gt; &lt;br /&gt;
* A standard error of &amp;lt;math&amp;gt;0.020s&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Updating Measurement===&lt;br /&gt;
&lt;br /&gt;
NOTE: ILtimetrial.py has been modified to:&lt;br /&gt;
* Perform a requested number of &#039;2000 Monte Carlo Step&#039; measurements&lt;br /&gt;
* Record these measurements in a CSV file&lt;br /&gt;
* Return the mean measuremd time and the Standard Error i.e.   &amp;lt;math&amp;gt; \frac{\sigma}{n} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:TimeTrialMethod.PNG]]&lt;br /&gt;
&lt;br /&gt;
===Updating Energy and Magnetisation Methods===&lt;br /&gt;
[[File:New_Mag_Method.PNG]]&lt;br /&gt;
[[File:New_Ene_Method.PNG]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Updated Method Speeds===&lt;br /&gt;
[[File:TimeTrial.PNG]]&lt;br /&gt;
&lt;br /&gt;
Taking 30 measurements of the time taken to perform 2000 Monte Carlo Steps resulted in:&lt;br /&gt;
&lt;br /&gt;
* An average time of &amp;lt;math&amp;gt;\displaystyle{0.87s}&amp;lt;/math&amp;gt;&lt;br /&gt;
* A standard error of &amp;lt;math&amp;gt;2.5 \times 10^{-3}s&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This represents a &#039;&#039;&#039;INSERT&#039;&#039;&#039;% decrease in computation time from the initial methods.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==The Effect of Temperature==&lt;br /&gt;
&lt;br /&gt;
===Correcting the Averaging  Code===&lt;br /&gt;
&lt;br /&gt;
To quickly find a value for &amp;lt;math&amp;gt; N_{d}&amp;lt;/math&amp;gt;, the minimum number of cycles typically needed for the equilibration of a system of within the lattice and temperature ranges of interest, it was assumed that:&lt;br /&gt;
&lt;br /&gt;
* Larger lattices would require more Monte Carlo steps to reach equilibrium from their initial, random configurations&lt;br /&gt;
&lt;br /&gt;
* Lattices at lower temperatures would require more Monte Carlo steps to reach equilibrium from their initial, random configurations.&lt;br /&gt;
&lt;br /&gt;
Therefore, an initial value for &amp;lt;math&amp;gt; N_{d}&amp;lt;/math&amp;gt; was found for a &amp;lt;math&amp;gt; 128\times128 &amp;lt;/math&amp;gt; lattice at a temperature of &amp;lt;math&amp;gt;0.5&amp;lt;/math&amp;gt; reduced temperature units.&lt;br /&gt;
*&amp;lt;math&amp;gt; N_{d} = 185000 &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
By this number of steps, all smaller lattices at all higher temperatures were found to have equilibrated also. Thus, this value of&amp;lt;math&amp;gt; N_{d}&amp;lt;/math&amp;gt; was accepted as an appropriate delay.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:AFinFrame 128 3e5 T= 0.5line.png|400px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
For the 128x128 lattices at T=0.5, equilibration was ensured from 185000 steps onwards.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Smaller lattices at the same temperature did indeed equilibrate more slowly, but all equilibrated within &amp;lt;math&amp;gt; N_{d}&amp;lt;/math&amp;gt; MC steps.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:AFinFrame 64 3e5 T= 0.5line.png|400px]]&lt;br /&gt;
[[File:AFinFrame 32 3e5 T= 0.5line2.png|400px]]&lt;br /&gt;
[[File:AFinFrame 16 3e5 T= 0.5line2.png|400px]]&lt;br /&gt;
[[File:AFinFrame 8 3e5 T= 0.5line.png|400px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The figure below shows the modifications made to IsingLattice.py to incorporate the &amp;lt;math&amp;gt; N_{d} &amp;lt;/math&amp;gt; step delay.&lt;br /&gt;
&lt;br /&gt;
===Running over a Range of Temperatures===&lt;br /&gt;
&lt;br /&gt;
To examine the effect of temperature on the average energy &amp;lt;math&amp;gt; \left\langle E\right\rangle &amp;lt;/math&amp;gt; and average magnetisation &amp;lt;math&amp;gt; \left\langle M\right\rangle &amp;lt;/math&amp;gt; of Ising lattices at equilibrium, the following parameters were used:&lt;br /&gt;
&lt;br /&gt;
* Temperature Range: &amp;lt;math&amp;gt;  0.5 - 5 &amp;lt;/math&amp;gt; reduced units&lt;br /&gt;
* Temperature Interval: &amp;lt;math&amp;gt;0.01&amp;lt;/math&amp;gt; reduced units (&amp;lt;math&amp;gt;450&amp;lt;/math&amp;gt; temperature values)&lt;br /&gt;
* Number of MMC Steps per Temperature value: &amp;lt;math&amp;gt; 2 \times 10^5 &amp;lt;/math&amp;gt; with the aforementioned value of &amp;lt;math&amp;gt; N_{d} = 1.85 \times 10^5 &amp;lt;/math&amp;gt; Monte Carlo steps&lt;br /&gt;
* Lattice Sizes:  &amp;lt;math&amp;gt; 2 \times 2 &amp;lt;/math&amp;gt;, &amp;lt;math&amp;gt; 4 \times 4 &amp;lt;/math&amp;gt; , &amp;lt;math&amp;gt; 8 \times 8 &amp;lt;/math&amp;gt; , &amp;lt;math&amp;gt; 16 \times 16 &amp;lt;/math&amp;gt; , &amp;lt;math&amp;gt; 32 \times 32 &amp;lt;/math&amp;gt; , &amp;lt;math&amp;gt; 64 \times 64 &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Plots of  &amp;lt;math&amp;gt; \left\langle E\right\rangle &amp;lt;/math&amp;gt; and  &amp;lt;math&amp;gt; \left\langle M\right\rangle &amp;lt;/math&amp;gt; per spin as versus temperature are presented below for each lattice size. Errorbars have been implemented to demonstrate how &#039;&#039;well-behaved&#039;&#039; lattice systems of each size are at each temperature, that is, how temperature and lattice size affect the size of the variations in the expected values. For the error calculations, the standard errors, &amp;lt;math&amp;gt; \sigma_\bar{X} &amp;lt;/math&amp;gt;,  in &amp;lt;math&amp;gt; \left\langle E\right\rangle &amp;lt;/math&amp;gt; and  &amp;lt;math&amp;gt; \left\langle M\right\rangle &amp;lt;/math&amp;gt; per spin have been used:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====8x8====&lt;br /&gt;
&lt;br /&gt;
[[File:8x8e+error.png]] [[File:8x8m+error.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
A Python script has been written to generate a plot of &amp;lt;math&amp;gt;\left\langle E\right\rangle&amp;lt;/math&amp;gt; or &amp;lt;math&amp;gt;\left\langle M\right\rangle&amp;lt;/math&amp;gt; against temperature based upon user input. A screenshot of this code has been inserted below.&lt;br /&gt;
&lt;br /&gt;
[[File:ExpectedvsTemp.PNG|200px]]&lt;br /&gt;
&lt;br /&gt;
===Scaling the System Size===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====2x2====&lt;br /&gt;
[[File:2x2e+error.png]] [[File:2x2m+error.png]]&lt;br /&gt;
&lt;br /&gt;
====4x4====&lt;br /&gt;
[[File:4x4e+error.png]] [[File:4x4m+error.png]]&lt;br /&gt;
&lt;br /&gt;
====16x16====&lt;br /&gt;
[[File:16x16e+error.png]] [[File:16x16m+error.png]]&lt;br /&gt;
&lt;br /&gt;
====32x32====&lt;br /&gt;
[[File:32x32e+error.png]] [[File:32x32m+error.png]]&lt;br /&gt;
&lt;br /&gt;
====64x64====&lt;br /&gt;
[[File:64x64e+error.png]] [[File:64x64m+error.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Determining the Heat Capacity==&lt;br /&gt;
&lt;br /&gt;
===Calculating the Heat Capacity===&lt;br /&gt;
Working in the canonical ensemble (constant volume), the heat capacity &amp;lt;math&amp;gt; C_V &amp;lt;/math&amp;gt; is given by:&lt;br /&gt;
&lt;br /&gt;
:&amp;lt;math&amp;gt;C_V = \frac{\partial \left\langle E\right\rangle}{\partial T}_V&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
where &amp;lt;math&amp;gt;\left\langle E\right\rangle&amp;lt;/math&amp;gt; is the average total energy or expected value of the internal energy of the system.&lt;br /&gt;
&lt;br /&gt;
: &amp;lt;math&amp;gt; \left\langle E\right\rangle = - \frac{\partial ln Q}{\partial \beta} = -\frac{1}{Q}\frac{\partial Q}{\partial \beta} &amp;lt;/math&amp;gt;&lt;br /&gt;
where &amp;lt;math&amp;gt; Q&amp;lt;/math&amp;gt; is the partition function for the system of N interacting spins.&lt;br /&gt;
&lt;br /&gt;
By evaluating the second form of the partial derivative with respect to &amp;lt;math&amp;gt; \beta&amp;lt;/math&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \left\langle E\right\rangle = -\frac{1}{Q}\frac{\partial Q}{\partial \beta} = \frac{\Sigma \epsilon_{i} e^{-\beta \epsilon_{i}}}{\Sigma e^{-\beta \epsilon_{i}}} &amp;lt;/math&amp;gt; &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Applying the product rule enables the differentiation of this expression for &amp;lt;math&amp;gt;\left\langle E\right\rangle&amp;lt;/math&amp;gt; with respect to temperature, giving:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\frac{\partial \left\langle E\right\rangle}{\partial T} = \frac{\Sigma \epsilon_{i} \frac{\epsilon_i}{k_BT^2}e^{-\beta \epsilon_{i}}}{\Sigma e^{-\beta \epsilon_{i}}} - \frac{\Sigma \epsilon_i e^{-\beta \epsilon_i}\cdot \frac{\epsilon_i}{k_BT^2}e^{-\beta \epsilon_i}}{(\Sigma e^{-\beta \epsilon_{i}})^2}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\frac{\partial \left\langle E\right\rangle}{\partial T}  = \frac{1}{k_BT^2}\left[\frac{\Sigma \epsilon_i^2 e^{-\beta \epsilon_i}}{\Sigma e^{-\beta \epsilon_i}} - \left(\frac{\Sigma \epsilon_{i} e^{-\beta \epsilon_{i}}}{\Sigma e^{-\beta \epsilon_{i}}}\right)^2\right] &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\frac{\partial \left\langle E\right\rangle}{\partial T}  = \frac{1}{k_BT^2}\left[\left\langle E^2\right\rangle - \left\langle E\right\rangle^2 \right] &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Thus,&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\frac{\partial \left\langle E\right\rangle}{\partial T} = \frac{Var[E]}{k_BT^2} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Heat Capacity versus Temperature===&lt;br /&gt;
&lt;br /&gt;
====2x2====&lt;br /&gt;
[[File:HC2.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====4x4====&lt;br /&gt;
[[File:HC4.png]]&lt;br /&gt;
&lt;br /&gt;
====8x8====&lt;br /&gt;
[[File:HC8.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====16x16====&lt;br /&gt;
[[File:HC16.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====32x32====&lt;br /&gt;
[[File:HC32.png]]&lt;br /&gt;
&lt;br /&gt;
== Locating the Curie Temperature ==&lt;br /&gt;
&lt;br /&gt;
===C++ Data Comparison===&lt;br /&gt;
&lt;br /&gt;
[[File:CHC2.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Polyfitting of C++ Data===&lt;br /&gt;
&lt;br /&gt;
====Fitting a Polynomial to the Entire Range====&lt;br /&gt;
&lt;br /&gt;
[[File:15Polyc2x2.png]]&lt;br /&gt;
Polynomials with 5 terms and above were found to match the data in the vicinity of the critical region considerably well. Below 7 terms, the &#039;&#039;tails&#039;&#039; of the plot were matched poorly. In the above example, a polynomial of 15 terms was fit to the data.&lt;br /&gt;
&lt;br /&gt;
=== Python Scripts ===&lt;/div&gt;</summary>
		<author><name>Jj1516</name></author>
	</entry>
	<entry>
		<id>https://chemwiki.ch.ic.ac.uk/index.php?title=Rep:JJ1516Ising&amp;diff=736461</id>
		<title>Rep:JJ1516Ising</title>
		<link rel="alternate" type="text/html" href="https://chemwiki.ch.ic.ac.uk/index.php?title=Rep:JJ1516Ising&amp;diff=736461"/>
		<updated>2018-11-20T19:30:11Z</updated>

		<summary type="html">&lt;p&gt;Jj1516: /* Magnetisation at 0K */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Ex Script Link:&lt;br /&gt;
https://wiki.ch.ic.ac.uk/wiki/index.php?title=Third_year_CMP_compulsory_experiment&lt;br /&gt;
&lt;br /&gt;
= Introduction to the Ising Model =&lt;br /&gt;
&lt;br /&gt;
== The Model ==&lt;br /&gt;
&lt;br /&gt;
=== Minimum Energy State ===&lt;br /&gt;
====Minimum Interaction Energy====&lt;br /&gt;
The interaction energy of an Ising lattice is given by:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;E = -\frac{1}{2}J\displaystyle\sum_{i}^{N} \displaystyle\sum_{j\;\in\;{neighbours}\;(i)} \!\!\!\!\!\!\!\!\!\!\!\!s_{i}s_{j}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In an Ising lattice with D dimensions and periodic boundary conditions, a given spin &amp;lt;math&amp;gt; s_i&amp;lt;/math&amp;gt; has 2D neighbours.&lt;br /&gt;
&lt;br /&gt;
The minimum interaction energy is achieved when all spins in the lattice are aligned (all ↑ or all ↓). As  such, any spin &amp;lt;math&amp;gt; s_i&amp;lt;/math&amp;gt; must be aligned with all 2D of its neighbours. That is, &amp;lt;math&amp;gt;s_{i}s_{j} = 1&amp;lt;/math&amp;gt; for all &amp;lt;math&amp;gt;j&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Therefore, for any &amp;lt;math&amp;gt; s_i&amp;lt;/math&amp;gt;, the sum of its interactions is &amp;lt;math&amp;gt;\displaystyle\sum_{j\;\in\;{neighbours}\;(i)} \!\!\!\!\!\!\!\!\!\!\!\!s_{i}s_{j} = 2D &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
As this is true for all N spins in the lattice, it follows that &amp;lt;math&amp;gt;\displaystyle\sum_{i}^{N} 2D = 2DN&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Thus the minimum interaction energy is given by:&lt;br /&gt;
&lt;br /&gt;
:&amp;lt;math&amp;gt;E_{min} = -\frac{1}{2}J\cdot2DN = - DNJ &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Entropy of the Minimum Energy State====&lt;br /&gt;
&lt;br /&gt;
The entropy of a state is given by:&lt;br /&gt;
&lt;br /&gt;
:&amp;lt;math&amp;gt;S = k\; ln\; \Omega &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Where &amp;lt;math&amp;gt; \Omega &amp;lt;/math&amp;gt; is the multiplicity of the state, the number of degenerate configurations of said state. The minimum energy state is achievable with all spins ↑ or with all spins ↓. In the absence of an external magnetic field, these configurations are degenerate and indistinguishable giving &amp;lt;math&amp;gt; \Omega = 2 &amp;lt;/math&amp;gt; for this state. Therefore,&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; S_{E_{min}}  = k_{B}\; ln\; 2 = 0.693k_{B} = 9.57 \times 10^{-24} J\!\cdot\!\! K^{-1}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Phase Transitions ==&lt;br /&gt;
&lt;br /&gt;
=== Changes to Minimum Energy Configuration ===&lt;br /&gt;
&lt;br /&gt;
====Energy Change ====&lt;br /&gt;
The energy change &amp;lt;math&amp;gt; \Delta E&amp;lt;/math&amp;gt; associated with a single spin &#039;flip&#039; from the lowest energy onfiguration may be calculated by considering the change in the interaction energy with the spin&#039;s neighbours.&lt;br /&gt;
&lt;br /&gt;
Let &amp;lt;math&amp;gt; D = 3, N = 1000 &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\Delta{E} = E_1 - E_0&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;E_1&amp;lt;/math&amp;gt; Interaction energy after one spin has been &#039;flipped&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;E_0&amp;lt;/math&amp;gt; Lowest energy configuration&lt;br /&gt;
&lt;br /&gt;
[[Image:Task 2 table.PNG]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\displaystyle\sum_{interactions} = -2D + 2D(2D-2) + 2D[N-(2D+1)] &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; = 2DN - 8D &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;E_1 = \displaystyle-\frac{1}{2}J\;\sum_{interactions} = 4DJ - DNJ&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\Delta{E} = E_1 - E_0 = 4DJ - DNJ + DNJ = +4DJ = +12J&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This energy change is independent of &amp;lt;math&amp;gt; N&amp;lt;/math&amp;gt; and depends only on the dimension size and the coupling constant &amp;lt;math&amp;gt; J &amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
In this calculation, the following assumption has been made.&lt;br /&gt;
&lt;br /&gt;
* The lattice dimensions are infinite relative to the size of each cell&lt;br /&gt;
&lt;br /&gt;
This allows &#039;&#039;&#039;any&#039;&#039;&#039; cell to be treated as the centre of the lattice. As every cell interacts with 2D neighbours, flipping any cell in the minimum energy configuration results in the same energy change. Alternatively, the periodic boundary conditions of the Ising model remove the necessity for such an assumption. As a consequence, the absence of &amp;lt;math&amp;gt; N &amp;lt;/math&amp;gt; from the resulting energy change is justified.&lt;br /&gt;
&lt;br /&gt;
====Entropy Change====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; S = k_{B}\; ln\; \Omega &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\Omega = \displaystyle\frac{N!}{{N_{\uparrow}!}{N_{\downarrow}!}}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Where &amp;lt;math&amp;gt;N_{x}!&amp;lt;/math&amp;gt; denotes the factorial of the number of spins in spin state &amp;lt;math&amp;gt;x&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\Delta{S} = k_{B}\;ln\;\left(\displaystyle\frac{\Omega_{2}}{\Omega_{1}}\right)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\Omega_{2} = \frac{1000!}{999!1!} = 1000&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \Omega_{1} = \frac{1000!}{1000!} = 1&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\Delta{S} = k_{B}\;ln\;1000 = 9.54 \times 10^{-23} JK^{-1}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\Delta{S_{mol}} = N_{A}k_{B}\;ln\;1000 = 57.4 \,JK^{-1}mol^{-1}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Magnetisation Values of 1D and 2D Lattices===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;M = \sum_i s_i&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====1D Lattice Magnetisation====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;M_{1D} =\;\;+1&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====2D Lattice Magnetisation====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;M_{2D} =\;\;+1&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Magnetisation at 0K====&lt;br /&gt;
&lt;br /&gt;
At 0K, no thermal energy is available to overcome the energetic barriers to spin flipping. Considering the Hemholtz free energy:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; A = E - TS &amp;lt;/math&amp;gt; &lt;br /&gt;
&lt;br /&gt;
A temperature of 0K nullifies the entropic contribution to the free energy. Thus the energetic driving force (which maximises parallel spin interactions) dominates the entropic driving force (which maximises multiplicity of lattice states). For an Ising Lattice with D =  3, N = 1000 at 0K, the alignment of all spins results in the minimum energy configuration  and an overall magnetisation of &amp;lt;math&amp;gt; M = \pm 1000 &amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
= Calculating the Energy and Magnetisation =&lt;br /&gt;
&lt;br /&gt;
[[File:First_Ene_Method.PNG]]&lt;br /&gt;
&lt;br /&gt;
[[File:First_Mag_Method.PNG]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:ILChecks.PNG]]&lt;br /&gt;
&lt;br /&gt;
= Introduction to the Monte Carlo Simulation =&lt;br /&gt;
===Configurations Available to a 100 Spin System===&lt;br /&gt;
For a system of two spins, 4 configurations are possible (↑↑, ↓↓, ↑↓, ↓↑) i.e. &amp;lt;math&amp;gt;2^{2}&amp;lt;/math&amp;gt;. For a system of 100 spins, &amp;lt;math&amp;gt;2^{100}&amp;lt;/math&amp;gt; configurations are expected. In the first example, the ↑↑ and ↓↓ are degenerate, as are the ↑↓ and ↓↑ configurations. Therefore, dividing the number of possible configurations by the multiplicity of each configuration (&amp;lt;math&amp;gt;2&amp;lt;/math&amp;gt;) gives the number of distinguishable configurations.&lt;br /&gt;
For 100 spins, this gives &amp;lt;math&amp;gt;\displaystyle\frac{2^{100}}{2} = 6.338 \times 10^{29} &amp;lt;/math&amp;gt; distinguishable configurations or states.&lt;br /&gt;
&lt;br /&gt;
If our computational speed allowed for &amp;lt;math&amp;gt; 1 \times 10^{9}&amp;lt;/math&amp;gt; calculations each second, the evaluation of a single value of &amp;lt;math&amp;gt;\left\langle M\right\rangle_T&amp;lt;/math&amp;gt; would last &amp;lt;math&amp;gt; 6.338 \times 10^{20} &amp;lt;/math&amp;gt; seconds or &amp;lt;math&amp;gt; 1458 &amp;lt;/math&amp;gt; times the age of the Universe!&lt;br /&gt;
&lt;br /&gt;
===Modifying IsingLattice.py===&lt;br /&gt;
&lt;br /&gt;
[[File:Monte_Carlo.PNG]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The Metropolis Monte Carlo (MMC) algorithm provides a computationally inexpensive path from random initial states to the minimum free energy states of the Ising lattices generated. First, a random 2D Ising lattice is generated. A single random spin within this lattice is &amp;quot;flipped&amp;quot; and the resulting energy change between these states is measured. If the energy change is negative, this represents a decrease in the internal energy of the system which lowers the free energy: this configuration change is accepted.&lt;br /&gt;
&lt;br /&gt;
In the case that the spin &amp;quot;flip&amp;quot; does not lower the free energy, the MMC algorithm tests this configuration change against the Boltzman factor, enabling a determination of the resulting entropy change. In the canonical (NVT) ensemble, the entropy of the system is given by&lt;br /&gt;
&lt;br /&gt;
###&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:stats.PNG]]&lt;br /&gt;
&lt;br /&gt;
===Spontaneous Magnetisation===&lt;br /&gt;
&lt;br /&gt;
Below the Curie Temperature, &amp;lt;math&amp;gt; T_{C} &amp;lt;/math&amp;gt;, energetic driving forces dominate entropic driving forces. Therefore, the spins of the system align in order to maximise favourable interactions rather than adopting a less ordered configuration, which would maximise multiplicity (and thus entropy).&lt;br /&gt;
Below &amp;lt;math&amp;gt;T &amp;lt; T_C&amp;lt;/math&amp;gt;, the most probable configurations have an overall magnetisation resulting in &amp;lt;math&amp;gt;\left\langle M\right\rangle \neq 0&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
The plots of magnetisation per spin and energy per spin obtained from ILanim.py upon system equilibration show that at minimum energy per spin &amp;lt;math&amp;gt;E_{min_{spin}} = \frac{-NDJ}{N} = -DJ = -2&amp;lt;/math&amp;gt;, the magnitude of the overall magnetisation per spin is at a maximum &amp;lt;math&amp;gt;|M_{spin}| = 1&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:2T=1.0.png]]&lt;br /&gt;
[[File:T=1.0.png]]&lt;br /&gt;
[[File:3T=1.0.png]]&lt;br /&gt;
&lt;br /&gt;
==Accelerating the Code==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Initial Method Speeds===&lt;br /&gt;
Taking 10 repeat measurements for the time taken to perform 2000 Monte Carlo steps resulted in&lt;br /&gt;
&lt;br /&gt;
* An average time of  &amp;lt;math&amp;gt;11.7s&amp;lt;/math&amp;gt; &lt;br /&gt;
* A standard error of &amp;lt;math&amp;gt;0.020s&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Updating Measurement===&lt;br /&gt;
&lt;br /&gt;
NOTE: ILtimetrial.py has been modified to:&lt;br /&gt;
* Perform a requested number of &#039;2000 Monte Carlo Step&#039; measurements&lt;br /&gt;
* Record these measurements in a CSV file&lt;br /&gt;
* Return the mean measuremd time and the Standard Error i.e.   &amp;lt;math&amp;gt; \frac{\sigma}{n} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:TimeTrialMethod.PNG]]&lt;br /&gt;
&lt;br /&gt;
===Updating Energy and Magnetisation Methods===&lt;br /&gt;
[[File:New_Mag_Method.PNG]]&lt;br /&gt;
[[File:New_Ene_Method.PNG]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Updated Method Speeds===&lt;br /&gt;
[[File:TimeTrial.PNG]]&lt;br /&gt;
&lt;br /&gt;
Taking 30 measurements of the time taken to perform 2000 Monte Carlo Steps resulted in:&lt;br /&gt;
&lt;br /&gt;
* An average time of &amp;lt;math&amp;gt;\displaystyle{0.87s}&amp;lt;/math&amp;gt;&lt;br /&gt;
* A standard error of &amp;lt;math&amp;gt;2.5 \times 10^{-3}s&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This represents a &#039;&#039;&#039;INSERT&#039;&#039;&#039;% decrease in computation time from the initial methods.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==The Effect of Temperature==&lt;br /&gt;
&lt;br /&gt;
===Correcting the Averaging  Code===&lt;br /&gt;
&lt;br /&gt;
To quickly find a value for &amp;lt;math&amp;gt; N_{d}&amp;lt;/math&amp;gt;, the minimum number of cycles typically needed for the equilibration of a system of within the lattice and temperature ranges of interest, it was assumed that:&lt;br /&gt;
&lt;br /&gt;
* Larger lattices would require more Monte Carlo steps to reach equilibrium from their initial, random configurations&lt;br /&gt;
&lt;br /&gt;
* Lattices at lower temperatures would require more Monte Carlo steps to reach equilibrium from their initial, random configurations.&lt;br /&gt;
&lt;br /&gt;
Therefore, an initial value for &amp;lt;math&amp;gt; N_{d}&amp;lt;/math&amp;gt; was found for a &amp;lt;math&amp;gt; 128\times128 &amp;lt;/math&amp;gt; lattice at a temperature of &amp;lt;math&amp;gt;0.5&amp;lt;/math&amp;gt; reduced temperature units.&lt;br /&gt;
*&amp;lt;math&amp;gt; N_{d} = 185000 &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
By this number of steps, all smaller lattices at all higher temperatures were found to have equilibrated also. Thus, this value of&amp;lt;math&amp;gt; N_{d}&amp;lt;/math&amp;gt; was accepted as an appropriate delay.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:AFinFrame 128 3e5 T= 0.5line.png|400px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
For the 128x128 lattices at T=0.5, equilibration was ensured from 185000 steps onwards.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Smaller lattices at the same temperature did indeed equilibrate more slowly, but all equilibrated within &amp;lt;math&amp;gt; N_{d}&amp;lt;/math&amp;gt; MC steps.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:AFinFrame 64 3e5 T= 0.5line.png|400px]]&lt;br /&gt;
[[File:AFinFrame 32 3e5 T= 0.5line2.png|400px]]&lt;br /&gt;
[[File:AFinFrame 16 3e5 T= 0.5line2.png|400px]]&lt;br /&gt;
[[File:AFinFrame 8 3e5 T= 0.5line.png|400px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The figure below shows the modifications made to IsingLattice.py to incorporate the &amp;lt;math&amp;gt; N_{d} &amp;lt;/math&amp;gt; step delay.&lt;br /&gt;
&lt;br /&gt;
===Running over a Range of Temperatures===&lt;br /&gt;
&lt;br /&gt;
To examine the effect of temperature on the average energy &amp;lt;math&amp;gt; \left\langle E\right\rangle &amp;lt;/math&amp;gt; and average magnetisation &amp;lt;math&amp;gt; \left\langle M\right\rangle &amp;lt;/math&amp;gt; of Ising lattices at equilibrium, the following parameters were used:&lt;br /&gt;
&lt;br /&gt;
* Temperature Range: &amp;lt;math&amp;gt;  0.5 - 5 &amp;lt;/math&amp;gt; reduced units&lt;br /&gt;
* Temperature Interval: &amp;lt;math&amp;gt;0.01&amp;lt;/math&amp;gt; reduced units (&amp;lt;math&amp;gt;450&amp;lt;/math&amp;gt; temperature values)&lt;br /&gt;
* Number of MMC Steps per Temperature value: &amp;lt;math&amp;gt; 2 \times 10^5 &amp;lt;/math&amp;gt; with the aforementioned value of &amp;lt;math&amp;gt; N_{d} = 1.85 \times 10^5 &amp;lt;/math&amp;gt; Monte Carlo steps&lt;br /&gt;
* Lattice Sizes:  &amp;lt;math&amp;gt; 2 \times 2 &amp;lt;/math&amp;gt;, &amp;lt;math&amp;gt; 4 \times 4 &amp;lt;/math&amp;gt; , &amp;lt;math&amp;gt; 8 \times 8 &amp;lt;/math&amp;gt; , &amp;lt;math&amp;gt; 16 \times 16 &amp;lt;/math&amp;gt; , &amp;lt;math&amp;gt; 32 \times 32 &amp;lt;/math&amp;gt; , &amp;lt;math&amp;gt; 64 \times 64 &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Plots of  &amp;lt;math&amp;gt; \left\langle E\right\rangle &amp;lt;/math&amp;gt; and  &amp;lt;math&amp;gt; \left\langle M\right\rangle &amp;lt;/math&amp;gt; per spin as versus temperature are presented below for each lattice size. Errorbars have been implemented to demonstrate how &#039;&#039;well-behaved&#039;&#039; lattice systems of each size are at each temperature, that is, how temperature and lattice size affect the size of the variations in the expected values. For the error calculations, the standard errors, &amp;lt;math&amp;gt; \sigma_\bar{X} &amp;lt;/math&amp;gt;,  in &amp;lt;math&amp;gt; \left\langle E\right\rangle &amp;lt;/math&amp;gt; and  &amp;lt;math&amp;gt; \left\langle M\right\rangle &amp;lt;/math&amp;gt; per spin have been used:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====8x8====&lt;br /&gt;
&lt;br /&gt;
[[File:8x8e+error.png]] [[File:8x8m+error.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
A Python script has been written to generate a plot of &amp;lt;math&amp;gt;\left\langle E\right\rangle&amp;lt;/math&amp;gt; or &amp;lt;math&amp;gt;\left\langle M\right\rangle&amp;lt;/math&amp;gt; against temperature based upon user input. A screenshot of this code has been inserted below.&lt;br /&gt;
&lt;br /&gt;
[[File:ExpectedvsTemp.PNG|200px]]&lt;br /&gt;
&lt;br /&gt;
===Scaling the System Size===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====2x2====&lt;br /&gt;
[[File:2x2e+error.png]] [[File:2x2m+error.png]]&lt;br /&gt;
&lt;br /&gt;
====4x4====&lt;br /&gt;
[[File:4x4e+error.png]] [[File:4x4m+error.png]]&lt;br /&gt;
&lt;br /&gt;
====16x16====&lt;br /&gt;
[[File:16x16e+error.png]] [[File:16x16m+error.png]]&lt;br /&gt;
&lt;br /&gt;
====32x32====&lt;br /&gt;
[[File:32x32e+error.png]] [[File:32x32m+error.png]]&lt;br /&gt;
&lt;br /&gt;
====64x64====&lt;br /&gt;
[[File:64x64e+error.png]] [[File:64x64m+error.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Determining the Heat Capacity==&lt;br /&gt;
&lt;br /&gt;
===Calculating the Heat Capacity===&lt;br /&gt;
Working in the canonical ensemble (constant volume), the heat capacity &amp;lt;math&amp;gt; C_V &amp;lt;/math&amp;gt; is given by:&lt;br /&gt;
&lt;br /&gt;
:&amp;lt;math&amp;gt;C_V = \frac{\partial \left\langle E\right\rangle}{\partial T}_V&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
where &amp;lt;math&amp;gt;\left\langle E\right\rangle&amp;lt;/math&amp;gt; is the average total energy or expected value of the internal energy of the system.&lt;br /&gt;
&lt;br /&gt;
: &amp;lt;math&amp;gt; \left\langle E\right\rangle = - \frac{\partial ln Q}{\partial \beta} = -\frac{1}{Q}\frac{\partial Q}{\partial \beta} &amp;lt;/math&amp;gt;&lt;br /&gt;
where &amp;lt;math&amp;gt; Q&amp;lt;/math&amp;gt; is the partition function for the system of N interacting spins.&lt;br /&gt;
&lt;br /&gt;
By evaluating the second form of the partial derivative with respect to &amp;lt;math&amp;gt; \beta&amp;lt;/math&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \left\langle E\right\rangle = -\frac{1}{Q}\frac{\partial Q}{\partial \beta} = \frac{\Sigma \epsilon_{i} e^{-\beta \epsilon_{i}}}{\Sigma e^{-\beta \epsilon_{i}}} &amp;lt;/math&amp;gt; &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Applying the product rule enables the differentiation of this expression for &amp;lt;math&amp;gt;\left\langle E\right\rangle&amp;lt;/math&amp;gt; with respect to temperature, giving:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\frac{\partial \left\langle E\right\rangle}{\partial T} = \frac{\Sigma \epsilon_{i} \frac{\epsilon_i}{k_BT^2}e^{-\beta \epsilon_{i}}}{\Sigma e^{-\beta \epsilon_{i}}} - \frac{\Sigma \epsilon_i e^{-\beta \epsilon_i}\cdot \frac{\epsilon_i}{k_BT^2}e^{-\beta \epsilon_i}}{(\Sigma e^{-\beta \epsilon_{i}})^2}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\frac{\partial \left\langle E\right\rangle}{\partial T}  = \frac{1}{k_BT^2}\left[\frac{\Sigma \epsilon_i^2 e^{-\beta \epsilon_i}}{\Sigma e^{-\beta \epsilon_i}} - \left(\frac{\Sigma \epsilon_{i} e^{-\beta \epsilon_{i}}}{\Sigma e^{-\beta \epsilon_{i}}}\right)^2\right] &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\frac{\partial \left\langle E\right\rangle}{\partial T}  = \frac{1}{k_BT^2}\left[\left\langle E^2\right\rangle - \left\langle E\right\rangle^2 \right] &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Thus,&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\frac{\partial \left\langle E\right\rangle}{\partial T} = \frac{Var[E]}{k_BT^2} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Heat Capacity versus Temperature===&lt;br /&gt;
&lt;br /&gt;
====2x2====&lt;br /&gt;
[[File:HC2.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====4x4====&lt;br /&gt;
[[File:HC4.png]]&lt;br /&gt;
&lt;br /&gt;
====8x8====&lt;br /&gt;
[[File:HC8.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====16x16====&lt;br /&gt;
[[File:HC16.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====32x32====&lt;br /&gt;
[[File:HC32.png]]&lt;br /&gt;
&lt;br /&gt;
== Locating the Curie Temperature ==&lt;br /&gt;
&lt;br /&gt;
===C++ Data Comparison===&lt;br /&gt;
&lt;br /&gt;
[[File:CHC2.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Polyfitting of C++ Data===&lt;br /&gt;
&lt;br /&gt;
====Fitting a Polynomial to the Entire Range====&lt;br /&gt;
&lt;br /&gt;
[[File:15Polyc2x2.png]]&lt;br /&gt;
Polynomials with 5 terms and above were found to match the data in the vicinity of the critical region considerably well. Below 7 terms, the &#039;&#039;tails&#039;&#039; of the plot were matched poorly. In the above example, a polynomial of 15 terms was fit to the data.&lt;br /&gt;
&lt;br /&gt;
=== Python Scripts ===&lt;/div&gt;</summary>
		<author><name>Jj1516</name></author>
	</entry>
	<entry>
		<id>https://chemwiki.ch.ic.ac.uk/index.php?title=Rep:JJ1516Ising&amp;diff=736458</id>
		<title>Rep:JJ1516Ising</title>
		<link rel="alternate" type="text/html" href="https://chemwiki.ch.ic.ac.uk/index.php?title=Rep:JJ1516Ising&amp;diff=736458"/>
		<updated>2018-11-20T19:28:00Z</updated>

		<summary type="html">&lt;p&gt;Jj1516: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Ex Script Link:&lt;br /&gt;
https://wiki.ch.ic.ac.uk/wiki/index.php?title=Third_year_CMP_compulsory_experiment&lt;br /&gt;
&lt;br /&gt;
= Introduction to the Ising Model =&lt;br /&gt;
&lt;br /&gt;
== The Model ==&lt;br /&gt;
&lt;br /&gt;
=== Minimum Energy State ===&lt;br /&gt;
====Minimum Interaction Energy====&lt;br /&gt;
The interaction energy of an Ising lattice is given by:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;E = -\frac{1}{2}J\displaystyle\sum_{i}^{N} \displaystyle\sum_{j\;\in\;{neighbours}\;(i)} \!\!\!\!\!\!\!\!\!\!\!\!s_{i}s_{j}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In an Ising lattice with D dimensions and periodic boundary conditions, a given spin &amp;lt;math&amp;gt; s_i&amp;lt;/math&amp;gt; has 2D neighbours.&lt;br /&gt;
&lt;br /&gt;
The minimum interaction energy is achieved when all spins in the lattice are aligned (all ↑ or all ↓). As  such, any spin &amp;lt;math&amp;gt; s_i&amp;lt;/math&amp;gt; must be aligned with all 2D of its neighbours. That is, &amp;lt;math&amp;gt;s_{i}s_{j} = 1&amp;lt;/math&amp;gt; for all &amp;lt;math&amp;gt;j&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Therefore, for any &amp;lt;math&amp;gt; s_i&amp;lt;/math&amp;gt;, the sum of its interactions is &amp;lt;math&amp;gt;\displaystyle\sum_{j\;\in\;{neighbours}\;(i)} \!\!\!\!\!\!\!\!\!\!\!\!s_{i}s_{j} = 2D &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
As this is true for all N spins in the lattice, it follows that &amp;lt;math&amp;gt;\displaystyle\sum_{i}^{N} 2D = 2DN&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Thus the minimum interaction energy is given by:&lt;br /&gt;
&lt;br /&gt;
:&amp;lt;math&amp;gt;E_{min} = -\frac{1}{2}J\cdot2DN = - DNJ &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Entropy of the Minimum Energy State====&lt;br /&gt;
&lt;br /&gt;
The entropy of a state is given by:&lt;br /&gt;
&lt;br /&gt;
:&amp;lt;math&amp;gt;S = k\; ln\; \Omega &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Where &amp;lt;math&amp;gt; \Omega &amp;lt;/math&amp;gt; is the multiplicity of the state, the number of degenerate configurations of said state. The minimum energy state is achievable with all spins ↑ or with all spins ↓. In the absence of an external magnetic field, these configurations are degenerate and indistinguishable giving &amp;lt;math&amp;gt; \Omega = 2 &amp;lt;/math&amp;gt; for this state. Therefore,&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; S_{E_{min}}  = k_{B}\; ln\; 2 = 0.693k_{B} = 9.57 \times 10^{-24} J\!\cdot\!\! K^{-1}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Phase Transitions ==&lt;br /&gt;
&lt;br /&gt;
=== Changes to Minimum Energy Configuration ===&lt;br /&gt;
&lt;br /&gt;
====Energy Change ====&lt;br /&gt;
The energy change &amp;lt;math&amp;gt; \Delta E&amp;lt;/math&amp;gt; associated with a single spin &#039;flip&#039; from the lowest energy onfiguration may be calculated by considering the change in the interaction energy with the spin&#039;s neighbours.&lt;br /&gt;
&lt;br /&gt;
Let &amp;lt;math&amp;gt; D = 3, N = 1000 &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\Delta{E} = E_1 - E_0&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;E_1&amp;lt;/math&amp;gt; Interaction energy after one spin has been &#039;flipped&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;E_0&amp;lt;/math&amp;gt; Lowest energy configuration&lt;br /&gt;
&lt;br /&gt;
[[Image:Task 2 table.PNG]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\displaystyle\sum_{interactions} = -2D + 2D(2D-2) + 2D[N-(2D+1)] &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; = 2DN - 8D &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;E_1 = \displaystyle-\frac{1}{2}J\;\sum_{interactions} = 4DJ - DNJ&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\Delta{E} = E_1 - E_0 = 4DJ - DNJ + DNJ = +4DJ = +12J&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This energy change is independent of &amp;lt;math&amp;gt; N&amp;lt;/math&amp;gt; and depends only on the dimension size and the coupling constant &amp;lt;math&amp;gt; J &amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
In this calculation, the following assumption has been made.&lt;br /&gt;
&lt;br /&gt;
* The lattice dimensions are infinite relative to the size of each cell&lt;br /&gt;
&lt;br /&gt;
This allows &#039;&#039;&#039;any&#039;&#039;&#039; cell to be treated as the centre of the lattice. As every cell interacts with 2D neighbours, flipping any cell in the minimum energy configuration results in the same energy change. Alternatively, the periodic boundary conditions of the Ising model remove the necessity for such an assumption. As a consequence, the absence of &amp;lt;math&amp;gt; N &amp;lt;/math&amp;gt; from the resulting energy change is justified.&lt;br /&gt;
&lt;br /&gt;
====Entropy Change====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; S = k_{B}\; ln\; \Omega &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\Omega = \displaystyle\frac{N!}{{N_{\uparrow}!}{N_{\downarrow}!}}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Where &amp;lt;math&amp;gt;N_{x}!&amp;lt;/math&amp;gt; denotes the factorial of the number of spins in spin state &amp;lt;math&amp;gt;x&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\Delta{S} = k_{B}\;ln\;\left(\displaystyle\frac{\Omega_{2}}{\Omega_{1}}\right)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\Omega_{2} = \frac{1000!}{999!1!} = 1000&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \Omega_{1} = \frac{1000!}{1000!} = 1&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\Delta{S} = k_{B}\;ln\;1000 = 9.54 \times 10^{-23} JK^{-1}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\Delta{S_{mol}} = N_{A}k_{B}\;ln\;1000 = 57.4 \,JK^{-1}mol^{-1}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Magnetisation Values of 1D and 2D Lattices===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;M = \sum_i s_i&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====1D Lattice Magnetisation====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;M_{1D} =\;\;+1&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====2D Lattice Magnetisation====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;M_{2D} =\;\;+1&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Magnetisation at 0K====&lt;br /&gt;
&lt;br /&gt;
At 0K, no thermal energy is available to overcome the energetic barriers to spin flipping. Considering the Hemholtz free energy:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; A = E - TS &amp;lt;/math&amp;gt; &lt;br /&gt;
&lt;br /&gt;
A temperature of absolute 0 nullifies the entropic contribution arising from the multiplicity of the lattice state. Thus the energetic driving force (which maximises parallel spin interactions) dominates the entropic driving force (which maximises multiplicity). For an Ising Lattice with D =  3, N = 1000 at 0K, the alignment of all spins results in the minimum energy configuration  and an overall magnetisation of &amp;lt;math&amp;gt; M = \pm 1000 &amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
= Calculating the Energy and Magnetisation =&lt;br /&gt;
&lt;br /&gt;
[[File:First_Ene_Method.PNG]]&lt;br /&gt;
&lt;br /&gt;
[[File:First_Mag_Method.PNG]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:ILChecks.PNG]]&lt;br /&gt;
&lt;br /&gt;
= Introduction to the Monte Carlo Simulation =&lt;br /&gt;
===Configurations Available to a 100 Spin System===&lt;br /&gt;
For a system of two spins, 4 configurations are possible (↑↑, ↓↓, ↑↓, ↓↑) i.e. &amp;lt;math&amp;gt;2^{2}&amp;lt;/math&amp;gt;. For a system of 100 spins, &amp;lt;math&amp;gt;2^{100}&amp;lt;/math&amp;gt; configurations are expected. In the first example, the ↑↑ and ↓↓ are degenerate, as are the ↑↓ and ↓↑ configurations. Therefore, dividing the number of possible configurations by the multiplicity of each configuration (&amp;lt;math&amp;gt;2&amp;lt;/math&amp;gt;) gives the number of distinguishable configurations.&lt;br /&gt;
For 100 spins, this gives &amp;lt;math&amp;gt;\displaystyle\frac{2^{100}}{2} = 6.338 \times 10^{29} &amp;lt;/math&amp;gt; distinguishable configurations or states.&lt;br /&gt;
&lt;br /&gt;
If our computational speed allowed for &amp;lt;math&amp;gt; 1 \times 10^{9}&amp;lt;/math&amp;gt; calculations each second, the evaluation of a single value of &amp;lt;math&amp;gt;\left\langle M\right\rangle_T&amp;lt;/math&amp;gt; would last &amp;lt;math&amp;gt; 6.338 \times 10^{20} &amp;lt;/math&amp;gt; seconds or &amp;lt;math&amp;gt; 1458 &amp;lt;/math&amp;gt; times the age of the Universe!&lt;br /&gt;
&lt;br /&gt;
===Modifying IsingLattice.py===&lt;br /&gt;
&lt;br /&gt;
[[File:Monte_Carlo.PNG]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The Metropolis Monte Carlo (MMC) algorithm provides a computationally inexpensive path from random initial states to the minimum free energy states of the Ising lattices generated. First, a random 2D Ising lattice is generated. A single random spin within this lattice is &amp;quot;flipped&amp;quot; and the resulting energy change between these states is measured. If the energy change is negative, this represents a decrease in the internal energy of the system which lowers the free energy: this configuration change is accepted.&lt;br /&gt;
&lt;br /&gt;
In the case that the spin &amp;quot;flip&amp;quot; does not lower the free energy, the MMC algorithm tests this configuration change against the Boltzman factor, enabling a determination of the resulting entropy change. In the canonical (NVT) ensemble, the entropy of the system is given by&lt;br /&gt;
&lt;br /&gt;
###&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:stats.PNG]]&lt;br /&gt;
&lt;br /&gt;
===Spontaneous Magnetisation===&lt;br /&gt;
&lt;br /&gt;
Below the Curie Temperature, &amp;lt;math&amp;gt; T_{C} &amp;lt;/math&amp;gt;, energetic driving forces dominate entropic driving forces. Therefore, the spins of the system align in order to maximise favourable interactions rather than adopting a less ordered configuration, which would maximise multiplicity (and thus entropy).&lt;br /&gt;
Below &amp;lt;math&amp;gt;T &amp;lt; T_C&amp;lt;/math&amp;gt;, the most probable configurations have an overall magnetisation resulting in &amp;lt;math&amp;gt;\left\langle M\right\rangle \neq 0&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
The plots of magnetisation per spin and energy per spin obtained from ILanim.py upon system equilibration show that at minimum energy per spin &amp;lt;math&amp;gt;E_{min_{spin}} = \frac{-NDJ}{N} = -DJ = -2&amp;lt;/math&amp;gt;, the magnitude of the overall magnetisation per spin is at a maximum &amp;lt;math&amp;gt;|M_{spin}| = 1&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:2T=1.0.png]]&lt;br /&gt;
[[File:T=1.0.png]]&lt;br /&gt;
[[File:3T=1.0.png]]&lt;br /&gt;
&lt;br /&gt;
==Accelerating the Code==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Initial Method Speeds===&lt;br /&gt;
Taking 10 repeat measurements for the time taken to perform 2000 Monte Carlo steps resulted in&lt;br /&gt;
&lt;br /&gt;
* An average time of  &amp;lt;math&amp;gt;11.7s&amp;lt;/math&amp;gt; &lt;br /&gt;
* A standard error of &amp;lt;math&amp;gt;0.020s&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Updating Measurement===&lt;br /&gt;
&lt;br /&gt;
NOTE: ILtimetrial.py has been modified to:&lt;br /&gt;
* Perform a requested number of &#039;2000 Monte Carlo Step&#039; measurements&lt;br /&gt;
* Record these measurements in a CSV file&lt;br /&gt;
* Return the mean measuremd time and the Standard Error i.e.   &amp;lt;math&amp;gt; \frac{\sigma}{n} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:TimeTrialMethod.PNG]]&lt;br /&gt;
&lt;br /&gt;
===Updating Energy and Magnetisation Methods===&lt;br /&gt;
[[File:New_Mag_Method.PNG]]&lt;br /&gt;
[[File:New_Ene_Method.PNG]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Updated Method Speeds===&lt;br /&gt;
[[File:TimeTrial.PNG]]&lt;br /&gt;
&lt;br /&gt;
Taking 30 measurements of the time taken to perform 2000 Monte Carlo Steps resulted in:&lt;br /&gt;
&lt;br /&gt;
* An average time of &amp;lt;math&amp;gt;\displaystyle{0.87s}&amp;lt;/math&amp;gt;&lt;br /&gt;
* A standard error of &amp;lt;math&amp;gt;2.5 \times 10^{-3}s&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This represents a &#039;&#039;&#039;INSERT&#039;&#039;&#039;% decrease in computation time from the initial methods.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==The Effect of Temperature==&lt;br /&gt;
&lt;br /&gt;
===Correcting the Averaging  Code===&lt;br /&gt;
&lt;br /&gt;
To quickly find a value for &amp;lt;math&amp;gt; N_{d}&amp;lt;/math&amp;gt;, the minimum number of cycles typically needed for the equilibration of a system of within the lattice and temperature ranges of interest, it was assumed that:&lt;br /&gt;
&lt;br /&gt;
* Larger lattices would require more Monte Carlo steps to reach equilibrium from their initial, random configurations&lt;br /&gt;
&lt;br /&gt;
* Lattices at lower temperatures would require more Monte Carlo steps to reach equilibrium from their initial, random configurations.&lt;br /&gt;
&lt;br /&gt;
Therefore, an initial value for &amp;lt;math&amp;gt; N_{d}&amp;lt;/math&amp;gt; was found for a &amp;lt;math&amp;gt; 128\times128 &amp;lt;/math&amp;gt; lattice at a temperature of &amp;lt;math&amp;gt;0.5&amp;lt;/math&amp;gt; reduced temperature units.&lt;br /&gt;
*&amp;lt;math&amp;gt; N_{d} = 185000 &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
By this number of steps, all smaller lattices at all higher temperatures were found to have equilibrated also. Thus, this value of&amp;lt;math&amp;gt; N_{d}&amp;lt;/math&amp;gt; was accepted as an appropriate delay.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:AFinFrame 128 3e5 T= 0.5line.png|400px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
For the 128x128 lattices at T=0.5, equilibration was ensured from 185000 steps onwards.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Smaller lattices at the same temperature did indeed equilibrate more slowly, but all equilibrated within &amp;lt;math&amp;gt; N_{d}&amp;lt;/math&amp;gt; MC steps.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:AFinFrame 64 3e5 T= 0.5line.png|400px]]&lt;br /&gt;
[[File:AFinFrame 32 3e5 T= 0.5line2.png|400px]]&lt;br /&gt;
[[File:AFinFrame 16 3e5 T= 0.5line2.png|400px]]&lt;br /&gt;
[[File:AFinFrame 8 3e5 T= 0.5line.png|400px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The figure below shows the modifications made to IsingLattice.py to incorporate the &amp;lt;math&amp;gt; N_{d} &amp;lt;/math&amp;gt; step delay.&lt;br /&gt;
&lt;br /&gt;
===Running over a Range of Temperatures===&lt;br /&gt;
&lt;br /&gt;
To examine the effect of temperature on the average energy &amp;lt;math&amp;gt; \left\langle E\right\rangle &amp;lt;/math&amp;gt; and average magnetisation &amp;lt;math&amp;gt; \left\langle M\right\rangle &amp;lt;/math&amp;gt; of Ising lattices at equilibrium, the following parameters were used:&lt;br /&gt;
&lt;br /&gt;
* Temperature Range: &amp;lt;math&amp;gt;  0.5 - 5 &amp;lt;/math&amp;gt; reduced units&lt;br /&gt;
* Temperature Interval: &amp;lt;math&amp;gt;0.01&amp;lt;/math&amp;gt; reduced units (&amp;lt;math&amp;gt;450&amp;lt;/math&amp;gt; temperature values)&lt;br /&gt;
* Number of MMC Steps per Temperature value: &amp;lt;math&amp;gt; 2 \times 10^5 &amp;lt;/math&amp;gt; with the aforementioned value of &amp;lt;math&amp;gt; N_{d} = 1.85 \times 10^5 &amp;lt;/math&amp;gt; Monte Carlo steps&lt;br /&gt;
* Lattice Sizes:  &amp;lt;math&amp;gt; 2 \times 2 &amp;lt;/math&amp;gt;, &amp;lt;math&amp;gt; 4 \times 4 &amp;lt;/math&amp;gt; , &amp;lt;math&amp;gt; 8 \times 8 &amp;lt;/math&amp;gt; , &amp;lt;math&amp;gt; 16 \times 16 &amp;lt;/math&amp;gt; , &amp;lt;math&amp;gt; 32 \times 32 &amp;lt;/math&amp;gt; , &amp;lt;math&amp;gt; 64 \times 64 &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Plots of  &amp;lt;math&amp;gt; \left\langle E\right\rangle &amp;lt;/math&amp;gt; and  &amp;lt;math&amp;gt; \left\langle M\right\rangle &amp;lt;/math&amp;gt; per spin as versus temperature are presented below for each lattice size. Errorbars have been implemented to demonstrate how &#039;&#039;well-behaved&#039;&#039; lattice systems of each size are at each temperature, that is, how temperature and lattice size affect the size of the variations in the expected values. For the error calculations, the standard errors, &amp;lt;math&amp;gt; \sigma_\bar{X} &amp;lt;/math&amp;gt;,  in &amp;lt;math&amp;gt; \left\langle E\right\rangle &amp;lt;/math&amp;gt; and  &amp;lt;math&amp;gt; \left\langle M\right\rangle &amp;lt;/math&amp;gt; per spin have been used:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====8x8====&lt;br /&gt;
&lt;br /&gt;
[[File:8x8e+error.png]] [[File:8x8m+error.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
A Python script has been written to generate a plot of &amp;lt;math&amp;gt;\left\langle E\right\rangle&amp;lt;/math&amp;gt; or &amp;lt;math&amp;gt;\left\langle M\right\rangle&amp;lt;/math&amp;gt; against temperature based upon user input. A screenshot of this code has been inserted below.&lt;br /&gt;
&lt;br /&gt;
[[File:ExpectedvsTemp.PNG|200px]]&lt;br /&gt;
&lt;br /&gt;
===Scaling the System Size===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====2x2====&lt;br /&gt;
[[File:2x2e+error.png]] [[File:2x2m+error.png]]&lt;br /&gt;
&lt;br /&gt;
====4x4====&lt;br /&gt;
[[File:4x4e+error.png]] [[File:4x4m+error.png]]&lt;br /&gt;
&lt;br /&gt;
====16x16====&lt;br /&gt;
[[File:16x16e+error.png]] [[File:16x16m+error.png]]&lt;br /&gt;
&lt;br /&gt;
====32x32====&lt;br /&gt;
[[File:32x32e+error.png]] [[File:32x32m+error.png]]&lt;br /&gt;
&lt;br /&gt;
====64x64====&lt;br /&gt;
[[File:64x64e+error.png]] [[File:64x64m+error.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Determining the Heat Capacity==&lt;br /&gt;
&lt;br /&gt;
===Calculating the Heat Capacity===&lt;br /&gt;
Working in the canonical ensemble (constant volume), the heat capacity &amp;lt;math&amp;gt; C_V &amp;lt;/math&amp;gt; is given by:&lt;br /&gt;
&lt;br /&gt;
:&amp;lt;math&amp;gt;C_V = \frac{\partial \left\langle E\right\rangle}{\partial T}_V&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
where &amp;lt;math&amp;gt;\left\langle E\right\rangle&amp;lt;/math&amp;gt; is the average total energy or expected value of the internal energy of the system.&lt;br /&gt;
&lt;br /&gt;
: &amp;lt;math&amp;gt; \left\langle E\right\rangle = - \frac{\partial ln Q}{\partial \beta} = -\frac{1}{Q}\frac{\partial Q}{\partial \beta} &amp;lt;/math&amp;gt;&lt;br /&gt;
where &amp;lt;math&amp;gt; Q&amp;lt;/math&amp;gt; is the partition function for the system of N interacting spins.&lt;br /&gt;
&lt;br /&gt;
By evaluating the second form of the partial derivative with respect to &amp;lt;math&amp;gt; \beta&amp;lt;/math&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \left\langle E\right\rangle = -\frac{1}{Q}\frac{\partial Q}{\partial \beta} = \frac{\Sigma \epsilon_{i} e^{-\beta \epsilon_{i}}}{\Sigma e^{-\beta \epsilon_{i}}} &amp;lt;/math&amp;gt; &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Applying the product rule enables the differentiation of this expression for &amp;lt;math&amp;gt;\left\langle E\right\rangle&amp;lt;/math&amp;gt; with respect to temperature, giving:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\frac{\partial \left\langle E\right\rangle}{\partial T} = \frac{\Sigma \epsilon_{i} \frac{\epsilon_i}{k_BT^2}e^{-\beta \epsilon_{i}}}{\Sigma e^{-\beta \epsilon_{i}}} - \frac{\Sigma \epsilon_i e^{-\beta \epsilon_i}\cdot \frac{\epsilon_i}{k_BT^2}e^{-\beta \epsilon_i}}{(\Sigma e^{-\beta \epsilon_{i}})^2}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\frac{\partial \left\langle E\right\rangle}{\partial T}  = \frac{1}{k_BT^2}\left[\frac{\Sigma \epsilon_i^2 e^{-\beta \epsilon_i}}{\Sigma e^{-\beta \epsilon_i}} - \left(\frac{\Sigma \epsilon_{i} e^{-\beta \epsilon_{i}}}{\Sigma e^{-\beta \epsilon_{i}}}\right)^2\right] &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\frac{\partial \left\langle E\right\rangle}{\partial T}  = \frac{1}{k_BT^2}\left[\left\langle E^2\right\rangle - \left\langle E\right\rangle^2 \right] &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Thus,&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\frac{\partial \left\langle E\right\rangle}{\partial T} = \frac{Var[E]}{k_BT^2} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Heat Capacity versus Temperature===&lt;br /&gt;
&lt;br /&gt;
====2x2====&lt;br /&gt;
[[File:HC2.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====4x4====&lt;br /&gt;
[[File:HC4.png]]&lt;br /&gt;
&lt;br /&gt;
====8x8====&lt;br /&gt;
[[File:HC8.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====16x16====&lt;br /&gt;
[[File:HC16.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====32x32====&lt;br /&gt;
[[File:HC32.png]]&lt;br /&gt;
&lt;br /&gt;
== Locating the Curie Temperature ==&lt;br /&gt;
&lt;br /&gt;
===C++ Data Comparison===&lt;br /&gt;
&lt;br /&gt;
[[File:CHC2.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Polyfitting of C++ Data===&lt;br /&gt;
&lt;br /&gt;
====Fitting a Polynomial to the Entire Range====&lt;br /&gt;
&lt;br /&gt;
[[File:15Polyc2x2.png]]&lt;br /&gt;
Polynomials with 5 terms and above were found to match the data in the vicinity of the critical region considerably well. Below 7 terms, the &#039;&#039;tails&#039;&#039; of the plot were matched poorly. In the above example, a polynomial of 15 terms was fit to the data.&lt;br /&gt;
&lt;br /&gt;
=== Python Scripts ===&lt;/div&gt;</summary>
		<author><name>Jj1516</name></author>
	</entry>
	<entry>
		<id>https://chemwiki.ch.ic.ac.uk/index.php?title=Rep:JJ1516Ising&amp;diff=736448</id>
		<title>Rep:JJ1516Ising</title>
		<link rel="alternate" type="text/html" href="https://chemwiki.ch.ic.ac.uk/index.php?title=Rep:JJ1516Ising&amp;diff=736448"/>
		<updated>2018-11-20T19:08:41Z</updated>

		<summary type="html">&lt;p&gt;Jj1516: /* Calculating energy and entropy changes */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Ex Script Link:&lt;br /&gt;
https://wiki.ch.ic.ac.uk/wiki/index.php?title=Third_year_CMP_compulsory_experiment&lt;br /&gt;
&lt;br /&gt;
= Introduction to the Ising Model =&lt;br /&gt;
&lt;br /&gt;
== Calculating the minimum energy and entropy ==&lt;br /&gt;
The interaction energy of an Ising lattice is given by:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;E = -\frac{1}{2}J\displaystyle\sum_{i}^{N} \displaystyle\sum_{j\;\in\;{neighbours}\;(i)} \!\!\!\!\!\!\!\!\!\!\!\!s_{i}s_{j}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In an Ising lattice with D dimensions and periodic boundary conditions, a given spin &amp;lt;math&amp;gt; s_i&amp;lt;/math&amp;gt; has 2D neighbours.&lt;br /&gt;
&lt;br /&gt;
The minimum interaction energy is achieved when all spins in the lattice are aligned (all ↑ or all ↓). As  such, any spin &amp;lt;math&amp;gt; s_i&amp;lt;/math&amp;gt; must be aligned with all 2D of its neighbours. That is, &amp;lt;math&amp;gt;s_{i}s_{j} = 1&amp;lt;/math&amp;gt; for all &amp;lt;math&amp;gt;j&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Therefore, for any &amp;lt;math&amp;gt; s_i&amp;lt;/math&amp;gt;, the sum of its interactions is &amp;lt;math&amp;gt;\displaystyle\sum_{j\;\in\;{neighbours}\;(i)} \!\!\!\!\!\!\!\!\!\!\!\!s_{i}s_{j} = 2D &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
As this is true for all N spins in the lattice, it follows that &amp;lt;math&amp;gt;\displaystyle\sum_{i}^{N} 2D = 2DN&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Thus the minimum interaction energy is given by:&lt;br /&gt;
&lt;br /&gt;
:&amp;lt;math&amp;gt;E_{min} = -\frac{1}{2}J\cdot2DN = - DNJ &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The entropy of a given lattice state is given by:&lt;br /&gt;
&lt;br /&gt;
:&amp;lt;math&amp;gt;S = k\; ln\; \Omega &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Where &amp;lt;math&amp;gt; \Omega &amp;lt;/math&amp;gt; is the multiplicity of the state, the number of degenerate configurations of said state. The minimum energy state is achievable with all spins ↑ or by having all spins ↓. In the absence of an external magnetic field, these configurations are degenerate and indistinguishable giving &amp;lt;math&amp;gt; \Omega = 2 &amp;lt;/math&amp;gt; for this state. Therefore,&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; S_{E_{min}}  = k_{B}\; ln\; 2 = 0.693k_{B} = 9.57 \times 10^{-24} J\!\cdot\!\! K^{-1}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Calculating energy and entropy changes ==&lt;br /&gt;
====&lt;br /&gt;
&#039;&#039;&#039;What is the energy change from the lowest energy configuration when a single spin &amp;quot;flips&amp;quot;? What is the entropy change? (&amp;lt;math&amp;gt; D = 3, N = 1000 &amp;lt;/math&amp;gt;)&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\Delta{E} = E_1 - E_0&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;E_1&amp;lt;/math&amp;gt; One lattice cell spin flipped&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;E_0&amp;lt;/math&amp;gt; Lowest energy configuration&lt;br /&gt;
&lt;br /&gt;
[[Image:Task 2 table.PNG]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\displaystyle\sum_{interactions} = -2D + 2D(2D-2) + 2D[N-(2D+1)] &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; = 2DN - 8D &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;E_1 = \displaystyle-\frac{1}{2}J\;\sum_{interactions} = 4DJ - DNJ&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\Delta{E} = E_1 - E_0 = 4DJ - DNJ + DNJ = +4DJ = +12J&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This energy change is independent of &amp;lt;math&amp;gt; N&amp;lt;/math&amp;gt; and depends only on the dimension size.&lt;br /&gt;
&lt;br /&gt;
In this calculation, the following assumption has been made.&lt;br /&gt;
&lt;br /&gt;
* The lattice dimensions are infinite relative to the size of each cell&lt;br /&gt;
&lt;br /&gt;
This allows &#039;&#039;&#039;any&#039;&#039;&#039; cell to be treated as the centre of the lattice. As every cell interacts with 2D neighbours, flipping any cell in the minimum energy configuration results in the same energy change. Alternatively, the periodic boundary conditions of the Ising model remove the necessity for such an assumption. As a consequence, the absence of &amp;lt;math&amp;gt; N &amp;lt;/math&amp;gt; from the resulting energy change is justified.&lt;br /&gt;
&lt;br /&gt;
Entropy Change&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; S = k_{B}\; ln\; \Omega &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\Omega = \displaystyle\frac{N!}{{N_{\uparrow}!}{N_{\downarrow}!}}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Where &amp;lt;math&amp;gt;N_{i}!&amp;lt;/math&amp;gt; denotes the factorial of the number of spins in spin state &amp;lt;math&amp;gt;i&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\Delta{S} = k_{B}\;ln\;\left(\displaystyle\frac{\Omega_{2}}{\Omega_{1}}\right)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\Omega_{2} = \frac{1000!}{999!1!} = 1000&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \Omega_{1} = \frac{1000!}{1000!} = 1&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\Delta{S} = k_{B}\;ln\;1000 = 9.54 \times 10^{-23} JK^{-1}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\Delta{S_{mol}} = N_{A}k_{B}\;ln\;1000 = 57.4 \,JK^{-1}mol^{-1}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Magnetisation Values of 1D and 2D Lattices===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;M_{1D} =\;\;+1&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;M_{2D} =\;\;+1&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
At 0K, no thermal energy is available to overcome the energetic barriers to spin flipping. Thus the energetic driving forces dominates the entropic driving force; for an Ising Lattice with D =  3, N = 1000 at 0K, the lowest energy configuration is achieved when all spins are parallel. This resutls in the maximum number of coupling interactions between spins.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;M_{expected} =  1000&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Calculating the Energy and Magnetisation =&lt;br /&gt;
&lt;br /&gt;
[[File:First_Ene_Method.PNG]]&lt;br /&gt;
&lt;br /&gt;
[[File:First_Mag_Method.PNG]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:ILChecks.PNG]]&lt;br /&gt;
&lt;br /&gt;
= Introduction to the Monte Carlo Simulation =&lt;br /&gt;
===Configurations Available to a 100 Spin System===&lt;br /&gt;
For a system of two spins, 4 configurations are possible (↑↑, ↓↓, ↑↓, ↓↑) i.e. &amp;lt;math&amp;gt;2^{2}&amp;lt;/math&amp;gt;. For a system of 100 spins, &amp;lt;math&amp;gt;2^{100}&amp;lt;/math&amp;gt; configurations are expected. In the first example, the ↑↑ and ↓↓ are degenerate, as are the ↑↓ and ↓↑ configurations. Therefore, dividing the number of possible configurations by the multiplicity of each configuration (&amp;lt;math&amp;gt;2&amp;lt;/math&amp;gt;) gives the number of distinguishable configurations.&lt;br /&gt;
For 100 spins, this gives &amp;lt;math&amp;gt;\displaystyle\frac{2^{100}}{2} = 6.338 \times 10^{29} &amp;lt;/math&amp;gt; distinguishable configurations or states.&lt;br /&gt;
&lt;br /&gt;
If our computational speed allowed for &amp;lt;math&amp;gt; 1 \times 10^{9}&amp;lt;/math&amp;gt; calculations each second, the evaluation of a single value of &amp;lt;math&amp;gt;\left\langle M\right\rangle_T&amp;lt;/math&amp;gt; would last &amp;lt;math&amp;gt; 6.338 \times 10^{20} &amp;lt;/math&amp;gt; seconds or &amp;lt;math&amp;gt; 1458 &amp;lt;/math&amp;gt; times the age of the Universe!&lt;br /&gt;
&lt;br /&gt;
===Modifying IsingLattice.py===&lt;br /&gt;
&lt;br /&gt;
[[File:Monte_Carlo.PNG]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The Metropolis Monte Carlo (MMC) algorithm provides a computationally inexpensive path from random initial states to the minimum free energy states of the Ising lattices generated. First, a random 2D Ising lattice is generated. A single random spin within this lattice is &amp;quot;flipped&amp;quot; and the resulting energy change between these states is measured. If the energy change is negative, this represents a decrease in the internal energy of the system which lowers the free energy: this configuration change is accepted.&lt;br /&gt;
&lt;br /&gt;
In the case that the spin &amp;quot;flip&amp;quot; does not lower the free energy, the MMC algorithm tests this configuration change against the Boltzman factor, enabling a determination of the resulting entropy change. In the canonical (NVT) ensemble, the entropy of the system is given by&lt;br /&gt;
&lt;br /&gt;
###&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:stats.PNG]]&lt;br /&gt;
&lt;br /&gt;
===Spontaneous Magnetisation===&lt;br /&gt;
&lt;br /&gt;
Below the Curie Temperature, &amp;lt;math&amp;gt; T_{C} &amp;lt;/math&amp;gt;, energetic driving forces dominate entropic driving forces. Therefore, the spins of the system align in order to maximise favourable interactions rather than adopting a less ordered configuration, which would maximise multiplicity (and thus entropy).&lt;br /&gt;
Below &amp;lt;math&amp;gt;T &amp;lt; T_C&amp;lt;/math&amp;gt;, the most probable configurations have an overall magnetisation resulting in &amp;lt;math&amp;gt;\left\langle M\right\rangle \neq 0&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
The plots of magnetisation per spin and energy per spin obtained from ILanim.py upon system equilibration show that at minimum energy per spin &amp;lt;math&amp;gt;E_{min_{spin}} = \frac{-NDJ}{N} = -DJ = -2&amp;lt;/math&amp;gt;, the magnitude of the overall magnetisation per spin is at a maximum &amp;lt;math&amp;gt;|M_{spin}| = 1&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:2T=1.0.png]]&lt;br /&gt;
[[File:T=1.0.png]]&lt;br /&gt;
[[File:3T=1.0.png]]&lt;br /&gt;
&lt;br /&gt;
==Accelerating the Code==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Initial Method Speeds===&lt;br /&gt;
Taking 10 repeat measurements for the time taken to perform 2000 Monte Carlo steps resulted in&lt;br /&gt;
&lt;br /&gt;
* An average time of  &amp;lt;math&amp;gt;11.7s&amp;lt;/math&amp;gt; &lt;br /&gt;
* A standard error of &amp;lt;math&amp;gt;0.020s&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Updating Measurement===&lt;br /&gt;
&lt;br /&gt;
NOTE: ILtimetrial.py has been modified to:&lt;br /&gt;
* Perform a requested number of &#039;2000 Monte Carlo Step&#039; measurements&lt;br /&gt;
* Record these measurements in a CSV file&lt;br /&gt;
* Return the mean measuremd time and the Standard Error i.e.   &amp;lt;math&amp;gt; \frac{\sigma}{n} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:TimeTrialMethod.PNG]]&lt;br /&gt;
&lt;br /&gt;
===Updating Energy and Magnetisation Methods===&lt;br /&gt;
[[File:New_Mag_Method.PNG]]&lt;br /&gt;
[[File:New_Ene_Method.PNG]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Updated Method Speeds===&lt;br /&gt;
[[File:TimeTrial.PNG]]&lt;br /&gt;
&lt;br /&gt;
Taking 30 measurements of the time taken to perform 2000 Monte Carlo Steps resulted in:&lt;br /&gt;
&lt;br /&gt;
* An average time of &amp;lt;math&amp;gt;\displaystyle{0.87s}&amp;lt;/math&amp;gt;&lt;br /&gt;
* A standard error of &amp;lt;math&amp;gt;2.5 \times 10^{-3}s&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This represents a &#039;&#039;&#039;INSERT&#039;&#039;&#039;% decrease in computation time from the initial methods.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==The Effect of Temperature==&lt;br /&gt;
&lt;br /&gt;
===Correcting the Averaging  Code===&lt;br /&gt;
&lt;br /&gt;
To quickly find a value for &amp;lt;math&amp;gt; N_{d}&amp;lt;/math&amp;gt;, the minimum number of cycles typically needed for the equilibration of a system of within the lattice and temperature ranges of interest, it was assumed that:&lt;br /&gt;
&lt;br /&gt;
* Larger lattices would require more Monte Carlo steps to reach equilibrium from their initial, random configurations&lt;br /&gt;
&lt;br /&gt;
* Lattices at lower temperatures would require more Monte Carlo steps to reach equilibrium from their initial, random configurations.&lt;br /&gt;
&lt;br /&gt;
Therefore, an initial value for &amp;lt;math&amp;gt; N_{d}&amp;lt;/math&amp;gt; was found for a &amp;lt;math&amp;gt; 128\times128 &amp;lt;/math&amp;gt; lattice at a temperature of &amp;lt;math&amp;gt;0.5&amp;lt;/math&amp;gt; reduced temperature units.&lt;br /&gt;
*&amp;lt;math&amp;gt; N_{d} = 185000 &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
By this number of steps, all smaller lattices at all higher temperatures were found to have equilibrated also. Thus, this value of&amp;lt;math&amp;gt; N_{d}&amp;lt;/math&amp;gt; was accepted as an appropriate delay.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:AFinFrame 128 3e5 T= 0.5line.png|400px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
For the 128x128 lattices at T=0.5, equilibration was ensured from 185000 steps onwards.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Smaller lattices at the same temperature did indeed equilibrate more slowly, but all equilibrated within &amp;lt;math&amp;gt; N_{d}&amp;lt;/math&amp;gt; MC steps.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:AFinFrame 64 3e5 T= 0.5line.png|400px]]&lt;br /&gt;
[[File:AFinFrame 32 3e5 T= 0.5line2.png|400px]]&lt;br /&gt;
[[File:AFinFrame 16 3e5 T= 0.5line2.png|400px]]&lt;br /&gt;
[[File:AFinFrame 8 3e5 T= 0.5line.png|400px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The figure below shows the modifications made to IsingLattice.py to incorporate the &amp;lt;math&amp;gt; N_{d} &amp;lt;/math&amp;gt; step delay.&lt;br /&gt;
&lt;br /&gt;
===Running over a Range of Temperatures===&lt;br /&gt;
&lt;br /&gt;
To examine the effect of temperature on the average energy &amp;lt;math&amp;gt; \left\langle E\right\rangle &amp;lt;/math&amp;gt; and average magnetisation &amp;lt;math&amp;gt; \left\langle M\right\rangle &amp;lt;/math&amp;gt; of Ising lattices at equilibrium, the following parameters were used:&lt;br /&gt;
&lt;br /&gt;
* Temperature Range: &amp;lt;math&amp;gt;  0.5 - 5 &amp;lt;/math&amp;gt; reduced units&lt;br /&gt;
* Temperature Interval: &amp;lt;math&amp;gt;0.01&amp;lt;/math&amp;gt; reduced units (&amp;lt;math&amp;gt;450&amp;lt;/math&amp;gt; temperature values)&lt;br /&gt;
* Number of MMC Steps per Temperature value: &amp;lt;math&amp;gt; 2 \times 10^5 &amp;lt;/math&amp;gt; with the aforementioned value of &amp;lt;math&amp;gt; N_{d} = 1.85 \times 10^5 &amp;lt;/math&amp;gt; Monte Carlo steps&lt;br /&gt;
* Lattice Sizes:  &amp;lt;math&amp;gt; 2 \times 2 &amp;lt;/math&amp;gt;, &amp;lt;math&amp;gt; 4 \times 4 &amp;lt;/math&amp;gt; , &amp;lt;math&amp;gt; 8 \times 8 &amp;lt;/math&amp;gt; , &amp;lt;math&amp;gt; 16 \times 16 &amp;lt;/math&amp;gt; , &amp;lt;math&amp;gt; 32 \times 32 &amp;lt;/math&amp;gt; , &amp;lt;math&amp;gt; 64 \times 64 &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Plots of  &amp;lt;math&amp;gt; \left\langle E\right\rangle &amp;lt;/math&amp;gt; and  &amp;lt;math&amp;gt; \left\langle M\right\rangle &amp;lt;/math&amp;gt; per spin as versus temperature are presented below for each lattice size. Errorbars have been implemented to demonstrate how &#039;&#039;well-behaved&#039;&#039; lattice systems of each size are at each temperature, that is, how temperature and lattice size affect the size of the variations in the expected values. For the error calculations, the standard errors, &amp;lt;math&amp;gt; \sigma_\bar{X} &amp;lt;/math&amp;gt;,  in &amp;lt;math&amp;gt; \left\langle E\right\rangle &amp;lt;/math&amp;gt; and  &amp;lt;math&amp;gt; \left\langle M\right\rangle &amp;lt;/math&amp;gt; per spin have been used:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====8x8====&lt;br /&gt;
&lt;br /&gt;
[[File:8x8e+error.png]] [[File:8x8m+error.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
A Python script has been written to generate a plot of &amp;lt;math&amp;gt;\left\langle E\right\rangle&amp;lt;/math&amp;gt; or &amp;lt;math&amp;gt;\left\langle M\right\rangle&amp;lt;/math&amp;gt; against temperature based upon user input. A screenshot of this code has been inserted below.&lt;br /&gt;
&lt;br /&gt;
[[File:ExpectedvsTemp.PNG|200px]]&lt;br /&gt;
&lt;br /&gt;
===Scaling the System Size===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====2x2====&lt;br /&gt;
[[File:2x2e+error.png]] [[File:2x2m+error.png]]&lt;br /&gt;
&lt;br /&gt;
====4x4====&lt;br /&gt;
[[File:4x4e+error.png]] [[File:4x4m+error.png]]&lt;br /&gt;
&lt;br /&gt;
====16x16====&lt;br /&gt;
[[File:16x16e+error.png]] [[File:16x16m+error.png]]&lt;br /&gt;
&lt;br /&gt;
====32x32====&lt;br /&gt;
[[File:32x32e+error.png]] [[File:32x32m+error.png]]&lt;br /&gt;
&lt;br /&gt;
====64x64====&lt;br /&gt;
[[File:64x64e+error.png]] [[File:64x64m+error.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Determining the Heat Capacity==&lt;br /&gt;
&lt;br /&gt;
===Calculating the Heat Capacity===&lt;br /&gt;
Working in the canonical ensemble (constant volume), the heat capacity &amp;lt;math&amp;gt; C_V &amp;lt;/math&amp;gt; is given by:&lt;br /&gt;
&lt;br /&gt;
:&amp;lt;math&amp;gt;C_V = \frac{\partial \left\langle E\right\rangle}{\partial T}_V&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
where &amp;lt;math&amp;gt;\left\langle E\right\rangle&amp;lt;/math&amp;gt; is the average total energy or expected value of the internal energy of the system.&lt;br /&gt;
&lt;br /&gt;
: &amp;lt;math&amp;gt; \left\langle E\right\rangle = - \frac{\partial ln Q}{\partial \beta} = -\frac{1}{Q}\frac{\partial Q}{\partial \beta} &amp;lt;/math&amp;gt;&lt;br /&gt;
where &amp;lt;math&amp;gt; Q&amp;lt;/math&amp;gt; is the partition function for the system of N interacting spins.&lt;br /&gt;
&lt;br /&gt;
By evaluating the second form of the partial derivative with respect to &amp;lt;math&amp;gt; \beta&amp;lt;/math&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \left\langle E\right\rangle = -\frac{1}{Q}\frac{\partial Q}{\partial \beta} = \frac{\Sigma \epsilon_{i} e^{-\beta \epsilon_{i}}}{\Sigma e^{-\beta \epsilon_{i}}} &amp;lt;/math&amp;gt; &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Applying the product rule enables the differentiation of this expression for &amp;lt;math&amp;gt;\left\langle E\right\rangle&amp;lt;/math&amp;gt; with respect to temperature, giving:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\frac{\partial \left\langle E\right\rangle}{\partial T} = \frac{\Sigma \epsilon_{i} \frac{\epsilon_i}{k_BT^2}e^{-\beta \epsilon_{i}}}{\Sigma e^{-\beta \epsilon_{i}}} - \frac{\Sigma \epsilon_i e^{-\beta \epsilon_i}\cdot \frac{\epsilon_i}{k_BT^2}e^{-\beta \epsilon_i}}{(\Sigma e^{-\beta \epsilon_{i}})^2}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\frac{\partial \left\langle E\right\rangle}{\partial T}  = \frac{1}{k_BT^2}\left[\frac{\Sigma \epsilon_i^2 e^{-\beta \epsilon_i}}{\Sigma e^{-\beta \epsilon_i}} - \left(\frac{\Sigma \epsilon_{i} e^{-\beta \epsilon_{i}}}{\Sigma e^{-\beta \epsilon_{i}}}\right)^2\right] &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\frac{\partial \left\langle E\right\rangle}{\partial T}  = \frac{1}{k_BT^2}\left[\left\langle E^2\right\rangle - \left\langle E\right\rangle^2 \right] &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Thus,&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\frac{\partial \left\langle E\right\rangle}{\partial T} = \frac{Var[E]}{k_BT^2} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Heat Capacity versus Temperature===&lt;br /&gt;
&lt;br /&gt;
====2x2====&lt;br /&gt;
[[File:HC2.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====4x4====&lt;br /&gt;
[[File:HC4.png]]&lt;br /&gt;
&lt;br /&gt;
====8x8====&lt;br /&gt;
[[File:HC8.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====16x16====&lt;br /&gt;
[[File:HC16.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====32x32====&lt;br /&gt;
[[File:HC32.png]]&lt;br /&gt;
&lt;br /&gt;
== Locating the Curie Temperature ==&lt;br /&gt;
&lt;br /&gt;
===C++ Data Comparison===&lt;br /&gt;
&lt;br /&gt;
[[File:CHC2.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Polyfitting of C++ Data===&lt;br /&gt;
&lt;br /&gt;
====Fitting a Polynomial to the Entire Range====&lt;br /&gt;
&lt;br /&gt;
[[File:15Polyc2x2.png]]&lt;br /&gt;
Polynomials with 5 terms and above were found to match the data in the vicinity of the critical region considerably well. Below 7 terms, the &#039;&#039;tails&#039;&#039; of the plot were matched poorly. In the above example, a polynomial of 15 terms was fit to the data.&lt;br /&gt;
&lt;br /&gt;
=== Python Scripts ===&lt;/div&gt;</summary>
		<author><name>Jj1516</name></author>
	</entry>
	<entry>
		<id>https://chemwiki.ch.ic.ac.uk/index.php?title=Rep:JJ1516Ising&amp;diff=736444</id>
		<title>Rep:JJ1516Ising</title>
		<link rel="alternate" type="text/html" href="https://chemwiki.ch.ic.ac.uk/index.php?title=Rep:JJ1516Ising&amp;diff=736444"/>
		<updated>2018-11-20T18:58:42Z</updated>

		<summary type="html">&lt;p&gt;Jj1516: /* Calculating the minimum energy and entropy */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Ex Script Link:&lt;br /&gt;
https://wiki.ch.ic.ac.uk/wiki/index.php?title=Third_year_CMP_compulsory_experiment&lt;br /&gt;
&lt;br /&gt;
= Introduction to the Ising Model =&lt;br /&gt;
&lt;br /&gt;
== Calculating the minimum energy and entropy ==&lt;br /&gt;
The interaction energy of an Ising lattice is given by:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;E = -\frac{1}{2}J\displaystyle\sum_{i}^{N} \displaystyle\sum_{j\;\in\;{neighbours}\;(i)} \!\!\!\!\!\!\!\!\!\!\!\!s_{i}s_{j}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In an Ising lattice with D dimensions and periodic boundary conditions, a given spin &amp;lt;math&amp;gt; s_i&amp;lt;/math&amp;gt; has 2D neighbours.&lt;br /&gt;
&lt;br /&gt;
The minimum interaction energy is achieved when all spins in the lattice are aligned (all ↑ or all ↓). As  such, any spin &amp;lt;math&amp;gt; s_i&amp;lt;/math&amp;gt; must be aligned with all 2D of its neighbours. That is, &amp;lt;math&amp;gt;s_{i}s_{j} = 1&amp;lt;/math&amp;gt; for all &amp;lt;math&amp;gt;j&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Therefore, for any &amp;lt;math&amp;gt; s_i&amp;lt;/math&amp;gt;, the sum of its interactions is &amp;lt;math&amp;gt;\displaystyle\sum_{j\;\in\;{neighbours}\;(i)} \!\!\!\!\!\!\!\!\!\!\!\!s_{i}s_{j} = 2D &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
As this is true for all N spins in the lattice, it follows that &amp;lt;math&amp;gt;\displaystyle\sum_{i}^{N} 2D = 2DN&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Thus the minimum interaction energy is given by:&lt;br /&gt;
&lt;br /&gt;
:&amp;lt;math&amp;gt;E_{min} = -\frac{1}{2}J\cdot2DN = - DNJ &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The entropy of a given lattice state is given by:&lt;br /&gt;
&lt;br /&gt;
:&amp;lt;math&amp;gt;S = k\; ln\; \Omega &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Where &amp;lt;math&amp;gt; \Omega &amp;lt;/math&amp;gt; is the multiplicity of the state, the number of degenerate configurations of said state. The minimum energy state is achievable with all spins ↑ or by having all spins ↓. In the absence of an external magnetic field, these configurations are degenerate and indistinguishable giving &amp;lt;math&amp;gt; \Omega = 2 &amp;lt;/math&amp;gt; for this state. Therefore,&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; S_{E_{min}}  = k_{B}\; ln\; 2 = 0.693k_{B} = 9.57 \times 10^{-24} J\!\cdot\!\! K^{-1}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Calculating energy and entropy changes ==&lt;br /&gt;
&#039;&#039;&#039;What is the energy change from the lowest energy configuration when a single spin &amp;quot;flips&amp;quot;? What is the entropy change? (&amp;lt;math&amp;gt; D = 3, N = 1000 &amp;lt;/math&amp;gt;)&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\Delta{E} = E_1 - E_0&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;E_1&amp;lt;/math&amp;gt; One lattice cell spin flipped&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;E_0&amp;lt;/math&amp;gt; Lowest energy configuration&lt;br /&gt;
&lt;br /&gt;
[[Image:Task 2 table.PNG]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\displaystyle\sum_{interactions} = -2D + 2D(2D-2) + 2D[N-(2D+1)] &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; = 2DN - 8D &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;E_1 = \displaystyle-\frac{1}{2}J\;\sum_{int} = 4DJ - DNJ&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\Delta{E} = +4DJ = +12J&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Energy difference is independent of the number of lattice cells&lt;br /&gt;
&lt;br /&gt;
In this calculation, the following assumption has been made.&lt;br /&gt;
&lt;br /&gt;
* The lattice dimensions are infinite relative to the size of each cell&lt;br /&gt;
&lt;br /&gt;
This allows &#039;&#039;&#039;any&#039;&#039;&#039; cell to be treated as the centre of the lattice. In other words, it is possible to shift the lattice such that a cell initially at the lattice boundary is moved to the centre. This is justified by the periodic boundary conditions of the Ising model and in turn justifies this calculation&#039;s independence of N.&lt;br /&gt;
&lt;br /&gt;
Entropy Change&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; S = k_{B}\; ln\; \Omega &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\Omega = \displaystyle\frac{N!}{{N_{\uparrow}!}{N_{\downarrow}!}}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Where &amp;lt;math&amp;gt;N_{i}!&amp;lt;/math&amp;gt; denotes the factorial of the number of spins in spin state &amp;lt;math&amp;gt;i&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\Delta{S} = k_{B}\;ln\;\left(\displaystyle\frac{\Omega_{2}}{\Omega_{1}}\right)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\Omega_{2} = \frac{1000!}{999!1!} = 1000&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \Omega_{1} = \frac{1000!}{1000!} = 1&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\Delta{S} = k_{B}\;ln\;1000 = 9.54 \times 10^{-23} JK^{-1}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\Delta{S_{mol}} = N_{A}k_{B}\;ln\;1000 = 57.4 \,JK^{-1}mol^{-1}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Magnetisation Values of 1D and 2D Lattices===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;M_{1D} =\;\;+1&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;M_{2D} =\;\;+1&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
At 0K, no thermal energy is available to overcome the energetic barriers to spin flipping. Thus the energetic driving forces dominates the entropic driving force; for an Ising Lattice with D =  3, N = 1000 at 0K, the lowest energy configuration is achieved when all spins are parallel. This resutls in the maximum number of coupling interactions between spins.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;M_{expected} =  1000&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Calculating the Energy and Magnetisation =&lt;br /&gt;
&lt;br /&gt;
[[File:First_Ene_Method.PNG]]&lt;br /&gt;
&lt;br /&gt;
[[File:First_Mag_Method.PNG]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:ILChecks.PNG]]&lt;br /&gt;
&lt;br /&gt;
= Introduction to the Monte Carlo Simulation =&lt;br /&gt;
===Configurations Available to a 100 Spin System===&lt;br /&gt;
For a system of two spins, 4 configurations are possible (↑↑, ↓↓, ↑↓, ↓↑) i.e. &amp;lt;math&amp;gt;2^{2}&amp;lt;/math&amp;gt;. For a system of 100 spins, &amp;lt;math&amp;gt;2^{100}&amp;lt;/math&amp;gt; configurations are expected. In the first example, the ↑↑ and ↓↓ are degenerate, as are the ↑↓ and ↓↑ configurations. Therefore, dividing the number of possible configurations by the multiplicity of each configuration (&amp;lt;math&amp;gt;2&amp;lt;/math&amp;gt;) gives the number of distinguishable configurations.&lt;br /&gt;
For 100 spins, this gives &amp;lt;math&amp;gt;\displaystyle\frac{2^{100}}{2} = 6.338 \times 10^{29} &amp;lt;/math&amp;gt; distinguishable configurations or states.&lt;br /&gt;
&lt;br /&gt;
If our computational speed allowed for &amp;lt;math&amp;gt; 1 \times 10^{9}&amp;lt;/math&amp;gt; calculations each second, the evaluation of a single value of &amp;lt;math&amp;gt;\left\langle M\right\rangle_T&amp;lt;/math&amp;gt; would last &amp;lt;math&amp;gt; 6.338 \times 10^{20} &amp;lt;/math&amp;gt; seconds or &amp;lt;math&amp;gt; 1458 &amp;lt;/math&amp;gt; times the age of the Universe!&lt;br /&gt;
&lt;br /&gt;
===Modifying IsingLattice.py===&lt;br /&gt;
&lt;br /&gt;
[[File:Monte_Carlo.PNG]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The Metropolis Monte Carlo (MMC) algorithm provides a computationally inexpensive path from random initial states to the minimum free energy states of the Ising lattices generated. First, a random 2D Ising lattice is generated. A single random spin within this lattice is &amp;quot;flipped&amp;quot; and the resulting energy change between these states is measured. If the energy change is negative, this represents a decrease in the internal energy of the system which lowers the free energy: this configuration change is accepted.&lt;br /&gt;
&lt;br /&gt;
In the case that the spin &amp;quot;flip&amp;quot; does not lower the free energy, the MMC algorithm tests this configuration change against the Boltzman factor, enabling a determination of the resulting entropy change. In the canonical (NVT) ensemble, the entropy of the system is given by&lt;br /&gt;
&lt;br /&gt;
###&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:stats.PNG]]&lt;br /&gt;
&lt;br /&gt;
===Spontaneous Magnetisation===&lt;br /&gt;
&lt;br /&gt;
Below the Curie Temperature, &amp;lt;math&amp;gt; T_{C} &amp;lt;/math&amp;gt;, energetic driving forces dominate entropic driving forces. Therefore, the spins of the system align in order to maximise favourable interactions rather than adopting a less ordered configuration, which would maximise multiplicity (and thus entropy).&lt;br /&gt;
Below &amp;lt;math&amp;gt;T &amp;lt; T_C&amp;lt;/math&amp;gt;, the most probable configurations have an overall magnetisation resulting in &amp;lt;math&amp;gt;\left\langle M\right\rangle \neq 0&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
The plots of magnetisation per spin and energy per spin obtained from ILanim.py upon system equilibration show that at minimum energy per spin &amp;lt;math&amp;gt;E_{min_{spin}} = \frac{-NDJ}{N} = -DJ = -2&amp;lt;/math&amp;gt;, the magnitude of the overall magnetisation per spin is at a maximum &amp;lt;math&amp;gt;|M_{spin}| = 1&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:2T=1.0.png]]&lt;br /&gt;
[[File:T=1.0.png]]&lt;br /&gt;
[[File:3T=1.0.png]]&lt;br /&gt;
&lt;br /&gt;
==Accelerating the Code==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Initial Method Speeds===&lt;br /&gt;
Taking 10 repeat measurements for the time taken to perform 2000 Monte Carlo steps resulted in&lt;br /&gt;
&lt;br /&gt;
* An average time of  &amp;lt;math&amp;gt;11.7s&amp;lt;/math&amp;gt; &lt;br /&gt;
* A standard error of &amp;lt;math&amp;gt;0.020s&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Updating Measurement===&lt;br /&gt;
&lt;br /&gt;
NOTE: ILtimetrial.py has been modified to:&lt;br /&gt;
* Perform a requested number of &#039;2000 Monte Carlo Step&#039; measurements&lt;br /&gt;
* Record these measurements in a CSV file&lt;br /&gt;
* Return the mean measuremd time and the Standard Error i.e.   &amp;lt;math&amp;gt; \frac{\sigma}{n} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:TimeTrialMethod.PNG]]&lt;br /&gt;
&lt;br /&gt;
===Updating Energy and Magnetisation Methods===&lt;br /&gt;
[[File:New_Mag_Method.PNG]]&lt;br /&gt;
[[File:New_Ene_Method.PNG]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Updated Method Speeds===&lt;br /&gt;
[[File:TimeTrial.PNG]]&lt;br /&gt;
&lt;br /&gt;
Taking 30 measurements of the time taken to perform 2000 Monte Carlo Steps resulted in:&lt;br /&gt;
&lt;br /&gt;
* An average time of &amp;lt;math&amp;gt;\displaystyle{0.87s}&amp;lt;/math&amp;gt;&lt;br /&gt;
* A standard error of &amp;lt;math&amp;gt;2.5 \times 10^{-3}s&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This represents a &#039;&#039;&#039;INSERT&#039;&#039;&#039;% decrease in computation time from the initial methods.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==The Effect of Temperature==&lt;br /&gt;
&lt;br /&gt;
===Correcting the Averaging  Code===&lt;br /&gt;
&lt;br /&gt;
To quickly find a value for &amp;lt;math&amp;gt; N_{d}&amp;lt;/math&amp;gt;, the minimum number of cycles typically needed for the equilibration of a system of within the lattice and temperature ranges of interest, it was assumed that:&lt;br /&gt;
&lt;br /&gt;
* Larger lattices would require more Monte Carlo steps to reach equilibrium from their initial, random configurations&lt;br /&gt;
&lt;br /&gt;
* Lattices at lower temperatures would require more Monte Carlo steps to reach equilibrium from their initial, random configurations.&lt;br /&gt;
&lt;br /&gt;
Therefore, an initial value for &amp;lt;math&amp;gt; N_{d}&amp;lt;/math&amp;gt; was found for a &amp;lt;math&amp;gt; 128\times128 &amp;lt;/math&amp;gt; lattice at a temperature of &amp;lt;math&amp;gt;0.5&amp;lt;/math&amp;gt; reduced temperature units.&lt;br /&gt;
*&amp;lt;math&amp;gt; N_{d} = 185000 &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
By this number of steps, all smaller lattices at all higher temperatures were found to have equilibrated also. Thus, this value of&amp;lt;math&amp;gt; N_{d}&amp;lt;/math&amp;gt; was accepted as an appropriate delay.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:AFinFrame 128 3e5 T= 0.5line.png|400px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
For the 128x128 lattices at T=0.5, equilibration was ensured from 185000 steps onwards.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Smaller lattices at the same temperature did indeed equilibrate more slowly, but all equilibrated within &amp;lt;math&amp;gt; N_{d}&amp;lt;/math&amp;gt; MC steps.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:AFinFrame 64 3e5 T= 0.5line.png|400px]]&lt;br /&gt;
[[File:AFinFrame 32 3e5 T= 0.5line2.png|400px]]&lt;br /&gt;
[[File:AFinFrame 16 3e5 T= 0.5line2.png|400px]]&lt;br /&gt;
[[File:AFinFrame 8 3e5 T= 0.5line.png|400px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The figure below shows the modifications made to IsingLattice.py to incorporate the &amp;lt;math&amp;gt; N_{d} &amp;lt;/math&amp;gt; step delay.&lt;br /&gt;
&lt;br /&gt;
===Running over a Range of Temperatures===&lt;br /&gt;
&lt;br /&gt;
To examine the effect of temperature on the average energy &amp;lt;math&amp;gt; \left\langle E\right\rangle &amp;lt;/math&amp;gt; and average magnetisation &amp;lt;math&amp;gt; \left\langle M\right\rangle &amp;lt;/math&amp;gt; of Ising lattices at equilibrium, the following parameters were used:&lt;br /&gt;
&lt;br /&gt;
* Temperature Range: &amp;lt;math&amp;gt;  0.5 - 5 &amp;lt;/math&amp;gt; reduced units&lt;br /&gt;
* Temperature Interval: &amp;lt;math&amp;gt;0.01&amp;lt;/math&amp;gt; reduced units (&amp;lt;math&amp;gt;450&amp;lt;/math&amp;gt; temperature values)&lt;br /&gt;
* Number of MMC Steps per Temperature value: &amp;lt;math&amp;gt; 2 \times 10^5 &amp;lt;/math&amp;gt; with the aforementioned value of &amp;lt;math&amp;gt; N_{d} = 1.85 \times 10^5 &amp;lt;/math&amp;gt; Monte Carlo steps&lt;br /&gt;
* Lattice Sizes:  &amp;lt;math&amp;gt; 2 \times 2 &amp;lt;/math&amp;gt;, &amp;lt;math&amp;gt; 4 \times 4 &amp;lt;/math&amp;gt; , &amp;lt;math&amp;gt; 8 \times 8 &amp;lt;/math&amp;gt; , &amp;lt;math&amp;gt; 16 \times 16 &amp;lt;/math&amp;gt; , &amp;lt;math&amp;gt; 32 \times 32 &amp;lt;/math&amp;gt; , &amp;lt;math&amp;gt; 64 \times 64 &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Plots of  &amp;lt;math&amp;gt; \left\langle E\right\rangle &amp;lt;/math&amp;gt; and  &amp;lt;math&amp;gt; \left\langle M\right\rangle &amp;lt;/math&amp;gt; per spin as versus temperature are presented below for each lattice size. Errorbars have been implemented to demonstrate how &#039;&#039;well-behaved&#039;&#039; lattice systems of each size are at each temperature, that is, how temperature and lattice size affect the size of the variations in the expected values. For the error calculations, the standard errors, &amp;lt;math&amp;gt; \sigma_\bar{X} &amp;lt;/math&amp;gt;,  in &amp;lt;math&amp;gt; \left\langle E\right\rangle &amp;lt;/math&amp;gt; and  &amp;lt;math&amp;gt; \left\langle M\right\rangle &amp;lt;/math&amp;gt; per spin have been used:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====8x8====&lt;br /&gt;
&lt;br /&gt;
[[File:8x8e+error.png]] [[File:8x8m+error.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
A Python script has been written to generate a plot of &amp;lt;math&amp;gt;\left\langle E\right\rangle&amp;lt;/math&amp;gt; or &amp;lt;math&amp;gt;\left\langle M\right\rangle&amp;lt;/math&amp;gt; against temperature based upon user input. A screenshot of this code has been inserted below.&lt;br /&gt;
&lt;br /&gt;
[[File:ExpectedvsTemp.PNG|200px]]&lt;br /&gt;
&lt;br /&gt;
===Scaling the System Size===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====2x2====&lt;br /&gt;
[[File:2x2e+error.png]] [[File:2x2m+error.png]]&lt;br /&gt;
&lt;br /&gt;
====4x4====&lt;br /&gt;
[[File:4x4e+error.png]] [[File:4x4m+error.png]]&lt;br /&gt;
&lt;br /&gt;
====16x16====&lt;br /&gt;
[[File:16x16e+error.png]] [[File:16x16m+error.png]]&lt;br /&gt;
&lt;br /&gt;
====32x32====&lt;br /&gt;
[[File:32x32e+error.png]] [[File:32x32m+error.png]]&lt;br /&gt;
&lt;br /&gt;
====64x64====&lt;br /&gt;
[[File:64x64e+error.png]] [[File:64x64m+error.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Determining the Heat Capacity==&lt;br /&gt;
&lt;br /&gt;
===Calculating the Heat Capacity===&lt;br /&gt;
Working in the canonical ensemble (constant volume), the heat capacity &amp;lt;math&amp;gt; C_V &amp;lt;/math&amp;gt; is given by:&lt;br /&gt;
&lt;br /&gt;
:&amp;lt;math&amp;gt;C_V = \frac{\partial \left\langle E\right\rangle}{\partial T}_V&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
where &amp;lt;math&amp;gt;\left\langle E\right\rangle&amp;lt;/math&amp;gt; is the average total energy or expected value of the internal energy of the system.&lt;br /&gt;
&lt;br /&gt;
: &amp;lt;math&amp;gt; \left\langle E\right\rangle = - \frac{\partial ln Q}{\partial \beta} = -\frac{1}{Q}\frac{\partial Q}{\partial \beta} &amp;lt;/math&amp;gt;&lt;br /&gt;
where &amp;lt;math&amp;gt; Q&amp;lt;/math&amp;gt; is the partition function for the system of N interacting spins.&lt;br /&gt;
&lt;br /&gt;
By evaluating the second form of the partial derivative with respect to &amp;lt;math&amp;gt; \beta&amp;lt;/math&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \left\langle E\right\rangle = -\frac{1}{Q}\frac{\partial Q}{\partial \beta} = \frac{\Sigma \epsilon_{i} e^{-\beta \epsilon_{i}}}{\Sigma e^{-\beta \epsilon_{i}}} &amp;lt;/math&amp;gt; &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Applying the product rule enables the differentiation of this expression for &amp;lt;math&amp;gt;\left\langle E\right\rangle&amp;lt;/math&amp;gt; with respect to temperature, giving:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\frac{\partial \left\langle E\right\rangle}{\partial T} = \frac{\Sigma \epsilon_{i} \frac{\epsilon_i}{k_BT^2}e^{-\beta \epsilon_{i}}}{\Sigma e^{-\beta \epsilon_{i}}} - \frac{\Sigma \epsilon_i e^{-\beta \epsilon_i}\cdot \frac{\epsilon_i}{k_BT^2}e^{-\beta \epsilon_i}}{(\Sigma e^{-\beta \epsilon_{i}})^2}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\frac{\partial \left\langle E\right\rangle}{\partial T}  = \frac{1}{k_BT^2}\left[\frac{\Sigma \epsilon_i^2 e^{-\beta \epsilon_i}}{\Sigma e^{-\beta \epsilon_i}} - \left(\frac{\Sigma \epsilon_{i} e^{-\beta \epsilon_{i}}}{\Sigma e^{-\beta \epsilon_{i}}}\right)^2\right] &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\frac{\partial \left\langle E\right\rangle}{\partial T}  = \frac{1}{k_BT^2}\left[\left\langle E^2\right\rangle - \left\langle E\right\rangle^2 \right] &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Thus,&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\frac{\partial \left\langle E\right\rangle}{\partial T} = \frac{Var[E]}{k_BT^2} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Heat Capacity versus Temperature===&lt;br /&gt;
&lt;br /&gt;
====2x2====&lt;br /&gt;
[[File:HC2.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====4x4====&lt;br /&gt;
[[File:HC4.png]]&lt;br /&gt;
&lt;br /&gt;
====8x8====&lt;br /&gt;
[[File:HC8.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====16x16====&lt;br /&gt;
[[File:HC16.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====32x32====&lt;br /&gt;
[[File:HC32.png]]&lt;br /&gt;
&lt;br /&gt;
== Locating the Curie Temperature ==&lt;br /&gt;
&lt;br /&gt;
===C++ Data Comparison===&lt;br /&gt;
&lt;br /&gt;
[[File:CHC2.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Polyfitting of C++ Data===&lt;br /&gt;
&lt;br /&gt;
====Fitting a Polynomial to the Entire Range====&lt;br /&gt;
&lt;br /&gt;
[[File:15Polyc2x2.png]]&lt;br /&gt;
Polynomials with 5 terms and above were found to match the data in the vicinity of the critical region considerably well. Below 7 terms, the &#039;&#039;tails&#039;&#039; of the plot were matched poorly. In the above example, a polynomial of 15 terms was fit to the data.&lt;br /&gt;
&lt;br /&gt;
=== Python Scripts ===&lt;/div&gt;</summary>
		<author><name>Jj1516</name></author>
	</entry>
	<entry>
		<id>https://chemwiki.ch.ic.ac.uk/index.php?title=Rep:JJ1516Ising&amp;diff=736278</id>
		<title>Rep:JJ1516Ising</title>
		<link rel="alternate" type="text/html" href="https://chemwiki.ch.ic.ac.uk/index.php?title=Rep:JJ1516Ising&amp;diff=736278"/>
		<updated>2018-11-20T13:22:39Z</updated>

		<summary type="html">&lt;p&gt;Jj1516: /* C++ Data Comparison */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Ex Script Link:&lt;br /&gt;
https://wiki.ch.ic.ac.uk/wiki/index.php?title=Third_year_CMP_compulsory_experiment&lt;br /&gt;
&lt;br /&gt;
= Introduction to the Ising Model =&lt;br /&gt;
&lt;br /&gt;
== Calculating the minimum energy and entropy ==&lt;br /&gt;
Show that the lowest possible lattice energy under the Ising Model is &amp;lt;math&amp;gt; E = -DNJ &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The energy of an Ising lattice is given by: &amp;lt;math&amp;gt; E = -DNJ&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In D dimensions, each lattice cell within a lattice with periodic boundary conditions has 2D neighbours.&lt;br /&gt;
&amp;lt;math&amp;gt;E = -\frac{1}{2}J\displaystyle\sum_{i}^{N} \displaystyle\sum_{j\;\in\;{neighbours}\;(i)} \!\!\!\!\!\!\!\!\!\!\!\!s_{i}s_{j}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In D dimensions with periodic boudnary conditions, each lattice cell has 2D neighbours.&lt;br /&gt;
&lt;br /&gt;
For the minimum energy interactions, all &amp;lt;math&amp;gt;s_{i}s_{j}&amp;lt;/math&amp;gt; pairs are spin aligned such that &amp;lt;math&amp;gt;s_{i}s_{j} = 1&amp;lt;/math&amp;gt; for all &amp;lt;math&amp;gt;i&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;j&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Therefore, &amp;lt;math&amp;gt;\displaystyle\sum_{j\;\in\;{neighbours}\;(i)} \!\!\!\!\!\!\!\!\!\!\!\!s_{i}s_{j} = 2D &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
It follows that &amp;lt;math&amp;gt;\displaystyle\sum_{i}^{N} 2D = 2DN&amp;lt;/math&amp;gt; &lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;E_{min} = -\frac{1}{2}J2DN = - DNJ &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The entropy of a given lattice configuration is given by:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;S_{min} = k\; ln\; \Omega &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For a given lattice energy, &amp;lt;math&amp;gt; \Omega &amp;lt;/math&amp;gt; is the total number of configurations which will give this energy. configuration may be achieved. In the case of the minimum energy configuration, which may be achieved with all spins or all spins down, &amp;lt;math&amp;gt; \Omega = 2 &amp;lt;/math&amp;gt;. Therefore,&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; S_{E_{min}}  = k_{B}\; ln\; 2 = 0.693k_{B} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Calculating energy and entropy changes ==&lt;br /&gt;
&#039;&#039;&#039;What is the energy change from the lowest energy configuration when a single spin &amp;quot;flips&amp;quot;? What is the entropy change? (&amp;lt;math&amp;gt; D = 3, N = 1000 &amp;lt;/math&amp;gt;)&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\Delta{E} = E_1 - E_0&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;E_1&amp;lt;/math&amp;gt; One lattice cell spin flipped&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;E_0&amp;lt;/math&amp;gt; Lowest energy configuration&lt;br /&gt;
&lt;br /&gt;
[[Image:Task 2 table.PNG]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\displaystyle\sum_{interactions} = -2D + 2D(2D-2) + 2D[N-(2D+1)] &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; = 2DN - 8D &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;E_1 = \displaystyle-\frac{1}{2}J\;\sum_{int} = 4DJ - DNJ&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\Delta{E} = +4DJ = +12J&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Energy difference is independent of the number of lattice cells&lt;br /&gt;
&lt;br /&gt;
In this calculation, the following assumption has been made.&lt;br /&gt;
&lt;br /&gt;
* The lattice dimensions are infinite relative to the size of each cell&lt;br /&gt;
&lt;br /&gt;
This allows &#039;&#039;&#039;any&#039;&#039;&#039; cell to be treated as the centre of the lattice. In other words, it is possible to shift the lattice such that a cell initially at the lattice boundary is moved to the centre. This is justified by the periodic boundary conditions of the Ising model and in turn justifies this calculation&#039;s independence of N.&lt;br /&gt;
&lt;br /&gt;
Entropy Change&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; S = k_{B}\; ln\; \Omega &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\Omega = \displaystyle\frac{N!}{{N_{\uparrow}!}{N_{\downarrow}!}}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Where &amp;lt;math&amp;gt;N_{i}!&amp;lt;/math&amp;gt; denotes the factorial of the number of spins in spin state &amp;lt;math&amp;gt;i&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\Delta{S} = k_{B}\;ln\;\left(\displaystyle\frac{\Omega_{2}}{\Omega_{1}}\right)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\Omega_{2} = \frac{1000!}{999!1!} = 1000&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \Omega_{1} = \frac{1000!}{1000!} = 1&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\Delta{S} = k_{B}\;ln\;1000 = 9.54 \times 10^{-23} JK^{-1}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\Delta{S_{mol}} = N_{A}k_{B}\;ln\;1000 = 57.4 \,JK^{-1}mol^{-1}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Magnetisation Values of 1D and 2D Lattices===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;M_{1D} =\;\;+1&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;M_{2D} =\;\;+1&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
At 0K, no thermal energy is available to overcome the energetic barriers to spin flipping. Thus the energetic driving forces dominates the entropic driving force; for an Ising Lattice with D =  3, N = 1000 at 0K, the lowest energy configuration is achieved when all spins are parallel. This resutls in the maximum number of coupling interactions between spins.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;M_{expected} =  1000&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Calculating the Energy and Magnetisation =&lt;br /&gt;
&lt;br /&gt;
[[File:First_Ene_Method.PNG]]&lt;br /&gt;
&lt;br /&gt;
[[File:First_Mag_Method.PNG]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:ILChecks.PNG]]&lt;br /&gt;
&lt;br /&gt;
= Introduction to the Monte Carlo Simulation =&lt;br /&gt;
===Configurations Available to a 100 Spin System===&lt;br /&gt;
For a system of two spins, 4 configurations are possible (↑↑, ↓↓, ↑↓, ↓↑) i.e. &amp;lt;math&amp;gt;2^{2}&amp;lt;/math&amp;gt;. For a system of 100 spins, &amp;lt;math&amp;gt;2^{100}&amp;lt;/math&amp;gt; configurations are expected. In the first example, the ↑↑ and ↓↓ are degenerate, as are the ↑↓ and ↓↑ configurations. Therefore, dividing the number of possible configurations by the multiplicity of each configuration (&amp;lt;math&amp;gt;2&amp;lt;/math&amp;gt;) gives the number of distinguishable configurations.&lt;br /&gt;
For 100 spins, this gives &amp;lt;math&amp;gt;\displaystyle\frac{2^{100}}{2} = 6.338 \times 10^{29} &amp;lt;/math&amp;gt; distinguishable configurations or states.&lt;br /&gt;
&lt;br /&gt;
If our computational speed allowed for &amp;lt;math&amp;gt; 1 \times 10^{9}&amp;lt;/math&amp;gt; calculations each second, the evaluation of a single value of &amp;lt;math&amp;gt;\left\langle M\right\rangle_T&amp;lt;/math&amp;gt; would last &amp;lt;math&amp;gt; 6.338 \times 10^{20} &amp;lt;/math&amp;gt; seconds or &amp;lt;math&amp;gt; 1458 &amp;lt;/math&amp;gt; times the age of the Universe!&lt;br /&gt;
&lt;br /&gt;
===Modifying IsingLattice.py===&lt;br /&gt;
&lt;br /&gt;
[[File:Monte_Carlo.PNG]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The Metropolis Monte Carlo (MMC) algorithm provides a computationally inexpensive path from random initial states to the minimum free energy states of the Ising lattices generated. First, a random 2D Ising lattice is generated. A single random spin within this lattice is &amp;quot;flipped&amp;quot; and the resulting energy change between these states is measured. If the energy change is negative, this represents a decrease in the internal energy of the system which lowers the free energy: this configuration change is accepted.&lt;br /&gt;
&lt;br /&gt;
In the case that the spin &amp;quot;flip&amp;quot; does not lower the free energy, the MMC algorithm tests this configuration change against the Boltzman factor, enabling a determination of the resulting entropy change. In the canonical (NVT) ensemble, the entropy of the system is given by&lt;br /&gt;
&lt;br /&gt;
###&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:stats.PNG]]&lt;br /&gt;
&lt;br /&gt;
===Spontaneous Magnetisation===&lt;br /&gt;
&lt;br /&gt;
Below the Curie Temperature, &amp;lt;math&amp;gt; T_{C} &amp;lt;/math&amp;gt;, energetic driving forces dominate entropic driving forces. Therefore, the spins of the system align in order to maximise favourable interactions rather than adopting a less ordered configuration, which would maximise multiplicity (and thus entropy).&lt;br /&gt;
Below &amp;lt;math&amp;gt;T &amp;lt; T_C&amp;lt;/math&amp;gt;, the most probable configurations have an overall magnetisation resulting in &amp;lt;math&amp;gt;\left\langle M\right\rangle \neq 0&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
The plots of magnetisation per spin and energy per spin obtained from ILanim.py upon system equilibration show that at minimum energy per spin &amp;lt;math&amp;gt;E_{min_{spin}} = \frac{-NDJ}{N} = -DJ = -2&amp;lt;/math&amp;gt;, the magnitude of the overall magnetisation per spin is at a maximum &amp;lt;math&amp;gt;|M_{spin}| = 1&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:2T=1.0.png]]&lt;br /&gt;
[[File:T=1.0.png]]&lt;br /&gt;
[[File:3T=1.0.png]]&lt;br /&gt;
&lt;br /&gt;
==Accelerating the Code==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Initial Method Speeds===&lt;br /&gt;
Taking 10 repeat measurements for the time taken to perform 2000 Monte Carlo steps resulted in&lt;br /&gt;
&lt;br /&gt;
* An average time of  &amp;lt;math&amp;gt;11.7s&amp;lt;/math&amp;gt; &lt;br /&gt;
* A standard error of &amp;lt;math&amp;gt;0.020s&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Updating Measurement===&lt;br /&gt;
&lt;br /&gt;
NOTE: ILtimetrial.py has been modified to:&lt;br /&gt;
* Perform a requested number of &#039;2000 Monte Carlo Step&#039; measurements&lt;br /&gt;
* Record these measurements in a CSV file&lt;br /&gt;
* Return the mean measuremd time and the Standard Error i.e.   &amp;lt;math&amp;gt; \frac{\sigma}{n} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:TimeTrialMethod.PNG]]&lt;br /&gt;
&lt;br /&gt;
===Updating Energy and Magnetisation Methods===&lt;br /&gt;
[[File:New_Mag_Method.PNG]]&lt;br /&gt;
[[File:New_Ene_Method.PNG]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Updated Method Speeds===&lt;br /&gt;
[[File:TimeTrial.PNG]]&lt;br /&gt;
&lt;br /&gt;
Taking 30 measurements of the time taken to perform 2000 Monte Carlo Steps resulted in:&lt;br /&gt;
&lt;br /&gt;
* An average time of &amp;lt;math&amp;gt;\displaystyle{0.87s}&amp;lt;/math&amp;gt;&lt;br /&gt;
* A standard error of &amp;lt;math&amp;gt;2.5 \times 10^{-3}s&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This represents a &#039;&#039;&#039;INSERT&#039;&#039;&#039;% decrease in computation time from the initial methods.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==The Effect of Temperature==&lt;br /&gt;
&lt;br /&gt;
===Correcting the Averaging  Code===&lt;br /&gt;
&lt;br /&gt;
To quickly find a value for &amp;lt;math&amp;gt; N_{d}&amp;lt;/math&amp;gt;, the minimum number of cycles typically needed for the equilibration of a system of within the lattice and temperature ranges of interest, it was assumed that:&lt;br /&gt;
&lt;br /&gt;
* Larger lattices would require more Monte Carlo steps to reach equilibrium from their initial, random configurations&lt;br /&gt;
&lt;br /&gt;
* Lattices at lower temperatures would require more Monte Carlo steps to reach equilibrium from their initial, random configurations.&lt;br /&gt;
&lt;br /&gt;
Therefore, an initial value for &amp;lt;math&amp;gt; N_{d}&amp;lt;/math&amp;gt; was found for a &amp;lt;math&amp;gt; 128\times128 &amp;lt;/math&amp;gt; lattice at a temperature of &amp;lt;math&amp;gt;0.5&amp;lt;/math&amp;gt; reduced temperature units.&lt;br /&gt;
*&amp;lt;math&amp;gt; N_{d} = 185000 &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
By this number of steps, all smaller lattices at all higher temperatures were found to have equilibrated also. Thus, this value of&amp;lt;math&amp;gt; N_{d}&amp;lt;/math&amp;gt; was accepted as an appropriate delay.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:AFinFrame 128 3e5 T= 0.5line.png|400px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
For the 128x128 lattices at T=0.5, equilibration was ensured from 185000 steps onwards.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Smaller lattices at the same temperature did indeed equilibrate more slowly, but all equilibrated within &amp;lt;math&amp;gt; N_{d}&amp;lt;/math&amp;gt; MC steps.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:AFinFrame 64 3e5 T= 0.5line.png|400px]]&lt;br /&gt;
[[File:AFinFrame 32 3e5 T= 0.5line2.png|400px]]&lt;br /&gt;
[[File:AFinFrame 16 3e5 T= 0.5line2.png|400px]]&lt;br /&gt;
[[File:AFinFrame 8 3e5 T= 0.5line.png|400px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The figure below shows the modifications made to IsingLattice.py to incorporate the &amp;lt;math&amp;gt; N_{d} &amp;lt;/math&amp;gt; step delay.&lt;br /&gt;
&lt;br /&gt;
===Running over a Range of Temperatures===&lt;br /&gt;
&lt;br /&gt;
To examine the effect of temperature on the average energy &amp;lt;math&amp;gt; \left\langle E\right\rangle &amp;lt;/math&amp;gt; and average magnetisation &amp;lt;math&amp;gt; \left\langle M\right\rangle &amp;lt;/math&amp;gt; of Ising lattices at equilibrium, the following parameters were used:&lt;br /&gt;
&lt;br /&gt;
* Temperature Range: &amp;lt;math&amp;gt;  0.5 - 5 &amp;lt;/math&amp;gt; reduced units&lt;br /&gt;
* Temperature Interval: &amp;lt;math&amp;gt;0.01&amp;lt;/math&amp;gt; reduced units (&amp;lt;math&amp;gt;450&amp;lt;/math&amp;gt; temperature values)&lt;br /&gt;
* Number of MMC Steps per Temperature value: &amp;lt;math&amp;gt; 2 \times 10^5 &amp;lt;/math&amp;gt; with the aforementioned value of &amp;lt;math&amp;gt; N_{d} = 1.85 \times 10^5 &amp;lt;/math&amp;gt; Monte Carlo steps&lt;br /&gt;
* Lattice Sizes:  &amp;lt;math&amp;gt; 2 \times 2 &amp;lt;/math&amp;gt;, &amp;lt;math&amp;gt; 4 \times 4 &amp;lt;/math&amp;gt; , &amp;lt;math&amp;gt; 8 \times 8 &amp;lt;/math&amp;gt; , &amp;lt;math&amp;gt; 16 \times 16 &amp;lt;/math&amp;gt; , &amp;lt;math&amp;gt; 32 \times 32 &amp;lt;/math&amp;gt; , &amp;lt;math&amp;gt; 64 \times 64 &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Plots of  &amp;lt;math&amp;gt; \left\langle E\right\rangle &amp;lt;/math&amp;gt; and  &amp;lt;math&amp;gt; \left\langle M\right\rangle &amp;lt;/math&amp;gt; per spin as versus temperature are presented below for each lattice size. Errorbars have been implemented to demonstrate how &#039;&#039;well-behaved&#039;&#039; lattice systems of each size are at each temperature, that is, how temperature and lattice size affect the size of the variations in the expected values. For the error calculations, the standard errors, &amp;lt;math&amp;gt; \sigma_\bar{X} &amp;lt;/math&amp;gt;,  in &amp;lt;math&amp;gt; \left\langle E\right\rangle &amp;lt;/math&amp;gt; and  &amp;lt;math&amp;gt; \left\langle M\right\rangle &amp;lt;/math&amp;gt; per spin have been used:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====8x8====&lt;br /&gt;
&lt;br /&gt;
[[File:8x8e+error.png]] [[File:8x8m+error.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
A Python script has been written to generate a plot of &amp;lt;math&amp;gt;\left\langle E\right\rangle&amp;lt;/math&amp;gt; or &amp;lt;math&amp;gt;\left\langle M\right\rangle&amp;lt;/math&amp;gt; against temperature based upon user input. A screenshot of this code has been inserted below.&lt;br /&gt;
&lt;br /&gt;
[[File:ExpectedvsTemp.PNG|200px]]&lt;br /&gt;
&lt;br /&gt;
===Scaling the System Size===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====2x2====&lt;br /&gt;
[[File:2x2e+error.png]] [[File:2x2m+error.png]]&lt;br /&gt;
&lt;br /&gt;
====4x4====&lt;br /&gt;
[[File:4x4e+error.png]] [[File:4x4m+error.png]]&lt;br /&gt;
&lt;br /&gt;
====16x16====&lt;br /&gt;
[[File:16x16e+error.png]] [[File:16x16m+error.png]]&lt;br /&gt;
&lt;br /&gt;
====32x32====&lt;br /&gt;
[[File:32x32e+error.png]] [[File:32x32m+error.png]]&lt;br /&gt;
&lt;br /&gt;
====64x64====&lt;br /&gt;
[[File:64x64e+error.png]] [[File:64x64m+error.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Determining the Heat Capacity==&lt;br /&gt;
&lt;br /&gt;
===Calculating the Heat Capacity===&lt;br /&gt;
Working in the canonical ensemble (constant volume), the heat capacity &amp;lt;math&amp;gt; C_V &amp;lt;/math&amp;gt; is given by:&lt;br /&gt;
&lt;br /&gt;
:&amp;lt;math&amp;gt;C_V = \frac{\partial \left\langle E\right\rangle}{\partial T}_V&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
where &amp;lt;math&amp;gt;\left\langle E\right\rangle&amp;lt;/math&amp;gt; is the average total energy or expected value of the internal energy of the system.&lt;br /&gt;
&lt;br /&gt;
: &amp;lt;math&amp;gt; \left\langle E\right\rangle = - \frac{\partial ln Q}{\partial \beta} = -\frac{1}{Q}\frac{\partial Q}{\partial \beta} &amp;lt;/math&amp;gt;&lt;br /&gt;
where &amp;lt;math&amp;gt; Q&amp;lt;/math&amp;gt; is the partition function for the system of N interacting spins.&lt;br /&gt;
&lt;br /&gt;
By evaluating the second form of the partial derivative with respect to &amp;lt;math&amp;gt; \beta&amp;lt;/math&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \left\langle E\right\rangle = -\frac{1}{Q}\frac{\partial Q}{\partial \beta} = \frac{\Sigma \epsilon_{i} e^{-\beta \epsilon_{i}}}{\Sigma e^{-\beta \epsilon_{i}}} &amp;lt;/math&amp;gt; &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Applying the product rule enables the differentiation of this expression for &amp;lt;math&amp;gt;\left\langle E\right\rangle&amp;lt;/math&amp;gt; with respect to temperature, giving:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\frac{\partial \left\langle E\right\rangle}{\partial T} = \frac{\Sigma \epsilon_{i} \frac{\epsilon_i}{k_BT^2}e^{-\beta \epsilon_{i}}}{\Sigma e^{-\beta \epsilon_{i}}} - \frac{\Sigma \epsilon_i e^{-\beta \epsilon_i}\cdot \frac{\epsilon_i}{k_BT^2}e^{-\beta \epsilon_i}}{(\Sigma e^{-\beta \epsilon_{i}})^2}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\frac{\partial \left\langle E\right\rangle}{\partial T}  = \frac{1}{k_BT^2}\left[\frac{\Sigma \epsilon_i^2 e^{-\beta \epsilon_i}}{\Sigma e^{-\beta \epsilon_i}} - \left(\frac{\Sigma \epsilon_{i} e^{-\beta \epsilon_{i}}}{\Sigma e^{-\beta \epsilon_{i}}}\right)^2\right] &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\frac{\partial \left\langle E\right\rangle}{\partial T}  = \frac{1}{k_BT^2}\left[\left\langle E^2\right\rangle - \left\langle E\right\rangle^2 \right] &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Thus,&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\frac{\partial \left\langle E\right\rangle}{\partial T} = \frac{Var[E]}{k_BT^2} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Heat Capacity versus Temperature===&lt;br /&gt;
&lt;br /&gt;
====2x2====&lt;br /&gt;
[[File:HC2.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====4x4====&lt;br /&gt;
[[File:HC4.png]]&lt;br /&gt;
&lt;br /&gt;
====8x8====&lt;br /&gt;
[[File:HC8.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====16x16====&lt;br /&gt;
[[File:HC16.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====32x32====&lt;br /&gt;
[[File:HC32.png]]&lt;br /&gt;
&lt;br /&gt;
== Locating the Curie Temperature ==&lt;br /&gt;
&lt;br /&gt;
===C++ Data Comparison===&lt;br /&gt;
&lt;br /&gt;
[[File:CHC2.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Polyfitting of C++ Data===&lt;br /&gt;
&lt;br /&gt;
====Fitting a Polynomial to the Entire Range====&lt;br /&gt;
&lt;br /&gt;
[[File:15Polyc2x2.png]]&lt;br /&gt;
Polynomials with 5 terms and above were found to match the data in the vicinity of the critical region considerably well. Below 7 terms, the &#039;&#039;tails&#039;&#039; of the plot were matched poorly. In the above example, a polynomial of 15 terms was fit to the data.&lt;br /&gt;
&lt;br /&gt;
=== Python Scripts ===&lt;/div&gt;</summary>
		<author><name>Jj1516</name></author>
	</entry>
	<entry>
		<id>https://chemwiki.ch.ic.ac.uk/index.php?title=File:15Polyc2x2.png&amp;diff=736274</id>
		<title>File:15Polyc2x2.png</title>
		<link rel="alternate" type="text/html" href="https://chemwiki.ch.ic.ac.uk/index.php?title=File:15Polyc2x2.png&amp;diff=736274"/>
		<updated>2018-11-20T13:18:54Z</updated>

		<summary type="html">&lt;p&gt;Jj1516: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Jj1516</name></author>
	</entry>
	<entry>
		<id>https://chemwiki.ch.ic.ac.uk/index.php?title=Rep:JJ1516Ising&amp;diff=736236</id>
		<title>Rep:JJ1516Ising</title>
		<link rel="alternate" type="text/html" href="https://chemwiki.ch.ic.ac.uk/index.php?title=Rep:JJ1516Ising&amp;diff=736236"/>
		<updated>2018-11-20T12:28:36Z</updated>

		<summary type="html">&lt;p&gt;Jj1516: /* Heat Capacity versus Temperature */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Ex Script Link:&lt;br /&gt;
https://wiki.ch.ic.ac.uk/wiki/index.php?title=Third_year_CMP_compulsory_experiment&lt;br /&gt;
&lt;br /&gt;
= Introduction to the Ising Model =&lt;br /&gt;
&lt;br /&gt;
== Calculating the minimum energy and entropy ==&lt;br /&gt;
Show that the lowest possible lattice energy under the Ising Model is &amp;lt;math&amp;gt; E = -DNJ &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The energy of an Ising lattice is given by: &amp;lt;math&amp;gt; E = -DNJ&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In D dimensions, each lattice cell within a lattice with periodic boundary conditions has 2D neighbours.&lt;br /&gt;
&amp;lt;math&amp;gt;E = -\frac{1}{2}J\displaystyle\sum_{i}^{N} \displaystyle\sum_{j\;\in\;{neighbours}\;(i)} \!\!\!\!\!\!\!\!\!\!\!\!s_{i}s_{j}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In D dimensions with periodic boudnary conditions, each lattice cell has 2D neighbours.&lt;br /&gt;
&lt;br /&gt;
For the minimum energy interactions, all &amp;lt;math&amp;gt;s_{i}s_{j}&amp;lt;/math&amp;gt; pairs are spin aligned such that &amp;lt;math&amp;gt;s_{i}s_{j} = 1&amp;lt;/math&amp;gt; for all &amp;lt;math&amp;gt;i&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;j&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Therefore, &amp;lt;math&amp;gt;\displaystyle\sum_{j\;\in\;{neighbours}\;(i)} \!\!\!\!\!\!\!\!\!\!\!\!s_{i}s_{j} = 2D &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
It follows that &amp;lt;math&amp;gt;\displaystyle\sum_{i}^{N} 2D = 2DN&amp;lt;/math&amp;gt; &lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;E_{min} = -\frac{1}{2}J2DN = - DNJ &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The entropy of a given lattice configuration is given by:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;S_{min} = k\; ln\; \Omega &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For a given lattice energy, &amp;lt;math&amp;gt; \Omega &amp;lt;/math&amp;gt; is the total number of configurations which will give this energy. configuration may be achieved. In the case of the minimum energy configuration, which may be achieved with all spins or all spins down, &amp;lt;math&amp;gt; \Omega = 2 &amp;lt;/math&amp;gt;. Therefore,&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; S_{E_{min}}  = k_{B}\; ln\; 2 = 0.693k_{B} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Calculating energy and entropy changes ==&lt;br /&gt;
&#039;&#039;&#039;What is the energy change from the lowest energy configuration when a single spin &amp;quot;flips&amp;quot;? What is the entropy change? (&amp;lt;math&amp;gt; D = 3, N = 1000 &amp;lt;/math&amp;gt;)&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\Delta{E} = E_1 - E_0&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;E_1&amp;lt;/math&amp;gt; One lattice cell spin flipped&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;E_0&amp;lt;/math&amp;gt; Lowest energy configuration&lt;br /&gt;
&lt;br /&gt;
[[Image:Task 2 table.PNG]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\displaystyle\sum_{interactions} = -2D + 2D(2D-2) + 2D[N-(2D+1)] &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; = 2DN - 8D &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;E_1 = \displaystyle-\frac{1}{2}J\;\sum_{int} = 4DJ - DNJ&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\Delta{E} = +4DJ = +12J&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Energy difference is independent of the number of lattice cells&lt;br /&gt;
&lt;br /&gt;
In this calculation, the following assumption has been made.&lt;br /&gt;
&lt;br /&gt;
* The lattice dimensions are infinite relative to the size of each cell&lt;br /&gt;
&lt;br /&gt;
This allows &#039;&#039;&#039;any&#039;&#039;&#039; cell to be treated as the centre of the lattice. In other words, it is possible to shift the lattice such that a cell initially at the lattice boundary is moved to the centre. This is justified by the periodic boundary conditions of the Ising model and in turn justifies this calculation&#039;s independence of N.&lt;br /&gt;
&lt;br /&gt;
Entropy Change&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; S = k_{B}\; ln\; \Omega &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\Omega = \displaystyle\frac{N!}{{N_{\uparrow}!}{N_{\downarrow}!}}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Where &amp;lt;math&amp;gt;N_{i}!&amp;lt;/math&amp;gt; denotes the factorial of the number of spins in spin state &amp;lt;math&amp;gt;i&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\Delta{S} = k_{B}\;ln\;\left(\displaystyle\frac{\Omega_{2}}{\Omega_{1}}\right)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\Omega_{2} = \frac{1000!}{999!1!} = 1000&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \Omega_{1} = \frac{1000!}{1000!} = 1&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\Delta{S} = k_{B}\;ln\;1000 = 9.54 \times 10^{-23} JK^{-1}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\Delta{S_{mol}} = N_{A}k_{B}\;ln\;1000 = 57.4 \,JK^{-1}mol^{-1}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Magnetisation Values of 1D and 2D Lattices===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;M_{1D} =\;\;+1&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;M_{2D} =\;\;+1&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
At 0K, no thermal energy is available to overcome the energetic barriers to spin flipping. Thus the energetic driving forces dominates the entropic driving force; for an Ising Lattice with D =  3, N = 1000 at 0K, the lowest energy configuration is achieved when all spins are parallel. This resutls in the maximum number of coupling interactions between spins.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;M_{expected} =  1000&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Calculating the Energy and Magnetisation =&lt;br /&gt;
&lt;br /&gt;
[[File:First_Ene_Method.PNG]]&lt;br /&gt;
&lt;br /&gt;
[[File:First_Mag_Method.PNG]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:ILChecks.PNG]]&lt;br /&gt;
&lt;br /&gt;
= Introduction to the Monte Carlo Simulation =&lt;br /&gt;
===Configurations Available to a 100 Spin System===&lt;br /&gt;
For a system of two spins, 4 configurations are possible (↑↑, ↓↓, ↑↓, ↓↑) i.e. &amp;lt;math&amp;gt;2^{2}&amp;lt;/math&amp;gt;. For a system of 100 spins, &amp;lt;math&amp;gt;2^{100}&amp;lt;/math&amp;gt; configurations are expected. In the first example, the ↑↑ and ↓↓ are degenerate, as are the ↑↓ and ↓↑ configurations. Therefore, dividing the number of possible configurations by the multiplicity of each configuration (&amp;lt;math&amp;gt;2&amp;lt;/math&amp;gt;) gives the number of distinguishable configurations.&lt;br /&gt;
For 100 spins, this gives &amp;lt;math&amp;gt;\displaystyle\frac{2^{100}}{2} = 6.338 \times 10^{29} &amp;lt;/math&amp;gt; distinguishable configurations or states.&lt;br /&gt;
&lt;br /&gt;
If our computational speed allowed for &amp;lt;math&amp;gt; 1 \times 10^{9}&amp;lt;/math&amp;gt; calculations each second, the evaluation of a single value of &amp;lt;math&amp;gt;\left\langle M\right\rangle_T&amp;lt;/math&amp;gt; would last &amp;lt;math&amp;gt; 6.338 \times 10^{20} &amp;lt;/math&amp;gt; seconds or &amp;lt;math&amp;gt; 1458 &amp;lt;/math&amp;gt; times the age of the Universe!&lt;br /&gt;
&lt;br /&gt;
===Modifying IsingLattice.py===&lt;br /&gt;
&lt;br /&gt;
[[File:Monte_Carlo.PNG]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The Metropolis Monte Carlo (MMC) algorithm provides a computationally inexpensive path from random initial states to the minimum free energy states of the Ising lattices generated. First, a random 2D Ising lattice is generated. A single random spin within this lattice is &amp;quot;flipped&amp;quot; and the resulting energy change between these states is measured. If the energy change is negative, this represents a decrease in the internal energy of the system which lowers the free energy: this configuration change is accepted.&lt;br /&gt;
&lt;br /&gt;
In the case that the spin &amp;quot;flip&amp;quot; does not lower the free energy, the MMC algorithm tests this configuration change against the Boltzman factor, enabling a determination of the resulting entropy change. In the canonical (NVT) ensemble, the entropy of the system is given by&lt;br /&gt;
&lt;br /&gt;
###&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:stats.PNG]]&lt;br /&gt;
&lt;br /&gt;
===Spontaneous Magnetisation===&lt;br /&gt;
&lt;br /&gt;
Below the Curie Temperature, &amp;lt;math&amp;gt; T_{C} &amp;lt;/math&amp;gt;, energetic driving forces dominate entropic driving forces. Therefore, the spins of the system align in order to maximise favourable interactions rather than adopting a less ordered configuration, which would maximise multiplicity (and thus entropy).&lt;br /&gt;
Below &amp;lt;math&amp;gt;T &amp;lt; T_C&amp;lt;/math&amp;gt;, the most probable configurations have an overall magnetisation resulting in &amp;lt;math&amp;gt;\left\langle M\right\rangle \neq 0&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
The plots of magnetisation per spin and energy per spin obtained from ILanim.py upon system equilibration show that at minimum energy per spin &amp;lt;math&amp;gt;E_{min_{spin}} = \frac{-NDJ}{N} = -DJ = -2&amp;lt;/math&amp;gt;, the magnitude of the overall magnetisation per spin is at a maximum &amp;lt;math&amp;gt;|M_{spin}| = 1&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:2T=1.0.png]]&lt;br /&gt;
[[File:T=1.0.png]]&lt;br /&gt;
[[File:3T=1.0.png]]&lt;br /&gt;
&lt;br /&gt;
==Accelerating the Code==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Initial Method Speeds===&lt;br /&gt;
Taking 10 repeat measurements for the time taken to perform 2000 Monte Carlo steps resulted in&lt;br /&gt;
&lt;br /&gt;
* An average time of  &amp;lt;math&amp;gt;11.7s&amp;lt;/math&amp;gt; &lt;br /&gt;
* A standard error of &amp;lt;math&amp;gt;0.020s&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Updating Measurement===&lt;br /&gt;
&lt;br /&gt;
NOTE: ILtimetrial.py has been modified to:&lt;br /&gt;
* Perform a requested number of &#039;2000 Monte Carlo Step&#039; measurements&lt;br /&gt;
* Record these measurements in a CSV file&lt;br /&gt;
* Return the mean measuremd time and the Standard Error i.e.   &amp;lt;math&amp;gt; \frac{\sigma}{n} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:TimeTrialMethod.PNG]]&lt;br /&gt;
&lt;br /&gt;
===Updating Energy and Magnetisation Methods===&lt;br /&gt;
[[File:New_Mag_Method.PNG]]&lt;br /&gt;
[[File:New_Ene_Method.PNG]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Updated Method Speeds===&lt;br /&gt;
[[File:TimeTrial.PNG]]&lt;br /&gt;
&lt;br /&gt;
Taking 30 measurements of the time taken to perform 2000 Monte Carlo Steps resulted in:&lt;br /&gt;
&lt;br /&gt;
* An average time of &amp;lt;math&amp;gt;\displaystyle{0.87s}&amp;lt;/math&amp;gt;&lt;br /&gt;
* A standard error of &amp;lt;math&amp;gt;2.5 \times 10^{-3}s&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This represents a &#039;&#039;&#039;INSERT&#039;&#039;&#039;% decrease in computation time from the initial methods.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==The Effect of Temperature==&lt;br /&gt;
&lt;br /&gt;
===Correcting the Averaging  Code===&lt;br /&gt;
&lt;br /&gt;
To quickly find a value for &amp;lt;math&amp;gt; N_{d}&amp;lt;/math&amp;gt;, the minimum number of cycles typically needed for the equilibration of a system of within the lattice and temperature ranges of interest, it was assumed that:&lt;br /&gt;
&lt;br /&gt;
* Larger lattices would require more Monte Carlo steps to reach equilibrium from their initial, random configurations&lt;br /&gt;
&lt;br /&gt;
* Lattices at lower temperatures would require more Monte Carlo steps to reach equilibrium from their initial, random configurations.&lt;br /&gt;
&lt;br /&gt;
Therefore, an initial value for &amp;lt;math&amp;gt; N_{d}&amp;lt;/math&amp;gt; was found for a &amp;lt;math&amp;gt; 128\times128 &amp;lt;/math&amp;gt; lattice at a temperature of &amp;lt;math&amp;gt;0.5&amp;lt;/math&amp;gt; reduced temperature units.&lt;br /&gt;
*&amp;lt;math&amp;gt; N_{d} = 185000 &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
By this number of steps, all smaller lattices at all higher temperatures were found to have equilibrated also. Thus, this value of&amp;lt;math&amp;gt; N_{d}&amp;lt;/math&amp;gt; was accepted as an appropriate delay.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:AFinFrame 128 3e5 T= 0.5line.png|400px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
For the 128x128 lattices at T=0.5, equilibration was ensured from 185000 steps onwards.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Smaller lattices at the same temperature did indeed equilibrate more slowly, but all equilibrated within &amp;lt;math&amp;gt; N_{d}&amp;lt;/math&amp;gt; MC steps.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:AFinFrame 64 3e5 T= 0.5line.png|400px]]&lt;br /&gt;
[[File:AFinFrame 32 3e5 T= 0.5line2.png|400px]]&lt;br /&gt;
[[File:AFinFrame 16 3e5 T= 0.5line2.png|400px]]&lt;br /&gt;
[[File:AFinFrame 8 3e5 T= 0.5line.png|400px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The figure below shows the modifications made to IsingLattice.py to incorporate the &amp;lt;math&amp;gt; N_{d} &amp;lt;/math&amp;gt; step delay.&lt;br /&gt;
&lt;br /&gt;
===Running over a Range of Temperatures===&lt;br /&gt;
&lt;br /&gt;
To examine the effect of temperature on the average energy &amp;lt;math&amp;gt; \left\langle E\right\rangle &amp;lt;/math&amp;gt; and average magnetisation &amp;lt;math&amp;gt; \left\langle M\right\rangle &amp;lt;/math&amp;gt; of Ising lattices at equilibrium, the following parameters were used:&lt;br /&gt;
&lt;br /&gt;
* Temperature Range: &amp;lt;math&amp;gt;  0.5 - 5 &amp;lt;/math&amp;gt; reduced units&lt;br /&gt;
* Temperature Interval: &amp;lt;math&amp;gt;0.01&amp;lt;/math&amp;gt; reduced units (&amp;lt;math&amp;gt;450&amp;lt;/math&amp;gt; temperature values)&lt;br /&gt;
* Number of MMC Steps per Temperature value: &amp;lt;math&amp;gt; 2 \times 10^5 &amp;lt;/math&amp;gt; with the aforementioned value of &amp;lt;math&amp;gt; N_{d} = 1.85 \times 10^5 &amp;lt;/math&amp;gt; Monte Carlo steps&lt;br /&gt;
* Lattice Sizes:  &amp;lt;math&amp;gt; 2 \times 2 &amp;lt;/math&amp;gt;, &amp;lt;math&amp;gt; 4 \times 4 &amp;lt;/math&amp;gt; , &amp;lt;math&amp;gt; 8 \times 8 &amp;lt;/math&amp;gt; , &amp;lt;math&amp;gt; 16 \times 16 &amp;lt;/math&amp;gt; , &amp;lt;math&amp;gt; 32 \times 32 &amp;lt;/math&amp;gt; , &amp;lt;math&amp;gt; 64 \times 64 &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Plots of  &amp;lt;math&amp;gt; \left\langle E\right\rangle &amp;lt;/math&amp;gt; and  &amp;lt;math&amp;gt; \left\langle M\right\rangle &amp;lt;/math&amp;gt; per spin as versus temperature are presented below for each lattice size. Errorbars have been implemented to demonstrate how &#039;&#039;well-behaved&#039;&#039; lattice systems of each size are at each temperature, that is, how temperature and lattice size affect the size of the variations in the expected values. For the error calculations, the standard errors, &amp;lt;math&amp;gt; \sigma_\bar{X} &amp;lt;/math&amp;gt;,  in &amp;lt;math&amp;gt; \left\langle E\right\rangle &amp;lt;/math&amp;gt; and  &amp;lt;math&amp;gt; \left\langle M\right\rangle &amp;lt;/math&amp;gt; per spin have been used:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====8x8====&lt;br /&gt;
&lt;br /&gt;
[[File:8x8e+error.png]] [[File:8x8m+error.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
A Python script has been written to generate a plot of &amp;lt;math&amp;gt;\left\langle E\right\rangle&amp;lt;/math&amp;gt; or &amp;lt;math&amp;gt;\left\langle M\right\rangle&amp;lt;/math&amp;gt; against temperature based upon user input. A screenshot of this code has been inserted below.&lt;br /&gt;
&lt;br /&gt;
[[File:ExpectedvsTemp.PNG|200px]]&lt;br /&gt;
&lt;br /&gt;
===Scaling the System Size===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====2x2====&lt;br /&gt;
[[File:2x2e+error.png]] [[File:2x2m+error.png]]&lt;br /&gt;
&lt;br /&gt;
====4x4====&lt;br /&gt;
[[File:4x4e+error.png]] [[File:4x4m+error.png]]&lt;br /&gt;
&lt;br /&gt;
====16x16====&lt;br /&gt;
[[File:16x16e+error.png]] [[File:16x16m+error.png]]&lt;br /&gt;
&lt;br /&gt;
====32x32====&lt;br /&gt;
[[File:32x32e+error.png]] [[File:32x32m+error.png]]&lt;br /&gt;
&lt;br /&gt;
====64x64====&lt;br /&gt;
[[File:64x64e+error.png]] [[File:64x64m+error.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Determining the Heat Capacity==&lt;br /&gt;
&lt;br /&gt;
===Calculating the Heat Capacity===&lt;br /&gt;
Working in the canonical ensemble (constant volume), the heat capacity &amp;lt;math&amp;gt; C_V &amp;lt;/math&amp;gt; is given by:&lt;br /&gt;
&lt;br /&gt;
:&amp;lt;math&amp;gt;C_V = \frac{\partial \left\langle E\right\rangle}{\partial T}_V&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
where &amp;lt;math&amp;gt;\left\langle E\right\rangle&amp;lt;/math&amp;gt; is the average total energy or expected value of the internal energy of the system.&lt;br /&gt;
&lt;br /&gt;
: &amp;lt;math&amp;gt; \left\langle E\right\rangle = - \frac{\partial ln Q}{\partial \beta} = -\frac{1}{Q}\frac{\partial Q}{\partial \beta} &amp;lt;/math&amp;gt;&lt;br /&gt;
where &amp;lt;math&amp;gt; Q&amp;lt;/math&amp;gt; is the partition function for the system of N interacting spins.&lt;br /&gt;
&lt;br /&gt;
By evaluating the second form of the partial derivative with respect to &amp;lt;math&amp;gt; \beta&amp;lt;/math&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \left\langle E\right\rangle = -\frac{1}{Q}\frac{\partial Q}{\partial \beta} = \frac{\Sigma \epsilon_{i} e^{-\beta \epsilon_{i}}}{\Sigma e^{-\beta \epsilon_{i}}} &amp;lt;/math&amp;gt; &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Applying the product rule enables the differentiation of this expression for &amp;lt;math&amp;gt;\left\langle E\right\rangle&amp;lt;/math&amp;gt; with respect to temperature, giving:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\frac{\partial \left\langle E\right\rangle}{\partial T} = \frac{\Sigma \epsilon_{i} \frac{\epsilon_i}{k_BT^2}e^{-\beta \epsilon_{i}}}{\Sigma e^{-\beta \epsilon_{i}}} - \frac{\Sigma \epsilon_i e^{-\beta \epsilon_i}\cdot \frac{\epsilon_i}{k_BT^2}e^{-\beta \epsilon_i}}{(\Sigma e^{-\beta \epsilon_{i}})^2}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\frac{\partial \left\langle E\right\rangle}{\partial T}  = \frac{1}{k_BT^2}\left[\frac{\Sigma \epsilon_i^2 e^{-\beta \epsilon_i}}{\Sigma e^{-\beta \epsilon_i}} - \left(\frac{\Sigma \epsilon_{i} e^{-\beta \epsilon_{i}}}{\Sigma e^{-\beta \epsilon_{i}}}\right)^2\right] &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\frac{\partial \left\langle E\right\rangle}{\partial T}  = \frac{1}{k_BT^2}\left[\left\langle E^2\right\rangle - \left\langle E\right\rangle^2 \right] &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Thus,&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\frac{\partial \left\langle E\right\rangle}{\partial T} = \frac{Var[E]}{k_BT^2} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Heat Capacity versus Temperature===&lt;br /&gt;
&lt;br /&gt;
====2x2====&lt;br /&gt;
[[File:HC2.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====4x4====&lt;br /&gt;
[[File:HC4.png]]&lt;br /&gt;
&lt;br /&gt;
====8x8====&lt;br /&gt;
[[File:HC8.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====16x16====&lt;br /&gt;
[[File:HC16.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====32x32====&lt;br /&gt;
[[File:HC32.png]]&lt;br /&gt;
&lt;br /&gt;
== Locating the Curie Temperature ==&lt;br /&gt;
&lt;br /&gt;
===C++ Data Comparison===&lt;br /&gt;
&lt;br /&gt;
[[File:CHC2.png]]&lt;br /&gt;
&lt;br /&gt;
=== Python Scripts ===&lt;/div&gt;</summary>
		<author><name>Jj1516</name></author>
	</entry>
	<entry>
		<id>https://chemwiki.ch.ic.ac.uk/index.php?title=File:CHC2.png&amp;diff=736235</id>
		<title>File:CHC2.png</title>
		<link rel="alternate" type="text/html" href="https://chemwiki.ch.ic.ac.uk/index.php?title=File:CHC2.png&amp;diff=736235"/>
		<updated>2018-11-20T12:28:32Z</updated>

		<summary type="html">&lt;p&gt;Jj1516: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Jj1516</name></author>
	</entry>
	<entry>
		<id>https://chemwiki.ch.ic.ac.uk/index.php?title=Rep:JJ1516Ising&amp;diff=736226</id>
		<title>Rep:JJ1516Ising</title>
		<link rel="alternate" type="text/html" href="https://chemwiki.ch.ic.ac.uk/index.php?title=Rep:JJ1516Ising&amp;diff=736226"/>
		<updated>2018-11-20T12:05:49Z</updated>

		<summary type="html">&lt;p&gt;Jj1516: /* 4x4 */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Ex Script Link:&lt;br /&gt;
https://wiki.ch.ic.ac.uk/wiki/index.php?title=Third_year_CMP_compulsory_experiment&lt;br /&gt;
&lt;br /&gt;
= Introduction to the Ising Model =&lt;br /&gt;
&lt;br /&gt;
== Calculating the minimum energy and entropy ==&lt;br /&gt;
Show that the lowest possible lattice energy under the Ising Model is &amp;lt;math&amp;gt; E = -DNJ &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The energy of an Ising lattice is given by: &amp;lt;math&amp;gt; E = -DNJ&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In D dimensions, each lattice cell within a lattice with periodic boundary conditions has 2D neighbours.&lt;br /&gt;
&amp;lt;math&amp;gt;E = -\frac{1}{2}J\displaystyle\sum_{i}^{N} \displaystyle\sum_{j\;\in\;{neighbours}\;(i)} \!\!\!\!\!\!\!\!\!\!\!\!s_{i}s_{j}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In D dimensions with periodic boudnary conditions, each lattice cell has 2D neighbours.&lt;br /&gt;
&lt;br /&gt;
For the minimum energy interactions, all &amp;lt;math&amp;gt;s_{i}s_{j}&amp;lt;/math&amp;gt; pairs are spin aligned such that &amp;lt;math&amp;gt;s_{i}s_{j} = 1&amp;lt;/math&amp;gt; for all &amp;lt;math&amp;gt;i&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;j&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Therefore, &amp;lt;math&amp;gt;\displaystyle\sum_{j\;\in\;{neighbours}\;(i)} \!\!\!\!\!\!\!\!\!\!\!\!s_{i}s_{j} = 2D &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
It follows that &amp;lt;math&amp;gt;\displaystyle\sum_{i}^{N} 2D = 2DN&amp;lt;/math&amp;gt; &lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;E_{min} = -\frac{1}{2}J2DN = - DNJ &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The entropy of a given lattice configuration is given by:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;S_{min} = k\; ln\; \Omega &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For a given lattice energy, &amp;lt;math&amp;gt; \Omega &amp;lt;/math&amp;gt; is the total number of configurations which will give this energy. configuration may be achieved. In the case of the minimum energy configuration, which may be achieved with all spins or all spins down, &amp;lt;math&amp;gt; \Omega = 2 &amp;lt;/math&amp;gt;. Therefore,&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; S_{E_{min}}  = k_{B}\; ln\; 2 = 0.693k_{B} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Calculating energy and entropy changes ==&lt;br /&gt;
&#039;&#039;&#039;What is the energy change from the lowest energy configuration when a single spin &amp;quot;flips&amp;quot;? What is the entropy change? (&amp;lt;math&amp;gt; D = 3, N = 1000 &amp;lt;/math&amp;gt;)&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\Delta{E} = E_1 - E_0&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;E_1&amp;lt;/math&amp;gt; One lattice cell spin flipped&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;E_0&amp;lt;/math&amp;gt; Lowest energy configuration&lt;br /&gt;
&lt;br /&gt;
[[Image:Task 2 table.PNG]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\displaystyle\sum_{interactions} = -2D + 2D(2D-2) + 2D[N-(2D+1)] &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; = 2DN - 8D &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;E_1 = \displaystyle-\frac{1}{2}J\;\sum_{int} = 4DJ - DNJ&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\Delta{E} = +4DJ = +12J&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Energy difference is independent of the number of lattice cells&lt;br /&gt;
&lt;br /&gt;
In this calculation, the following assumption has been made.&lt;br /&gt;
&lt;br /&gt;
* The lattice dimensions are infinite relative to the size of each cell&lt;br /&gt;
&lt;br /&gt;
This allows &#039;&#039;&#039;any&#039;&#039;&#039; cell to be treated as the centre of the lattice. In other words, it is possible to shift the lattice such that a cell initially at the lattice boundary is moved to the centre. This is justified by the periodic boundary conditions of the Ising model and in turn justifies this calculation&#039;s independence of N.&lt;br /&gt;
&lt;br /&gt;
Entropy Change&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; S = k_{B}\; ln\; \Omega &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\Omega = \displaystyle\frac{N!}{{N_{\uparrow}!}{N_{\downarrow}!}}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Where &amp;lt;math&amp;gt;N_{i}!&amp;lt;/math&amp;gt; denotes the factorial of the number of spins in spin state &amp;lt;math&amp;gt;i&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\Delta{S} = k_{B}\;ln\;\left(\displaystyle\frac{\Omega_{2}}{\Omega_{1}}\right)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\Omega_{2} = \frac{1000!}{999!1!} = 1000&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \Omega_{1} = \frac{1000!}{1000!} = 1&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\Delta{S} = k_{B}\;ln\;1000 = 9.54 \times 10^{-23} JK^{-1}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\Delta{S_{mol}} = N_{A}k_{B}\;ln\;1000 = 57.4 \,JK^{-1}mol^{-1}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Magnetisation Values of 1D and 2D Lattices===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;M_{1D} =\;\;+1&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;M_{2D} =\;\;+1&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
At 0K, no thermal energy is available to overcome the energetic barriers to spin flipping. Thus the energetic driving forces dominates the entropic driving force; for an Ising Lattice with D =  3, N = 1000 at 0K, the lowest energy configuration is achieved when all spins are parallel. This resutls in the maximum number of coupling interactions between spins.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;M_{expected} =  1000&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Calculating the Energy and Magnetisation =&lt;br /&gt;
&lt;br /&gt;
[[File:First_Ene_Method.PNG]]&lt;br /&gt;
&lt;br /&gt;
[[File:First_Mag_Method.PNG]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:ILChecks.PNG]]&lt;br /&gt;
&lt;br /&gt;
= Introduction to the Monte Carlo Simulation =&lt;br /&gt;
===Configurations Available to a 100 Spin System===&lt;br /&gt;
For a system of two spins, 4 configurations are possible (↑↑, ↓↓, ↑↓, ↓↑) i.e. &amp;lt;math&amp;gt;2^{2}&amp;lt;/math&amp;gt;. For a system of 100 spins, &amp;lt;math&amp;gt;2^{100}&amp;lt;/math&amp;gt; configurations are expected. In the first example, the ↑↑ and ↓↓ are degenerate, as are the ↑↓ and ↓↑ configurations. Therefore, dividing the number of possible configurations by the multiplicity of each configuration (&amp;lt;math&amp;gt;2&amp;lt;/math&amp;gt;) gives the number of distinguishable configurations.&lt;br /&gt;
For 100 spins, this gives &amp;lt;math&amp;gt;\displaystyle\frac{2^{100}}{2} = 6.338 \times 10^{29} &amp;lt;/math&amp;gt; distinguishable configurations or states.&lt;br /&gt;
&lt;br /&gt;
If our computational speed allowed for &amp;lt;math&amp;gt; 1 \times 10^{9}&amp;lt;/math&amp;gt; calculations each second, the evaluation of a single value of &amp;lt;math&amp;gt;\left\langle M\right\rangle_T&amp;lt;/math&amp;gt; would last &amp;lt;math&amp;gt; 6.338 \times 10^{20} &amp;lt;/math&amp;gt; seconds or &amp;lt;math&amp;gt; 1458 &amp;lt;/math&amp;gt; times the age of the Universe!&lt;br /&gt;
&lt;br /&gt;
===Modifying IsingLattice.py===&lt;br /&gt;
&lt;br /&gt;
[[File:Monte_Carlo.PNG]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The Metropolis Monte Carlo (MMC) algorithm provides a computationally inexpensive path from random initial states to the minimum free energy states of the Ising lattices generated. First, a random 2D Ising lattice is generated. A single random spin within this lattice is &amp;quot;flipped&amp;quot; and the resulting energy change between these states is measured. If the energy change is negative, this represents a decrease in the internal energy of the system which lowers the free energy: this configuration change is accepted.&lt;br /&gt;
&lt;br /&gt;
In the case that the spin &amp;quot;flip&amp;quot; does not lower the free energy, the MMC algorithm tests this configuration change against the Boltzman factor, enabling a determination of the resulting entropy change. In the canonical (NVT) ensemble, the entropy of the system is given by&lt;br /&gt;
&lt;br /&gt;
###&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:stats.PNG]]&lt;br /&gt;
&lt;br /&gt;
===Spontaneous Magnetisation===&lt;br /&gt;
&lt;br /&gt;
Below the Curie Temperature, &amp;lt;math&amp;gt; T_{C} &amp;lt;/math&amp;gt;, energetic driving forces dominate entropic driving forces. Therefore, the spins of the system align in order to maximise favourable interactions rather than adopting a less ordered configuration, which would maximise multiplicity (and thus entropy).&lt;br /&gt;
Below &amp;lt;math&amp;gt;T &amp;lt; T_C&amp;lt;/math&amp;gt;, the most probable configurations have an overall magnetisation resulting in &amp;lt;math&amp;gt;\left\langle M\right\rangle \neq 0&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
The plots of magnetisation per spin and energy per spin obtained from ILanim.py upon system equilibration show that at minimum energy per spin &amp;lt;math&amp;gt;E_{min_{spin}} = \frac{-NDJ}{N} = -DJ = -2&amp;lt;/math&amp;gt;, the magnitude of the overall magnetisation per spin is at a maximum &amp;lt;math&amp;gt;|M_{spin}| = 1&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:2T=1.0.png]]&lt;br /&gt;
[[File:T=1.0.png]]&lt;br /&gt;
[[File:3T=1.0.png]]&lt;br /&gt;
&lt;br /&gt;
==Accelerating the Code==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Initial Method Speeds===&lt;br /&gt;
Taking 10 repeat measurements for the time taken to perform 2000 Monte Carlo steps resulted in&lt;br /&gt;
&lt;br /&gt;
* An average time of  &amp;lt;math&amp;gt;11.7s&amp;lt;/math&amp;gt; &lt;br /&gt;
* A standard error of &amp;lt;math&amp;gt;0.020s&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Updating Measurement===&lt;br /&gt;
&lt;br /&gt;
NOTE: ILtimetrial.py has been modified to:&lt;br /&gt;
* Perform a requested number of &#039;2000 Monte Carlo Step&#039; measurements&lt;br /&gt;
* Record these measurements in a CSV file&lt;br /&gt;
* Return the mean measuremd time and the Standard Error i.e.   &amp;lt;math&amp;gt; \frac{\sigma}{n} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:TimeTrialMethod.PNG]]&lt;br /&gt;
&lt;br /&gt;
===Updating Energy and Magnetisation Methods===&lt;br /&gt;
[[File:New_Mag_Method.PNG]]&lt;br /&gt;
[[File:New_Ene_Method.PNG]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Updated Method Speeds===&lt;br /&gt;
[[File:TimeTrial.PNG]]&lt;br /&gt;
&lt;br /&gt;
Taking 30 measurements of the time taken to perform 2000 Monte Carlo Steps resulted in:&lt;br /&gt;
&lt;br /&gt;
* An average time of &amp;lt;math&amp;gt;\displaystyle{0.87s}&amp;lt;/math&amp;gt;&lt;br /&gt;
* A standard error of &amp;lt;math&amp;gt;2.5 \times 10^{-3}s&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This represents a &#039;&#039;&#039;INSERT&#039;&#039;&#039;% decrease in computation time from the initial methods.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==The Effect of Temperature==&lt;br /&gt;
&lt;br /&gt;
===Correcting the Averaging  Code===&lt;br /&gt;
&lt;br /&gt;
To quickly find a value for &amp;lt;math&amp;gt; N_{d}&amp;lt;/math&amp;gt;, the minimum number of cycles typically needed for the equilibration of a system of within the lattice and temperature ranges of interest, it was assumed that:&lt;br /&gt;
&lt;br /&gt;
* Larger lattices would require more Monte Carlo steps to reach equilibrium from their initial, random configurations&lt;br /&gt;
&lt;br /&gt;
* Lattices at lower temperatures would require more Monte Carlo steps to reach equilibrium from their initial, random configurations.&lt;br /&gt;
&lt;br /&gt;
Therefore, an initial value for &amp;lt;math&amp;gt; N_{d}&amp;lt;/math&amp;gt; was found for a &amp;lt;math&amp;gt; 128\times128 &amp;lt;/math&amp;gt; lattice at a temperature of &amp;lt;math&amp;gt;0.5&amp;lt;/math&amp;gt; reduced temperature units.&lt;br /&gt;
*&amp;lt;math&amp;gt; N_{d} = 185000 &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
By this number of steps, all smaller lattices at all higher temperatures were found to have equilibrated also. Thus, this value of&amp;lt;math&amp;gt; N_{d}&amp;lt;/math&amp;gt; was accepted as an appropriate delay.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:AFinFrame 128 3e5 T= 0.5line.png|400px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
For the 128x128 lattices at T=0.5, equilibration was ensured from 185000 steps onwards.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Smaller lattices at the same temperature did indeed equilibrate more slowly, but all equilibrated within &amp;lt;math&amp;gt; N_{d}&amp;lt;/math&amp;gt; MC steps.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:AFinFrame 64 3e5 T= 0.5line.png|400px]]&lt;br /&gt;
[[File:AFinFrame 32 3e5 T= 0.5line2.png|400px]]&lt;br /&gt;
[[File:AFinFrame 16 3e5 T= 0.5line2.png|400px]]&lt;br /&gt;
[[File:AFinFrame 8 3e5 T= 0.5line.png|400px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The figure below shows the modifications made to IsingLattice.py to incorporate the &amp;lt;math&amp;gt; N_{d} &amp;lt;/math&amp;gt; step delay.&lt;br /&gt;
&lt;br /&gt;
===Running over a Range of Temperatures===&lt;br /&gt;
&lt;br /&gt;
To examine the effect of temperature on the average energy &amp;lt;math&amp;gt; \left\langle E\right\rangle &amp;lt;/math&amp;gt; and average magnetisation &amp;lt;math&amp;gt; \left\langle M\right\rangle &amp;lt;/math&amp;gt; of Ising lattices at equilibrium, the following parameters were used:&lt;br /&gt;
&lt;br /&gt;
* Temperature Range: &amp;lt;math&amp;gt;  0.5 - 5 &amp;lt;/math&amp;gt; reduced units&lt;br /&gt;
* Temperature Interval: &amp;lt;math&amp;gt;0.01&amp;lt;/math&amp;gt; reduced units (&amp;lt;math&amp;gt;450&amp;lt;/math&amp;gt; temperature values)&lt;br /&gt;
* Number of MMC Steps per Temperature value: &amp;lt;math&amp;gt; 2 \times 10^5 &amp;lt;/math&amp;gt; with the aforementioned value of &amp;lt;math&amp;gt; N_{d} = 1.85 \times 10^5 &amp;lt;/math&amp;gt; Monte Carlo steps&lt;br /&gt;
* Lattice Sizes:  &amp;lt;math&amp;gt; 2 \times 2 &amp;lt;/math&amp;gt;, &amp;lt;math&amp;gt; 4 \times 4 &amp;lt;/math&amp;gt; , &amp;lt;math&amp;gt; 8 \times 8 &amp;lt;/math&amp;gt; , &amp;lt;math&amp;gt; 16 \times 16 &amp;lt;/math&amp;gt; , &amp;lt;math&amp;gt; 32 \times 32 &amp;lt;/math&amp;gt; , &amp;lt;math&amp;gt; 64 \times 64 &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Plots of  &amp;lt;math&amp;gt; \left\langle E\right\rangle &amp;lt;/math&amp;gt; and  &amp;lt;math&amp;gt; \left\langle M\right\rangle &amp;lt;/math&amp;gt; per spin as versus temperature are presented below for each lattice size. Errorbars have been implemented to demonstrate how &#039;&#039;well-behaved&#039;&#039; lattice systems of each size are at each temperature, that is, how temperature and lattice size affect the size of the variations in the expected values. For the error calculations, the standard errors, &amp;lt;math&amp;gt; \sigma_\bar{X} &amp;lt;/math&amp;gt;,  in &amp;lt;math&amp;gt; \left\langle E\right\rangle &amp;lt;/math&amp;gt; and  &amp;lt;math&amp;gt; \left\langle M\right\rangle &amp;lt;/math&amp;gt; per spin have been used:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====8x8====&lt;br /&gt;
&lt;br /&gt;
[[File:8x8e+error.png]] [[File:8x8m+error.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
A Python script has been written to generate a plot of &amp;lt;math&amp;gt;\left\langle E\right\rangle&amp;lt;/math&amp;gt; or &amp;lt;math&amp;gt;\left\langle M\right\rangle&amp;lt;/math&amp;gt; against temperature based upon user input. A screenshot of this code has been inserted below.&lt;br /&gt;
&lt;br /&gt;
[[File:ExpectedvsTemp.PNG|200px]]&lt;br /&gt;
&lt;br /&gt;
===Scaling the System Size===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====2x2====&lt;br /&gt;
[[File:2x2e+error.png]] [[File:2x2m+error.png]]&lt;br /&gt;
&lt;br /&gt;
====4x4====&lt;br /&gt;
[[File:4x4e+error.png]] [[File:4x4m+error.png]]&lt;br /&gt;
&lt;br /&gt;
====16x16====&lt;br /&gt;
[[File:16x16e+error.png]] [[File:16x16m+error.png]]&lt;br /&gt;
&lt;br /&gt;
====32x32====&lt;br /&gt;
[[File:32x32e+error.png]] [[File:32x32m+error.png]]&lt;br /&gt;
&lt;br /&gt;
====64x64====&lt;br /&gt;
[[File:64x64e+error.png]] [[File:64x64m+error.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Determining the Heat Capacity==&lt;br /&gt;
&lt;br /&gt;
===Calculating the Heat Capacity===&lt;br /&gt;
Working in the canonical ensemble (constant volume), the heat capacity &amp;lt;math&amp;gt; C_V &amp;lt;/math&amp;gt; is given by:&lt;br /&gt;
&lt;br /&gt;
:&amp;lt;math&amp;gt;C_V = \frac{\partial \left\langle E\right\rangle}{\partial T}_V&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
where &amp;lt;math&amp;gt;\left\langle E\right\rangle&amp;lt;/math&amp;gt; is the average total energy or expected value of the internal energy of the system.&lt;br /&gt;
&lt;br /&gt;
: &amp;lt;math&amp;gt; \left\langle E\right\rangle = - \frac{\partial ln Q}{\partial \beta} = -\frac{1}{Q}\frac{\partial Q}{\partial \beta} &amp;lt;/math&amp;gt;&lt;br /&gt;
where &amp;lt;math&amp;gt; Q&amp;lt;/math&amp;gt; is the partition function for the system of N interacting spins.&lt;br /&gt;
&lt;br /&gt;
By evaluating the second form of the partial derivative with respect to &amp;lt;math&amp;gt; \beta&amp;lt;/math&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \left\langle E\right\rangle = -\frac{1}{Q}\frac{\partial Q}{\partial \beta} = \frac{\Sigma \epsilon_{i} e^{-\beta \epsilon_{i}}}{\Sigma e^{-\beta \epsilon_{i}}} &amp;lt;/math&amp;gt; &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Applying the product rule enables the differentiation of this expression for &amp;lt;math&amp;gt;\left\langle E\right\rangle&amp;lt;/math&amp;gt; with respect to temperature, giving:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\frac{\partial \left\langle E\right\rangle}{\partial T} = \frac{\Sigma \epsilon_{i} \frac{\epsilon_i}{k_BT^2}e^{-\beta \epsilon_{i}}}{\Sigma e^{-\beta \epsilon_{i}}} - \frac{\Sigma \epsilon_i e^{-\beta \epsilon_i}\cdot \frac{\epsilon_i}{k_BT^2}e^{-\beta \epsilon_i}}{(\Sigma e^{-\beta \epsilon_{i}})^2}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\frac{\partial \left\langle E\right\rangle}{\partial T}  = \frac{1}{k_BT^2}\left[\frac{\Sigma \epsilon_i^2 e^{-\beta \epsilon_i}}{\Sigma e^{-\beta \epsilon_i}} - \left(\frac{\Sigma \epsilon_{i} e^{-\beta \epsilon_{i}}}{\Sigma e^{-\beta \epsilon_{i}}}\right)^2\right] &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\frac{\partial \left\langle E\right\rangle}{\partial T}  = \frac{1}{k_BT^2}\left[\left\langle E^2\right\rangle - \left\langle E\right\rangle^2 \right] &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Thus,&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\frac{\partial \left\langle E\right\rangle}{\partial T} = \frac{Var[E]}{k_BT^2} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Heat Capacity versus Temperature===&lt;br /&gt;
&lt;br /&gt;
====2x2====&lt;br /&gt;
[[File:HC2.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====4x4====&lt;br /&gt;
[[File:HC4.png]]&lt;br /&gt;
&lt;br /&gt;
====8x8====&lt;br /&gt;
[[File:HC8.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====16x16====&lt;br /&gt;
[[File:HC16.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====32x32====&lt;br /&gt;
[[File:HC32.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Python Scripts ===&lt;/div&gt;</summary>
		<author><name>Jj1516</name></author>
	</entry>
	<entry>
		<id>https://chemwiki.ch.ic.ac.uk/index.php?title=Rep:JJ1516Ising&amp;diff=736225</id>
		<title>Rep:JJ1516Ising</title>
		<link rel="alternate" type="text/html" href="https://chemwiki.ch.ic.ac.uk/index.php?title=Rep:JJ1516Ising&amp;diff=736225"/>
		<updated>2018-11-20T12:05:25Z</updated>

		<summary type="html">&lt;p&gt;Jj1516: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Ex Script Link:&lt;br /&gt;
https://wiki.ch.ic.ac.uk/wiki/index.php?title=Third_year_CMP_compulsory_experiment&lt;br /&gt;
&lt;br /&gt;
= Introduction to the Ising Model =&lt;br /&gt;
&lt;br /&gt;
== Calculating the minimum energy and entropy ==&lt;br /&gt;
Show that the lowest possible lattice energy under the Ising Model is &amp;lt;math&amp;gt; E = -DNJ &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The energy of an Ising lattice is given by: &amp;lt;math&amp;gt; E = -DNJ&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In D dimensions, each lattice cell within a lattice with periodic boundary conditions has 2D neighbours.&lt;br /&gt;
&amp;lt;math&amp;gt;E = -\frac{1}{2}J\displaystyle\sum_{i}^{N} \displaystyle\sum_{j\;\in\;{neighbours}\;(i)} \!\!\!\!\!\!\!\!\!\!\!\!s_{i}s_{j}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In D dimensions with periodic boudnary conditions, each lattice cell has 2D neighbours.&lt;br /&gt;
&lt;br /&gt;
For the minimum energy interactions, all &amp;lt;math&amp;gt;s_{i}s_{j}&amp;lt;/math&amp;gt; pairs are spin aligned such that &amp;lt;math&amp;gt;s_{i}s_{j} = 1&amp;lt;/math&amp;gt; for all &amp;lt;math&amp;gt;i&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;j&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Therefore, &amp;lt;math&amp;gt;\displaystyle\sum_{j\;\in\;{neighbours}\;(i)} \!\!\!\!\!\!\!\!\!\!\!\!s_{i}s_{j} = 2D &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
It follows that &amp;lt;math&amp;gt;\displaystyle\sum_{i}^{N} 2D = 2DN&amp;lt;/math&amp;gt; &lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;E_{min} = -\frac{1}{2}J2DN = - DNJ &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The entropy of a given lattice configuration is given by:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;S_{min} = k\; ln\; \Omega &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For a given lattice energy, &amp;lt;math&amp;gt; \Omega &amp;lt;/math&amp;gt; is the total number of configurations which will give this energy. configuration may be achieved. In the case of the minimum energy configuration, which may be achieved with all spins or all spins down, &amp;lt;math&amp;gt; \Omega = 2 &amp;lt;/math&amp;gt;. Therefore,&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; S_{E_{min}}  = k_{B}\; ln\; 2 = 0.693k_{B} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Calculating energy and entropy changes ==&lt;br /&gt;
&#039;&#039;&#039;What is the energy change from the lowest energy configuration when a single spin &amp;quot;flips&amp;quot;? What is the entropy change? (&amp;lt;math&amp;gt; D = 3, N = 1000 &amp;lt;/math&amp;gt;)&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\Delta{E} = E_1 - E_0&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;E_1&amp;lt;/math&amp;gt; One lattice cell spin flipped&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;E_0&amp;lt;/math&amp;gt; Lowest energy configuration&lt;br /&gt;
&lt;br /&gt;
[[Image:Task 2 table.PNG]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\displaystyle\sum_{interactions} = -2D + 2D(2D-2) + 2D[N-(2D+1)] &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; = 2DN - 8D &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;E_1 = \displaystyle-\frac{1}{2}J\;\sum_{int} = 4DJ - DNJ&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\Delta{E} = +4DJ = +12J&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Energy difference is independent of the number of lattice cells&lt;br /&gt;
&lt;br /&gt;
In this calculation, the following assumption has been made.&lt;br /&gt;
&lt;br /&gt;
* The lattice dimensions are infinite relative to the size of each cell&lt;br /&gt;
&lt;br /&gt;
This allows &#039;&#039;&#039;any&#039;&#039;&#039; cell to be treated as the centre of the lattice. In other words, it is possible to shift the lattice such that a cell initially at the lattice boundary is moved to the centre. This is justified by the periodic boundary conditions of the Ising model and in turn justifies this calculation&#039;s independence of N.&lt;br /&gt;
&lt;br /&gt;
Entropy Change&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; S = k_{B}\; ln\; \Omega &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\Omega = \displaystyle\frac{N!}{{N_{\uparrow}!}{N_{\downarrow}!}}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Where &amp;lt;math&amp;gt;N_{i}!&amp;lt;/math&amp;gt; denotes the factorial of the number of spins in spin state &amp;lt;math&amp;gt;i&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\Delta{S} = k_{B}\;ln\;\left(\displaystyle\frac{\Omega_{2}}{\Omega_{1}}\right)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\Omega_{2} = \frac{1000!}{999!1!} = 1000&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \Omega_{1} = \frac{1000!}{1000!} = 1&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\Delta{S} = k_{B}\;ln\;1000 = 9.54 \times 10^{-23} JK^{-1}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\Delta{S_{mol}} = N_{A}k_{B}\;ln\;1000 = 57.4 \,JK^{-1}mol^{-1}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Magnetisation Values of 1D and 2D Lattices===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;M_{1D} =\;\;+1&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;M_{2D} =\;\;+1&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
At 0K, no thermal energy is available to overcome the energetic barriers to spin flipping. Thus the energetic driving forces dominates the entropic driving force; for an Ising Lattice with D =  3, N = 1000 at 0K, the lowest energy configuration is achieved when all spins are parallel. This resutls in the maximum number of coupling interactions between spins.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;M_{expected} =  1000&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Calculating the Energy and Magnetisation =&lt;br /&gt;
&lt;br /&gt;
[[File:First_Ene_Method.PNG]]&lt;br /&gt;
&lt;br /&gt;
[[File:First_Mag_Method.PNG]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:ILChecks.PNG]]&lt;br /&gt;
&lt;br /&gt;
= Introduction to the Monte Carlo Simulation =&lt;br /&gt;
===Configurations Available to a 100 Spin System===&lt;br /&gt;
For a system of two spins, 4 configurations are possible (↑↑, ↓↓, ↑↓, ↓↑) i.e. &amp;lt;math&amp;gt;2^{2}&amp;lt;/math&amp;gt;. For a system of 100 spins, &amp;lt;math&amp;gt;2^{100}&amp;lt;/math&amp;gt; configurations are expected. In the first example, the ↑↑ and ↓↓ are degenerate, as are the ↑↓ and ↓↑ configurations. Therefore, dividing the number of possible configurations by the multiplicity of each configuration (&amp;lt;math&amp;gt;2&amp;lt;/math&amp;gt;) gives the number of distinguishable configurations.&lt;br /&gt;
For 100 spins, this gives &amp;lt;math&amp;gt;\displaystyle\frac{2^{100}}{2} = 6.338 \times 10^{29} &amp;lt;/math&amp;gt; distinguishable configurations or states.&lt;br /&gt;
&lt;br /&gt;
If our computational speed allowed for &amp;lt;math&amp;gt; 1 \times 10^{9}&amp;lt;/math&amp;gt; calculations each second, the evaluation of a single value of &amp;lt;math&amp;gt;\left\langle M\right\rangle_T&amp;lt;/math&amp;gt; would last &amp;lt;math&amp;gt; 6.338 \times 10^{20} &amp;lt;/math&amp;gt; seconds or &amp;lt;math&amp;gt; 1458 &amp;lt;/math&amp;gt; times the age of the Universe!&lt;br /&gt;
&lt;br /&gt;
===Modifying IsingLattice.py===&lt;br /&gt;
&lt;br /&gt;
[[File:Monte_Carlo.PNG]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The Metropolis Monte Carlo (MMC) algorithm provides a computationally inexpensive path from random initial states to the minimum free energy states of the Ising lattices generated. First, a random 2D Ising lattice is generated. A single random spin within this lattice is &amp;quot;flipped&amp;quot; and the resulting energy change between these states is measured. If the energy change is negative, this represents a decrease in the internal energy of the system which lowers the free energy: this configuration change is accepted.&lt;br /&gt;
&lt;br /&gt;
In the case that the spin &amp;quot;flip&amp;quot; does not lower the free energy, the MMC algorithm tests this configuration change against the Boltzman factor, enabling a determination of the resulting entropy change. In the canonical (NVT) ensemble, the entropy of the system is given by&lt;br /&gt;
&lt;br /&gt;
###&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:stats.PNG]]&lt;br /&gt;
&lt;br /&gt;
===Spontaneous Magnetisation===&lt;br /&gt;
&lt;br /&gt;
Below the Curie Temperature, &amp;lt;math&amp;gt; T_{C} &amp;lt;/math&amp;gt;, energetic driving forces dominate entropic driving forces. Therefore, the spins of the system align in order to maximise favourable interactions rather than adopting a less ordered configuration, which would maximise multiplicity (and thus entropy).&lt;br /&gt;
Below &amp;lt;math&amp;gt;T &amp;lt; T_C&amp;lt;/math&amp;gt;, the most probable configurations have an overall magnetisation resulting in &amp;lt;math&amp;gt;\left\langle M\right\rangle \neq 0&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
The plots of magnetisation per spin and energy per spin obtained from ILanim.py upon system equilibration show that at minimum energy per spin &amp;lt;math&amp;gt;E_{min_{spin}} = \frac{-NDJ}{N} = -DJ = -2&amp;lt;/math&amp;gt;, the magnitude of the overall magnetisation per spin is at a maximum &amp;lt;math&amp;gt;|M_{spin}| = 1&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:2T=1.0.png]]&lt;br /&gt;
[[File:T=1.0.png]]&lt;br /&gt;
[[File:3T=1.0.png]]&lt;br /&gt;
&lt;br /&gt;
==Accelerating the Code==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Initial Method Speeds===&lt;br /&gt;
Taking 10 repeat measurements for the time taken to perform 2000 Monte Carlo steps resulted in&lt;br /&gt;
&lt;br /&gt;
* An average time of  &amp;lt;math&amp;gt;11.7s&amp;lt;/math&amp;gt; &lt;br /&gt;
* A standard error of &amp;lt;math&amp;gt;0.020s&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Updating Measurement===&lt;br /&gt;
&lt;br /&gt;
NOTE: ILtimetrial.py has been modified to:&lt;br /&gt;
* Perform a requested number of &#039;2000 Monte Carlo Step&#039; measurements&lt;br /&gt;
* Record these measurements in a CSV file&lt;br /&gt;
* Return the mean measuremd time and the Standard Error i.e.   &amp;lt;math&amp;gt; \frac{\sigma}{n} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:TimeTrialMethod.PNG]]&lt;br /&gt;
&lt;br /&gt;
===Updating Energy and Magnetisation Methods===&lt;br /&gt;
[[File:New_Mag_Method.PNG]]&lt;br /&gt;
[[File:New_Ene_Method.PNG]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Updated Method Speeds===&lt;br /&gt;
[[File:TimeTrial.PNG]]&lt;br /&gt;
&lt;br /&gt;
Taking 30 measurements of the time taken to perform 2000 Monte Carlo Steps resulted in:&lt;br /&gt;
&lt;br /&gt;
* An average time of &amp;lt;math&amp;gt;\displaystyle{0.87s}&amp;lt;/math&amp;gt;&lt;br /&gt;
* A standard error of &amp;lt;math&amp;gt;2.5 \times 10^{-3}s&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This represents a &#039;&#039;&#039;INSERT&#039;&#039;&#039;% decrease in computation time from the initial methods.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==The Effect of Temperature==&lt;br /&gt;
&lt;br /&gt;
===Correcting the Averaging  Code===&lt;br /&gt;
&lt;br /&gt;
To quickly find a value for &amp;lt;math&amp;gt; N_{d}&amp;lt;/math&amp;gt;, the minimum number of cycles typically needed for the equilibration of a system of within the lattice and temperature ranges of interest, it was assumed that:&lt;br /&gt;
&lt;br /&gt;
* Larger lattices would require more Monte Carlo steps to reach equilibrium from their initial, random configurations&lt;br /&gt;
&lt;br /&gt;
* Lattices at lower temperatures would require more Monte Carlo steps to reach equilibrium from their initial, random configurations.&lt;br /&gt;
&lt;br /&gt;
Therefore, an initial value for &amp;lt;math&amp;gt; N_{d}&amp;lt;/math&amp;gt; was found for a &amp;lt;math&amp;gt; 128\times128 &amp;lt;/math&amp;gt; lattice at a temperature of &amp;lt;math&amp;gt;0.5&amp;lt;/math&amp;gt; reduced temperature units.&lt;br /&gt;
*&amp;lt;math&amp;gt; N_{d} = 185000 &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
By this number of steps, all smaller lattices at all higher temperatures were found to have equilibrated also. Thus, this value of&amp;lt;math&amp;gt; N_{d}&amp;lt;/math&amp;gt; was accepted as an appropriate delay.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:AFinFrame 128 3e5 T= 0.5line.png|400px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
For the 128x128 lattices at T=0.5, equilibration was ensured from 185000 steps onwards.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Smaller lattices at the same temperature did indeed equilibrate more slowly, but all equilibrated within &amp;lt;math&amp;gt; N_{d}&amp;lt;/math&amp;gt; MC steps.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:AFinFrame 64 3e5 T= 0.5line.png|400px]]&lt;br /&gt;
[[File:AFinFrame 32 3e5 T= 0.5line2.png|400px]]&lt;br /&gt;
[[File:AFinFrame 16 3e5 T= 0.5line2.png|400px]]&lt;br /&gt;
[[File:AFinFrame 8 3e5 T= 0.5line.png|400px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The figure below shows the modifications made to IsingLattice.py to incorporate the &amp;lt;math&amp;gt; N_{d} &amp;lt;/math&amp;gt; step delay.&lt;br /&gt;
&lt;br /&gt;
===Running over a Range of Temperatures===&lt;br /&gt;
&lt;br /&gt;
To examine the effect of temperature on the average energy &amp;lt;math&amp;gt; \left\langle E\right\rangle &amp;lt;/math&amp;gt; and average magnetisation &amp;lt;math&amp;gt; \left\langle M\right\rangle &amp;lt;/math&amp;gt; of Ising lattices at equilibrium, the following parameters were used:&lt;br /&gt;
&lt;br /&gt;
* Temperature Range: &amp;lt;math&amp;gt;  0.5 - 5 &amp;lt;/math&amp;gt; reduced units&lt;br /&gt;
* Temperature Interval: &amp;lt;math&amp;gt;0.01&amp;lt;/math&amp;gt; reduced units (&amp;lt;math&amp;gt;450&amp;lt;/math&amp;gt; temperature values)&lt;br /&gt;
* Number of MMC Steps per Temperature value: &amp;lt;math&amp;gt; 2 \times 10^5 &amp;lt;/math&amp;gt; with the aforementioned value of &amp;lt;math&amp;gt; N_{d} = 1.85 \times 10^5 &amp;lt;/math&amp;gt; Monte Carlo steps&lt;br /&gt;
* Lattice Sizes:  &amp;lt;math&amp;gt; 2 \times 2 &amp;lt;/math&amp;gt;, &amp;lt;math&amp;gt; 4 \times 4 &amp;lt;/math&amp;gt; , &amp;lt;math&amp;gt; 8 \times 8 &amp;lt;/math&amp;gt; , &amp;lt;math&amp;gt; 16 \times 16 &amp;lt;/math&amp;gt; , &amp;lt;math&amp;gt; 32 \times 32 &amp;lt;/math&amp;gt; , &amp;lt;math&amp;gt; 64 \times 64 &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Plots of  &amp;lt;math&amp;gt; \left\langle E\right\rangle &amp;lt;/math&amp;gt; and  &amp;lt;math&amp;gt; \left\langle M\right\rangle &amp;lt;/math&amp;gt; per spin as versus temperature are presented below for each lattice size. Errorbars have been implemented to demonstrate how &#039;&#039;well-behaved&#039;&#039; lattice systems of each size are at each temperature, that is, how temperature and lattice size affect the size of the variations in the expected values. For the error calculations, the standard errors, &amp;lt;math&amp;gt; \sigma_\bar{X} &amp;lt;/math&amp;gt;,  in &amp;lt;math&amp;gt; \left\langle E\right\rangle &amp;lt;/math&amp;gt; and  &amp;lt;math&amp;gt; \left\langle M\right\rangle &amp;lt;/math&amp;gt; per spin have been used:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====8x8====&lt;br /&gt;
&lt;br /&gt;
[[File:8x8e+error.png]] [[File:8x8m+error.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
A Python script has been written to generate a plot of &amp;lt;math&amp;gt;\left\langle E\right\rangle&amp;lt;/math&amp;gt; or &amp;lt;math&amp;gt;\left\langle M\right\rangle&amp;lt;/math&amp;gt; against temperature based upon user input. A screenshot of this code has been inserted below.&lt;br /&gt;
&lt;br /&gt;
[[File:ExpectedvsTemp.PNG|200px]]&lt;br /&gt;
&lt;br /&gt;
===Scaling the System Size===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====2x2====&lt;br /&gt;
[[File:2x2e+error.png]] [[File:2x2m+error.png]]&lt;br /&gt;
&lt;br /&gt;
====4x4====&lt;br /&gt;
[[File:4x4e+error.png]] [[File:4x4m+error.png]]&lt;br /&gt;
&lt;br /&gt;
====16x16====&lt;br /&gt;
[[File:16x16e+error.png]] [[File:16x16m+error.png]]&lt;br /&gt;
&lt;br /&gt;
====32x32====&lt;br /&gt;
[[File:32x32e+error.png]] [[File:32x32m+error.png]]&lt;br /&gt;
&lt;br /&gt;
====64x64====&lt;br /&gt;
[[File:64x64e+error.png]] [[File:64x64m+error.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Determining the Heat Capacity==&lt;br /&gt;
&lt;br /&gt;
===Calculating the Heat Capacity===&lt;br /&gt;
Working in the canonical ensemble (constant volume), the heat capacity &amp;lt;math&amp;gt; C_V &amp;lt;/math&amp;gt; is given by:&lt;br /&gt;
&lt;br /&gt;
:&amp;lt;math&amp;gt;C_V = \frac{\partial \left\langle E\right\rangle}{\partial T}_V&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
where &amp;lt;math&amp;gt;\left\langle E\right\rangle&amp;lt;/math&amp;gt; is the average total energy or expected value of the internal energy of the system.&lt;br /&gt;
&lt;br /&gt;
: &amp;lt;math&amp;gt; \left\langle E\right\rangle = - \frac{\partial ln Q}{\partial \beta} = -\frac{1}{Q}\frac{\partial Q}{\partial \beta} &amp;lt;/math&amp;gt;&lt;br /&gt;
where &amp;lt;math&amp;gt; Q&amp;lt;/math&amp;gt; is the partition function for the system of N interacting spins.&lt;br /&gt;
&lt;br /&gt;
By evaluating the second form of the partial derivative with respect to &amp;lt;math&amp;gt; \beta&amp;lt;/math&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \left\langle E\right\rangle = -\frac{1}{Q}\frac{\partial Q}{\partial \beta} = \frac{\Sigma \epsilon_{i} e^{-\beta \epsilon_{i}}}{\Sigma e^{-\beta \epsilon_{i}}} &amp;lt;/math&amp;gt; &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Applying the product rule enables the differentiation of this expression for &amp;lt;math&amp;gt;\left\langle E\right\rangle&amp;lt;/math&amp;gt; with respect to temperature, giving:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\frac{\partial \left\langle E\right\rangle}{\partial T} = \frac{\Sigma \epsilon_{i} \frac{\epsilon_i}{k_BT^2}e^{-\beta \epsilon_{i}}}{\Sigma e^{-\beta \epsilon_{i}}} - \frac{\Sigma \epsilon_i e^{-\beta \epsilon_i}\cdot \frac{\epsilon_i}{k_BT^2}e^{-\beta \epsilon_i}}{(\Sigma e^{-\beta \epsilon_{i}})^2}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\frac{\partial \left\langle E\right\rangle}{\partial T}  = \frac{1}{k_BT^2}\left[\frac{\Sigma \epsilon_i^2 e^{-\beta \epsilon_i}}{\Sigma e^{-\beta \epsilon_i}} - \left(\frac{\Sigma \epsilon_{i} e^{-\beta \epsilon_{i}}}{\Sigma e^{-\beta \epsilon_{i}}}\right)^2\right] &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\frac{\partial \left\langle E\right\rangle}{\partial T}  = \frac{1}{k_BT^2}\left[\left\langle E^2\right\rangle - \left\langle E\right\rangle^2 \right] &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Thus,&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\frac{\partial \left\langle E\right\rangle}{\partial T} = \frac{Var[E]}{k_BT^2} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Heat Capacity versus Temperature===&lt;br /&gt;
&lt;br /&gt;
====2x2====&lt;br /&gt;
[[File:HC2.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====4x4====&lt;br /&gt;
[[File:H4.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====8x8====&lt;br /&gt;
[[File:HC8.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====16x16====&lt;br /&gt;
[[File:HC16.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====32x32====&lt;br /&gt;
[[File:HC32.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Python Scripts ===&lt;/div&gt;</summary>
		<author><name>Jj1516</name></author>
	</entry>
</feed>