# Solve the ODE using complex variables

$$y''+4y=1+\cos2x$$ The homogeneous solution is $$y_H=A\cos 2x+B\sin 2x$$ I'm strugling to find the correct trial solution for the inhomogeneous part of the ODE. $y_P=Ce^{2ix}$ does not work because the constant cancels out after inputing the solution into the ODE (and the real part is already a fundamental solution of the ODE). $y_P=Cxe^{2ix}$ leaves me with $Ce^{2ix}(4iC-1)=1$.

I could, of course, splitthe ODE into two inhomogeneous ODEs, solve for them, and sum their solution for the particular solution of the initial ODE, but that's not the point of this exercise.

• @WillJagy I tried that before, it only accounts for the $\cos{2x}$ term, so it only works if I separate the ODE into one with $\cos{2x}$ and one with $1$. Commented May 17, 2018 at 0:31
• You will also need to address that $1$ on the right hand side. But it is quick to observe that adding a $1/4$ to your general solution should do the job in addition to Will's suggestion Commented May 17, 2018 at 0:32
• @WillJagy so it would seem that this works. However, I still seek an approach using complex variables. Commented May 17, 2018 at 0:35
• $Cx e^{2ix} + Dx e^{-2ix} + F$ Commented May 17, 2018 at 0:37
• @WillJagy Thank you. Commented May 17, 2018 at 0:38

The equation you have is the real part of

$$z'' + 4z = 1 + e^{2ix}$$

where $z$ is complex-valued and $y$ is the real part of $z$. Since $e^{2ix}$ is already a homogeneous solution, you will need to have a particular solution of the form

$$z_p(x) = A + Bxe^{2ix}$$

Taking derivatives \begin{align} {z_p}' &= B\big[e^{2ix} + 2ixe^{2ix}\big] = B(1+2ix)e^{2ix} \\ {z_p}'' &= B\big[2ie^{2ix} + 2i(1+2ix)e^{2ix}\big] = B(4i-4x)e^{2ix} \end{align}

Plugging this in, we find $${z_p}'' + 4{z_p} = 4A + 4iBe^{2ix} = 1 + e^{2ix}$$

this gives $$A = \frac14, \ B = \frac{1}{4i}=-\frac{i}{4}$$

Then

\begin{align} z_p(x) &= \frac14 - \frac{i}{2}xe^{2ix}\\ &= \frac14 - \frac{i}{4}x\big[\cos 2x + i\sin 2x\big] \\ &= \frac14 + \frac{1}{4}x\sin 2x - i\frac{1}{2}x\cos 2x \end{align}

Taking the real part $$y_p(x) = \frac14 + \frac{1}{4}x\sin 2x$$

$\newcommand{\bbx}[1]{\,\bbox[15px,border:1px groove navy]{\displaystyle{#1}}\,} \newcommand{\braces}[1]{\left\lbrace\,{#1}\,\right\rbrace} \newcommand{\bracks}[1]{\left\lbrack\,{#1}\,\right\rbrack} \newcommand{\dd}{\mathrm{d}} \newcommand{\ds}[1]{\displaystyle{#1}} \newcommand{\expo}[1]{\,\mathrm{e}^{#1}\,} \newcommand{\ic}{\mathrm{i}} \newcommand{\mc}[1]{\mathcal{#1}} \newcommand{\mrm}[1]{\mathrm{#1}} \newcommand{\pars}[1]{\left(\,{#1}\,\right)} \newcommand{\partiald}[3][]{\frac{\partial^{#1} #2}{\partial #3^{#1}}} \newcommand{\root}[2][]{\,\sqrt[#1]{\,{#2}\,}\,} \newcommand{\totald}[3][]{\frac{\mathrm{d}^{#1} #2}{\mathrm{d} #3^{#1}}} \newcommand{\verts}[1]{\left\vert\,{#1}\,\right\vert}$

Lets $\ds{\xi \equiv y' + 2\ic y\quad}$ such that $\ds{\quad y = {1 \over 2}\,\Im\pars{\xi}}$.

$\ds{\xi' = y'' + 2\ic y' = \pars{y'' + 4y} + 2\ic\pars{y' + 2\ic y} = \pars{y'' + 4y} + 2\ic\xi}$

$\ds{\implies \bbx{y'' + 4y = \xi' - 2\ic\xi = 1 + \cos\pars{2x}}}$.

\begin{align} \totald{\pars{\expo{-2\ic x}\xi}}{x} & = \expo{-2\ic x} + \expo{-2\ic x}\cos\pars{2x} \\[5mm] \expo{-2\ic x}\xi & = {1 \over 2}\,\ic\expo{-2\ic x} + {1 \over 8}\,\ic\expo{-4\ic x} + {1 \over 2}\,x + 2a\,, \qquad\pars{a \in \mathbb{C}\ \mbox{is a}\ constant} \\[5mm] \xi & = {1 \over 2}\,\ic + {1 \over 8}\,\ic\expo{-2\ic x} + {1 \over 2}\,x\expo{2\ic x} + 2a\expo{2\ic x} \\[5mm] y & = \bbx{{1 \over 4} + {1 \over 16}\,\cos\pars{2x} + {1 \over 4}\,x\sin\pars{2x} + \Im\pars{a\expo{2\ic x}}} \end{align}

Lets $\ds{a \equiv a_{r} + \ic a_{i}}$ with $\ds{a_{r}, a_{i} \in \mathbb{R}}$.

Then, \begin{align} y & = {1 \over 4} + {1 \over 16}\,\cos\pars{2x} + {1 \over 4}\,x\sin\pars{2x}\ +\ \overbrace{\quad\bracks{\rule{0pt}{5mm}a_{r}\sin\pars{2x} + a_{i}\cos\pars{2x}}\quad}^{\ds{Particular\ Solution}} \\[5mm] & a_{r}\ \mbox{and}\ a_{i}\ \mbox{are}\ determined\ \mbox{by the}\ Initial\ Conditions. \end{align}

• @LutzL Thanks. Fixed. $Particular\ Solution$ is the solution of the homogeneous equation. Commented May 17, 2018 at 21:07
• I meant that the $-\frac1{16}\sin(2x)$ only constitute a change of the constant $a_r$. You pick one particular solution of the inhomogeneous equation, then any other solution differs by a solution of the homogeneous equation. Commented May 17, 2018 at 22:57
• @LutzL Yes. You can make the change $\displaystyle a_{i} + {1 \over 16} \mapsto a_{i}$. Any way, the remaining constants are found once you set a particular initial condition ( like $\displaystyle y\left(0\right)$ and $\displaystyle y'\left(0\right)$, for example ). Commented May 17, 2018 at 23:25