Solution (source code)

= Solution

Introduce independent fast and slow times
$$
t_0=t,
\qquad
T=\epsilon t,
$$
and seek $u=u_0+\epsilon u_1+\cdots$. Then
$$
\frac d{dt}=\partial_{t_0}+\epsilon\partial_T,
\qquad
\frac{d^2}{dt^2}
=\partial_{t_0}^2
+2\epsilon\partial_{t_0T}+O(\epsilon^2).
$$
At leading order,
$$
u_{0,t_0t_0}+u_0=0,
$$
so write
$$
u_0=R(T)\cos\theta,
\qquad
\theta=t_0+\phi(T).
$$
At order $\epsilon$,
$$
u_{1,t_0t_0}+u_1
=f(u_0,u_{0,t_0},T)
+2R'\sin\theta
+2R\phi'\cos\theta.
$$
The <solvability condition in the method of multiple scales> removes the resonant sine and cosine components. Averaging over one fast period gives the <amplitude-phase equations for a weakly perturbed oscillator>
$$
\boxed{
\frac{dR}{dT}
=-\langle f\sin\theta\rangle},
\qquad
\boxed{
R\frac{d\phi}{dT}
=-\langle f\cos\theta\rangle}.
$$
\b[Therefore $u\sim R(T)\cos[t+\phi(T)]$ without the secular growth that a single-time expansion would produce.]