"Look at the implementation of the discrete Fourier transform above. You can see that as we have a double nested loop, each with $N$ elements, the implementation will scale with O($N^2$).\n",

"\n",

"The Fast Fourier Transform (FFT) algorithm is based on a clever reorganisation of the nested sum that improves the scaling to O($N\\log N$). The method originally relied on $N$ being a power of 2 so that the summation could be repeatedly broken down into smaller parts. It has been steadily generalized since then, so that even prime values of $N$ can achieve O($N\\log N$) scaling.\n",

"The Fast Fourier Transform (FFT) algorithm is based on a clever reorganisation of the nested sum that improves the scaling to $\\mathrm{O}(N\\log N$). The method originally relied on $N$ being a power of 2 so that the summation could be repeatedly broken down into smaller parts. It has been steadily generalized since then, so that even prime values of $N$ can achieve O($N\\log N$) scaling.\n",

"\n",

"The FFT will produce exactly the same output as the naive implementation above, but allows significantly larger data sets to be used.\n",

"\n",

...

...

@@ -245,9 +233,7 @@

{

"cell_type": "code",

"execution_count": null,

"metadata": {

"collapsed": true

},

"metadata": {},

"outputs": [],

"source": [

"n = 20; f= 0.1; p = np.pi * 0; t = 1;\n",

...

...

@@ -290,9 +276,7 @@

{

"cell_type": "code",

"execution_count": null,

"metadata": {

"collapsed": true

},

"metadata": {},

"outputs": [],

"source": [

"import scipy.fftpack\n",

...

...

@@ -343,7 +327,7 @@

"\n",

"If we have some distribution of electrons $n(r)$ in a periodic system, it's common to calculate the their electrostatic interaction with each other as a single term contributing to the total energy of the system (along with several other terms depending on what method is being used). This is usually referred to as the Hartree term and is given by:\n",

"\\mathbf d\\mathbf r \\mathbf d\\mathbf r' $$\n",

"\\mathbf d\\mathbf r \\mathbf d\\mathbf r'. $$\n",

"\n",

"As you might imagine, this term when considered in isolation, diverges since it only considers the negative electrons and we have a periodic (infinitely repeating) system. You can see this if you consider a one dimensional system consisting of a chain of equal charges, $q$, per cell of dimension $a$, and each charge at position $x$ within its cell. The energy of these charges interacting with each other if we consider $N$ neighbouring cells is given by\n",