How to derive the intensity formula of a diffraction grating? In the notes I have, they have a diffraction grating with $2N + 1$ slits, a slit width of $2a$ and a slit spacing of $d$. They then say that the equation for the diffraction intensity pattern is given by:
$$I = I_0
  \left( \frac{\sin((N+\frac{1}{2})kd\sin\theta)}{\sin(\frac{1}{2}kd\sin\theta)} \right)^2
  \left( \frac{\sin(ka\sin\theta)}{ka\sin\theta} \right)^2
$$
They don't, however, give any proof or reason why this is the formula. I have been looking online for a way to justify this formula but I cant find anything. Anybody have a nice proof for this?
 A: 
(image from Antonine education)
The light amplitude $E(\theta)$ into direction $\theta$ can be calculated
straight-forward by summing the contributions


*

*of all the slits ($n$ from $-N$ to $+N$)

*and of the parts of each individual slit ($x$ from $-a$ to $+a$)


The path difference of each contributing ray
(compared to the path length of the ray originating from the center of the grating)
is $(nd+x)\sin\theta$.
And hence its phase is $k(nd+x)\sin\theta$.
Summing these contributions you get
$$
\begin{align}
E(\theta)
&= E_0 \sum_{n=-N}^{+N} \int_{-a}^{+a} e^{ik(nd+x)\sin\theta} \text{d}x \\
&= E_0 \left( \sum_{n=-N}^{+N} e^{iknd\sin\theta}\right)
       \left( \int_{-a}^{+a} e^{ikx\sin\theta} \text{d}x \right) \\
&= E_0 \left( \frac{\sin((N+\frac{1}{2})kd\sin\theta)}{\sin(\frac{1}{2}kd\sin\theta)} \right)
       \left( 2a\frac{\sin(ka\sin\theta)}{ka\sin\theta} \right)
\end{align}
$$
And finally you get the intensity by taking the absolute square of the amplitude
$$I(\theta) = |E(\theta)|^2$$
