2.1004   ODE No. 1004

\[ -a \cos (b x)+y''(x)+y(x)=0 \] Mathematica : cpu = 0.0899925 (sec), leaf count = 47


\[\left \{\left \{y(x)\to \frac {-a \cos ^2(x) \cos (b x)-a \sin ^2(x) \cos (b x)}{b^2-1}+c_1 \cos (x)+c_2 \sin (x)\right \}\right \}\] Maple : cpu = 0.054 (sec), leaf count = 27


\[y \relax (x ) = \sin \relax (x ) c_{2}+\cos \relax (x ) c_{1}-\frac {a \cos \left (b x \right )}{b^{2}-1}\]

Hand solution

\begin {equation} y^{\prime \prime }+y=a\cos bx \tag {1} \end {equation} We start by solving the homogeneous equation \[ y^{\prime \prime }+y=0 \] Let \(y=e^{\lambda x}\), substitution in above gives\begin {align*} \lambda ^{2}e^{\lambda x}+e^{\lambda x} & =0\\ \lambda ^{2}+1 & =0 \end {align*}

Hence \(\lambda =\pm i\), therefore the solution is\begin {align*} y_{h} & =Ae^{ix}+Be^{-ix}\\ & =A\left (\cos x+i\sin x\right ) +B\left (\cos x-i\sin x\right ) \\ & =\cos x\left (A+B\right ) +\sin x\left (Ai-iB\right ) \\ & =\cos x\left (A+B\right ) +\sin x\left (i\left (A-B\right ) \right ) \end {align*}

Let \(A+B=c_{1},i\left (A-B\right ) =c_{2}\) hence\[ y_{h}=c_{1}\cos x+c_{2}\sin x \] Now we solve for the particular solution using variation of parameters. Let \begin {align*} y_{p} & =u_{1}\relax (x) \cos x+u_{2}\relax (x) \sin x\\ y_{p}^{\prime } & =u_{1}^{\prime }\cos x-u_{1}\sin x+u_{2}^{\prime }\sin x+u_{2}\cos x\\ & =u_{2}\cos x-u_{1}\sin x+u_{1}^{\prime }\cos x+u_{2}^{\prime }\sin x \end {align*}

Let first condition be \begin {equation} u_{1}^{\prime }\cos x+u_{2}^{\prime }\sin x=0 \tag {2} \end {equation}

Hence\begin {align*} y_{p}^{\prime } & =u_{2}\cos x-u_{1}\sin x\\ y_{p}^{\prime \prime } & =u_{2}^{\prime }\cos x-u_{2}\sin x-u_{1}^{\prime }\sin x-u_{1}\cos x \end {align*}

Substituting in (1) gives \begin {align} y_{p}^{\prime \prime }+y_{p} & =a\cos bx\nonumber \\ u_{2}^{\prime }\cos x-u_{2}\sin x-u_{1}^{\prime }\sin x-u_{1}\cos x+u_{1}\cos x+u_{2}\sin x & =a\cos bx\nonumber \\ u_{2}^{\prime }\cos x-u_{1}^{\prime }\sin x & =a\cos bx\tag {3} \end {align}

So we have two equations (1)(2) to solve for \(u_{1},u_{2}\)\begin {align*} u_{1}^{\prime }\cos x+u_{2}^{\prime }\sin x & =0\\ u_{2}^{\prime }\cos x-u_{1}^{\prime }\sin x & =a\cos bx \end {align*}

From the first equation\begin {equation} u_{1}^{\prime }=-u_{2}^{\prime }\frac {\sin x}{\cos x}\tag {4} \end {equation} Substituting in the second equation\begin {align*} u_{2}^{\prime }\cos x-\left (-u_{2}^{\prime }\frac {\sin x}{\cos x}\right ) \sin x & =a\cos bx\\ u_{2}^{\prime }\left (\cos x+\frac {\sin x}{\cos x}\sin x\right ) & =a\cos bx\\ u_{2}^{\prime }\left (\frac {\cos ^{2}x+\sin ^{2}x}{\cos x}\right ) & =a\cos bx\\ u_{2}^{\prime } & =a\cos x\cos bx \end {align*}

Hence \begin {align*} u_{2} & =a\int \cos x\cos \left (bx\right ) dx\\ & =a\frac {-\cos \left (bx\right ) \sin x+b\cos x\sin \left (bx\right ) }{b^{2}-1} \end {align*}

From (4)\begin {align*} u_{1}^{\prime } & =-a\cos \left (bx\right ) \sin x\\ u_{1} & =-a\int \cos \left (bx\right ) \sin xdx\\ & =-a\frac {\cos \left (bx\right ) \cos x+b\sin x\sin \left (bx\right ) }{b^{2}-1} \end {align*}

Since \(y_{p}=u_{1}\relax (x) \cos x+u_{2}\relax (x) \sin x\) then\begin {align*} y_{p} & =\left (-a\frac {\cos \left (bx\right ) \cos x+b\sin x\sin \left ( bx\right ) }{b^{2}-1}\right ) \cos x+\left (a\frac {-\cos \left (bx\right ) \sin x+b\cos x\sin \left (bx\right ) }{b^{2}-1}\right ) \sin x\\ & =\frac {-a\cos \left (bx\right ) \cos ^{2}x-ab\cos x\sin x\sin \left ( bx\right ) -a\cos \left (bx\right ) \sin ^{2}x+ab\sin x\cos x\sin \left ( bx\right ) }{b^{2}-1}\\ & =\frac {-a\cos \left (bx\right ) \cos ^{2}x-a\cos \left (bx\right ) \sin ^{2}x}{b^{2}-1}\\ & =\frac {-a\cos \left (bx\right ) \left (\cos ^{2}x+\sin ^{2}x\right ) }{b^{2}-1}\\ & =\frac {-a\cos \left (bx\right ) }{b^{2}-1}\\ & =\frac {a\cos \left (bx\right ) }{1-b^{2}} \end {align*}

Therefore, the full solution is (for \(b^{2}\neq 1\))\begin {align*} y & =y_{h}+y_{p}\\ & =c_{1}\cos x+c_{2}\sin x+\frac {a\cos \left (bx\right ) }{1-b^{2}} \end {align*}