Solution of $y''+4y=\cos^2t$ I'm trying to find the solution, which is supposed to be 
$y(t)=c_2\sin(2t)+c_1\cos(2t)+\frac{t\sin(2t)}{8}+\frac{\cos^2(t)}{4}$,
but I'm doing something wrong along the way and I can't figure out what I did.  I was hoping someone would be able to find my mistake for me.  I'll show what I've gotten:
First I got the complementary solution $y_c(t)=c_1\cos(2x)+c_2\cos(2x)$
I then used the particular solution $y_p=A+B\cos(2t)+C\sin(2t)$ - I'm guessing this is where my error occurs, but I don't see what's wrong with it.
I derived it two times and got $y_p''=-4B\cos2t-4C\sin(2t)$
I plugged it into the original equation (assuming $\cos^2t$ is $\frac{1}{2}+\frac{\cos(2x)}{2}$) and then tried to solve the problem, at which point I found myself running in circles:
$\sin2t(-4C-4C)+\cos2t(-4B+4B)+4A=\frac{1}{2}+\frac{\cos(2x)}{2}$.
Can anyone help me find my mistake(s)?  Thanks a lot.
 A: You figured out the issue with:
$$y_c(t) = c_1 \cos 2t + c_2 \sin 2t$$
For the particular solution, some care is needed given the homogeneous (complementary) solution. We expand the $\cos^2 2t$ term as:
$$\cos^2 2t = \dfrac{1}{2}\left(1 +\cos 2t\right)$$
Now, we notice that this has a common term with the homogeneous term, so we multiply the particular solution by $t$ to account for that. Thus, we choose a particular solution as:
$$y_p(t) = a + b~ t \cos 2t + c~ t \sin 2t$$
Now, substitute and solve for $a$, $b$ and $c$.
You should get:
$$a = \dfrac{1}{8}, b = 0, c = \dfrac{1}{8}$$
Your final solution will be:
$$y(t) = y_c(t) + y_p(t)$$
A: The complementary solution is 
$$y_c(t) = c_1\cos(2t) + c_2\sin(2t).$$
Notice that $t\mapsto \cos^2(t)$ is in the linear span of this solution.  What do you do in those cases?
A: $\newcommand{\+}{^{\dagger}}%
 \newcommand{\angles}[1]{\left\langle #1 \right\rangle}%
 \newcommand{\braces}[1]{\left\lbrace #1 \right\rbrace}%
 \newcommand{\bracks}[1]{\left\lbrack #1 \right\rbrack}%
 \newcommand{\dd}{{\rm d}}%
 \newcommand{\isdiv}{\,\left.\right\vert\,}%
 \newcommand{\ds}[1]{\displaystyle{#1}}%
 \newcommand{\equalby}[1]{{#1 \atop {= \atop \vphantom{\huge A}}}}%
 \newcommand{\expo}[1]{\,{\rm e}^{#1}\,}%
 \newcommand{\floor}[1]{\,\left\lfloor #1 \right\rfloor\,}%
 \newcommand{\ic}{{\rm i}}%
 \newcommand{\imp}{\Longrightarrow}%
 \newcommand{\ket}[1]{\left\vert #1\right\rangle}%
 \newcommand{\pars}[1]{\left( #1 \right)}%
 \newcommand{\partiald}[3][]{\frac{\partial^{#1} #2}{\partial #3^{#1}}}
 \newcommand{\pp}{{\cal P}}%
 \newcommand{\root}[2][]{\,\sqrt[#1]{\,#2\,}\,}%
 \newcommand{\sech}{\,{\rm sech}}%
 \newcommand{\sgn}{\,{\rm sgn}}%
 \newcommand{\totald}[3][]{\frac{{\rm d}^{#1} #2}{{\rm d} #3^{#1}}}
 \newcommand{\ul}[1]{\underline{#1}}%
 \newcommand{\verts}[1]{\left\vert #1 \right\vert}%
 \newcommand{\yy}{\Longleftrightarrow}$
$\ds{y'' + 4y = \cos^{2}t:\ {\large ?}}$

Let's define $\mu \equiv y' + 2y\ic$ such that
$$
\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!
\cos^{2}\pars{t} = y'' + 4y = \pars{\mu'' - 2y'\ic} + 4\,{\mu - y' \over 2\ic}
= 
\mu' -2\mu\ic
\quad\imp\quad
\mu' -2\mu\ic = \cos^{2}\pars{t}
\tag{1}
$$
$$
\mbox{Notice that}\quad y = {1 \over 2}\,\Im\mu \tag{2}
$$

Multiply both members of the last equation in $\pars{1}$ by the factor
$\expo{-2\ic t}$:
$$
\expo{-2\ic t}\mu' -2\mu\expo{-2\ic t}\ic = \expo{-2\ic t}\cos^{2}\pars{t}
\quad\imp\quad
\totald{\pars{\expo{-2\ic t}\mu}}{t} = \expo{-2\ic t}\cos^{2}\pars{t}
$$
$$
\expo{-2\ic t}\mu = \int\expo{-2\ic t}\cos^{2}\pars{t}\,\dd t + A
\quad\mbox{where}\quad
A \in {\mathbb C}\ \mbox{is a}\ {\it\mbox{constant}}.
\tag{3}
$$
Also
\begin{align}
\int\expo{-2\ic t}\cos^{2}\pars{t}\,\dd t
&=
\int\expo{-2\ic t}\,{1 + \cos\pars{2t} \over 2}\,\dd t
=
{1 \over 2}\bracks{%
\int\expo{-2\ic t}\,\dd t + {1 \over 2}\pars{1 + \int\expo{-4\ic t}\,\dd t}}
\\[3mm]&=
{1 \over 4}\,\ic\expo{-2\ic t} + {1 \over 4}\,t + {1 \over 16}\,\ic\expo{-4\ic t}
\end{align}
By replacing this integration in $\pars{3}$ we get:
$$
\mu
=
{1 \over 4}\ic + {1 \over 4}\,t\expo{2it} + {1 \over 16}\,\ic\expo{-2\ic t}
+
A\expo{2it} 
$$
Then $\pars{~\mbox{see Eq.}\ \pars{2}~}$
$$
y
=
{1 \over 8} + {1 \over 8}\,t\sin\pars{2t} + {1 \over 32}\,\cos\pars{2t}
+
{1 \over 2}\,\Im\bracks{A\expo{2it}} 
$$
Let's write $A = B/4 + 2\pars{C - 1/32}\,\ic$ where $B$ and $C$ are constants
$\pars{~B, C \in {\mathbb R}~}$:
$$
y
=
{1 \over 8} + {1 \over 8}\,t\sin\pars{2t} + {1 \over 32}\,\cos\pars{2t}
+
{1 \over 8}\,B\sin\pars{2t} + \pars{C - {1 \over 32}}\cos\pars{2t} 
$$
\begin{align}
&
\\[1cm]
\\
{\large y\pars{t}}
&{\large =
{1 \over 8} + {1 \over 8}\pars{t + B}\sin\pars{2t} + C\cos\pars{2t}}
\\[3mm]&
{\large B\ \mbox{and}\ C\ \mbox{are determined by the initial conditions.}}
\end{align}
Let's check it:
\begin{align}
y'\pars{t}
&=
{1 \over 8}\,\sin\pars{2t} + {1 \over 4}\pars{t + B}\cos\pars{2t}
-
2C\sin\pars{2t}
\\[3mm]
y''\pars{t}
&=
{1 \over 4}\,\cos\pars{2t} + {1 \over 4}\cos\pars{2t}
-
{1 \over 2}\pars{t + B}\sin\pars{2t}
-
4C\cos\pars{2t}
\\
{\large y''\pars{t} + 4y\pars{t}}
&=
{1 \over 4}\,\cos\pars{2t} + {1 \over 4}\cos\pars{2t}
+
{1 \over 2}
=
{1 \over 2}\bracks{1 + \cos\pars{2t}} = {\large\cos^{2}\pars{t}}
\end{align}
