<s>[INST] Integration of a equation $$\int_{x}^{y}\left[\sum_{i=1}^{N}\sqrt{a}\cos\left(\frac{2\pi(d_{i}-a)}{\lambda} \right)\right]^{\!2}da$$
Can anyone solve this integration for me
I don't know how the summation and integration will behave with each other
 [/INST] You have to square the sum first. Note that the $\sqrt{a}$ is common to all terms in
$$\sqrt{a}\cos\left(\frac{2\pi(d_{i}-a)}{\lambda} \right)\cdot \sqrt{a}\cos\left(\frac{2\pi(d_{j}-a)}{\lambda} \right),$$
so it can factor out as $a.$ That is, we have
$$\int_{x}^{y}a\left[\sum_{i=1}^{N}\cos\left(\frac{2\pi(d_{i}-a)}{\lambda} \right)\right]^{\!2}da.$$
We must now square the sum in order to proceed:
\begin{align*}
&\phantom{=}\left[\sum_{i=1}^{N}\cos\left(\frac{2\pi(d_{i}-a)}{\lambda} \right)\right]^{\!2}\\
&=\sum_{i,j=1}^{N}\cos\left(\frac{2\pi(d_i-a)}{\lambda} \right)\cos\left(\frac{2\pi(d_j-a)}{\lambda} \right)\\
&=\sum_{i,j=1}^{N}\cos\left(\frac{2\pi d_i}{\lambda}-\frac{2\pi a}{\lambda} \right)\cos\left(\frac{2\pi d_j}{\lambda}-\frac{2\pi a}{\lambda}\right)\\
&=\frac12\sum_{i,j=1}^{N}\left[\cos\left(\frac{2\pi d_i}{\lambda}-\frac{2\pi d_j}{\lambda} \right)+\cos\left(\frac{2\pi d_i}{\lambda}+\frac{2\pi d_j}{\lambda}-\frac{4\pi a}{\lambda}\right)\right]\\
&=\frac12\sum_{i,j=1}^{N}\left[\cos\left(\frac{2\pi(d_i-d_j)}{\lambda}\right)+\cos\left(\frac{2\pi(d_i+d_j)}{\lambda}-\frac{4\pi a}{\lambda}\right)\right].
\end{align*}
Now we can move the integral inside the sum:
\begin{align*}
\int&=\int_x^y\frac{a}{2}\sum_{i,j=1}^{N}\left[\cos\left(\frac{2\pi(d_i-d_j)}{\lambda}\right)+\cos\left(\frac{2\pi(d_i+d_j)}{\lambda}-\frac{4\pi a}{\lambda}\right)\right]da\\
&=\frac12\sum_{i,j=1}^{N}\int_x^y a\left[\cos\left(\frac{2\pi(d_i-d_j)}{\lambda}\right)+\cos\left(\frac{2\pi(d_i+d_j)}{\lambda}-\frac{4\pi a}{\lambda}\right)\right]da\\
&=\frac12\sum_{i,j=1}^{N}\left[\int_x^y a\cos\left(\frac{2\pi(d_i-d_j)}{\lambda}\right)da+\int_x^ya\cos\left(\frac{2\pi(d_i+d_j)}{\lambda}-\frac{4\pi a}{\lambda}\right)da\right].
\end{align*}
To continue, we note that according to the comments, there exists $k,\;1\le k\le N$ such that $d_k=a.$ Without loss of generality, we will just assume that $k=N,$ so that $d_N=a.$ Now with the double-sum over $i$ and $j,$ we have four cases to deal with:

*

*$i\not=N, j\not=N.$ The integral is then
\begin{align*}
&\phantom{=}\frac12\sum_{i,j=1}^{N-1}\left[\int_x^y a\cos\left(\frac{2\pi(d_i-d_j)}{\lambda}\right)da+\int_x^ya\cos\left(\frac{2\pi(d_i+d_j)}{\lambda}-\frac{4\pi a}{\lambda}\right)da\right]\\
&=\frac12\sum_{i,j=1}^{N-1}\Bigg[\left(\frac{y^2}{2}-\frac{x^2}{2}\right)\cos\left(\frac{2\pi(d_i-d_j)}{\lambda}\right)\\
&\qquad+\int_x^ya\cos\left(\frac{2\pi(d_i+d_j)}{\lambda}-\frac{4\pi a}{\lambda}\right)da\Bigg]
\end{align*}

*$i\not=N, j=N.$ For this case, there are $N-1$ terms, and the integral is
\begin{align*}
&\phantom{=}\frac12\sum_{i=1}^{N-1}\left[\int_x^y a\cos\left(\frac{2\pi(d_i-a)}{\lambda}\right)da+\int_x^ya\cos\left(\frac{2\pi(d_i+a)}{\lambda}-\frac{4\pi a}{\lambda}\right)da\right]\\
&=\frac12\sum_{i=1}^{N-1}\left[\int_x^y a\cos\left(\frac{2\pi(d_i-a)}{\lambda}\right)da+\int_x^ya\cos\left(\frac{2\pi(d_i-a)}{\lambda}\right)da\right]\\
&=\sum_{i=1}^{N-1}\int_x^y a\cos\left(\frac{2\pi(d_i-a)}{\lambda}\right)da.
\end{align*}

*$i=N, j\not=N.$ For this case, there are $N-1$ terms, and the integral is
\begin{align*}
&\phantom{=}\frac12\sum_{j=1}^{N-1}\left[\int_x^y a\cos\left(\frac{2\pi(a-d_j)}{\lambda}\right)da+\int_x^ya\cos\left(\frac{2\pi(a+d_j)}{\lambda}-\frac{4\pi a}{\lambda}\right)da\right]\\
&=\frac12\sum_{j=1}^{N-1}\left[\int_x^y a\cos\left(\frac{2\pi(d_j-a)}{\lambda}\right)da+\int_x^ya\cos\left(\frac{2\pi(d_j-a)}{\lambda}\right)da\right]\\
&=\sum_{j=1}^{N-1}\int_x^y a\cos\left(\frac{2\pi(d_j-a)}{\lambda}\right)da.
\end{align*}
This is the same expression as in Case 2, so we can consolidate these two cases into one case that's doubled: Case 2 and 3:
$$2\sum_{j=1}^{N-1}\int_x^y a\cos\left(\frac{2\pi(d_j-a)}{\lambda}\right)da.$$

*$i=j=N.$ For this case, there's only $1$ term, and the integral is
$$\frac12\left[\int_x^y a\,da+\int_x^ya\,da\right]=\int_x^ya\,da=\frac{y^2}{2}-\frac{x^2}{2}.$$
This is getting rather unwieldy to continue writing down. I would just remark that the integral
$$\int_x^y a\cos(c+a)\,da=\cos(c+y)+y\sin(c+y)-\cos(c+x)-x\sin(c+x).$$
All the remaining integrals are of this form. I'll let you finish.
</s>