The differential equation for a forced undamped oscillator has the form $$\mathcal{L}x\equiv \frac{d^2x}{dt^2}+\omega_0^2x=f(t),$$ and the Green function $G(t,t')$ defined as $$\mathcal{L}G(t,t')\equiv \left(\frac{d^2}{dt^2}+\omega_0^2\right)G(t,t')=\delta(t-t'),\tag{A}$$ and subjected to the condition $G=0$ for $t<t'$ is given by $$G(t,t')=\Theta(t-t')\frac{\sin\omega_0(t-t')}{\omega_0}.\tag{1}$$ This result can be derived using Fourier transform and the standard method of complex contour integration.
However, I am interested in the following alternative definition of Green function. I want to derive/verify the same result $(1)$, using the eigenfunction expansion formula of Green function: $$G(t,t')=\sum_{n=0}^{\infty}\frac{x_n(t)x_n(t')}{\lambda_n}.\tag{B}$$
To this end, we think of the given problem as a Strum-Liouville problem with $$\mathcal{L}x=\left(\frac{d^2}{dt^2}+\omega_0^2\right)x=-\lambda x$$ in the interval $[0,T]$ subjected to the boundary conditions $$x(t=0)=0, \quad x(t+T)=x(t)$$ where $T=2\pi/\omega_0$. We find that the eigenfunctions and the corresponding eigenvalues are given by $$x_n=A_n\sin(n\omega_0t), \quad \lambda_n=\omega_0^2(n^2-1)$$ respectively, where $n=0,\pm1,\pm 2,\ldots$. Therefore, invoking the formula for the eigenfunction expansion of Green function, we can write $$G(t,t')=\sum_{n=0}^{\infty}\frac{x_n(t)x_n(t')}{\lambda_n}=\sum_{n=0}^{\infty}A_n^2\frac{\sin(n\omega_0t)\sin(n\omega_0t')}{(n^2-1)\omega_0^2}$$ which unfortunately diverges for $n=1$.
If we assume $T$ is the periodicity of the external force and $T\neq 2\pi/\omega_0$, the eigenfunctions and eigenvalues subject to the given boundary conditions are $$x_n=A_n \sin(2\pi n t/T), \quad \lambda_n=(2\pi n/T)^2-\omega_0^2,$$ respectively. In that case, $$G(t,t')=\sum_{n=0}^{\infty}\frac{x_n(t)x_n(t')}{\lambda_n}=\sum_{n=0}^{\infty}A_n^2\frac{\sin(2\pi nt/T)\sin(2\pi nt'/T)}{(2\pi n/T)^2-\omega_0^2}\tag{2}$$ Now, the expression $(2)$ is no more divergent but it is not clear whether this expression is same as $(1)$. Presumably, they are not the same because the expression $(2)$ involves a new parameter $T$ which the expression $(1)$ did not have.
- Please help me understand the following. Why are the Green functions, in $(1)$ and in $(2)$, evaluated using two equivalent definitions, $(A)$ and $(B)$, are so different? I find it disturbing. Where am I wrong? How can we derive result $(1)$ using defintion $(B)$?
Here is the problem: you want a Green's function to find the solution to the forced undamped harmonic oscillator, $$ \ddot{x}(t)+\omega_0^2\,x(t)=f(t), \tag{1} $$ subjected to the conditions $x(0)=0$ and $x(t+T)=x(t)$. Such a solution exists$^{(*)}$ if $f$ is $T$-periodic and $T\neq\frac{2\pi}{\omega_0}$, but it may not exist if $T=\frac{2\pi}{\omega_0}$. For instance, the general solution to $(1)$ if $f(t)=f_0\sin(\omega_0t)$ is $$ x(t) = A\cos(\omega_0 t) + B\sin(\omega_0 t) - \frac{f_0}{2\omega_0}t\sin(\omega_0 t), \tag{2} $$ which satisfies $x(0)=0$ if $A=0$, but there is no value of $B$ for which $x(t+T)=x(t)$.
Finally, notice that the derivation of the second equation in your post does not assume periodicity of the solution to the forced undamped harmonic oscillator.
$^{(*)}$ Another condition is that $f(0)=0$ as well. For instance, the general solution to $(1)$ if $f(t) = f_0\cos(\omega t)$ is $$ x(t) = A\cos(\omega_0 t) + B\sin(\omega_0 t) + \frac{f_0}{\omega_0^2-\omega^2}\cos(\omega t). \tag{3} $$ If we make $A=B=0$ in $(3)$, then $x(t+T)=x(t)$ (with $T=\frac{2\pi}{\omega}$), but $x(0)\neq 0$. On the other hand, we can make $x(0)=0$ if we choose $A = -f_0/(\omega_0^2-\omega^2)$, but then $x(t)$ will not be $T$-periodic if $\omega_0/\omega$ is not integer.
EDITED: Footnote added.