We continue the method of undetermined coefficients.
Last time we looked at equations of the form $$ Ly=p(x)e^{\alpha x} $$ Today we look the form $$ Ly=e^{\alpha x}(p(x)\cos(\beta x)+q(x)\sin(\beta x)) $$ Reminder: Undetermined coefficients work well only when the equation has constant coefficients.
Example
Find a particular solution $y_p$ to the equation $$ y''-2y'+y=\cos(2x) $$
It is tempting to choose $y_p=A\cos(2x)$ as our particular solution.
However, when substituting this into the equation, sines appear.
Thus, we must instead choose $y_p=A\cos(2x)+B\sin(2x)$ as the form of our particular solution.
Then, $$ \begin{array}{lll} &\displaystyle y_p''-2y_p'+y_p=\cos(2x)&\mbox{}\\ \implies &\displaystyle (A\cos(2x)+B\sin(2x))''-2(A\cos(2x)+B\sin(2x))'+(A\cos(2x)+B\sin(2x))=\cos(2x)&\mbox{}\\ \implies &\displaystyle (-2A\sin(2x)+2B\cos(2x))'-2(-2A\sin(2x)+2B\cos(2x))+A\cos(2x)+B\sin(2x)=\cos(2x)&\mbox{}\\ \implies &\displaystyle \color{magenta}{-4A\cos(2x)}\color{blue}{-4B\sin(2x)}\color{blue}{+4A\sin(2x)}\color{magenta}{-4B\cos(2x)}\color{magenta}{+A\cos(2x)}\color{blue}{+B\sin(2x)}=\cos(2x)&\mbox{}\\ \implies &\displaystyle (-3A-4B)\cos(2x)+(4A-3B)\sin(2x)=\cos(2x)&\mbox{}\\ \implies &\displaystyle \begin{cases}-3A&-4B&=1\\ 4A&-3B&=0 \end{cases}&\mbox{}\\ \end{array} $$ Solving the system, the second equation tells us that $4A=3B,$ so that $\displaystyle B=\frac{4}{3}A.$
Then, from the first equation $$ 1=-3A-4B=-3A-4\left(\frac{4}{3}A\right)=-\frac{25}{3}A $$ Thus, $\displaystyle A=-\frac{3}{25}$ and $\displaystyle B=\frac{4}{3}A=\frac{4}{3}\left(-\frac{3}{25}\right)=-\frac{4}{25}.$
Our particular solution is then $$ y_p=-\frac{3}{25}\cos(2x)-\frac{4}{25}\sin(2x) $$
However, when substituting this into the equation, sines appear.
Thus, we must instead choose $y_p=A\cos(2x)+B\sin(2x)$ as the form of our particular solution.
Then, $$ \begin{array}{lll} &\displaystyle y_p''-2y_p'+y_p=\cos(2x)&\mbox{}\\ \implies &\displaystyle (A\cos(2x)+B\sin(2x))''-2(A\cos(2x)+B\sin(2x))'+(A\cos(2x)+B\sin(2x))=\cos(2x)&\mbox{}\\ \implies &\displaystyle (-2A\sin(2x)+2B\cos(2x))'-2(-2A\sin(2x)+2B\cos(2x))+A\cos(2x)+B\sin(2x)=\cos(2x)&\mbox{}\\ \implies &\displaystyle \color{magenta}{-4A\cos(2x)}\color{blue}{-4B\sin(2x)}\color{blue}{+4A\sin(2x)}\color{magenta}{-4B\cos(2x)}\color{magenta}{+A\cos(2x)}\color{blue}{+B\sin(2x)}=\cos(2x)&\mbox{}\\ \implies &\displaystyle (-3A-4B)\cos(2x)+(4A-3B)\sin(2x)=\cos(2x)&\mbox{}\\ \implies &\displaystyle \begin{cases}-3A&-4B&=1\\ 4A&-3B&=0 \end{cases}&\mbox{}\\ \end{array} $$ Solving the system, the second equation tells us that $4A=3B,$ so that $\displaystyle B=\frac{4}{3}A.$
Then, from the first equation $$ 1=-3A-4B=-3A-4\left(\frac{4}{3}A\right)=-\frac{25}{3}A $$ Thus, $\displaystyle A=-\frac{3}{25}$ and $\displaystyle B=\frac{4}{3}A=\frac{4}{3}\left(-\frac{3}{25}\right)=-\frac{4}{25}.$
Our particular solution is then $$ y_p=-\frac{3}{25}\cos(2x)-\frac{4}{25}\sin(2x) $$
Example
Find a particular solution $y_p$ and general solution to the equation $$ y''+4y=8\cos(2x)+12\sin(2x) $$ Given the homogeneous solution $y_h=C_1\cos(2x)+C_2\sin(2x),$ does anyone anticipate any issues?
Naively, we would guess $y_p=A\cos(2x)+B\sin(2x)$ as the form of our particular solution.
However, our choice of $y_p$ solves the homogeneous equation!
What ever shall we do?????
We amend our guess to $$ y_p=x\left(A\cos(2x)+B\sin(2x)\right) $$ Then, $$ \begin{array}{lll} &\displaystyle y_p''+4y_p=8\cos(2x)+12\sin(2x) &\mbox{}\\ \implies &\displaystyle (x\left(A\cos(2x)+B\sin(2x)\right))''+4(x\left(A\cos(2x)+B\sin(2x)\right))=8\cos(2x)+12\sin(2x)&\mbox{}\\ \implies &\displaystyle (A\cos(2x)+B\sin(2x)+x(-2A\sin(2x)+2B\cos(2x)))'+4Ax\cos(2x)+4Bx\sin(2x)=8\cos(2x)+12\sin(2x)&\mbox{}\\ \implies &\displaystyle -2A\sin(2x)+2B\cos(2x)+(-2A\sin(2x)+2B\cos(2x))+x(-4A\cos(2x)-4B\sin(2x))+4Ax\cos(2x)+4Bx\sin(2x)=8\cos(2x)+12\sin(2x)&\mbox{}\\ \implies &\displaystyle -4A\sin(2x)+4B\cos(2x)-4Ax\cos(2x)-4Bx\sin(2x)+4Ax\cos(2x)+4Bx\sin(2x)=8\cos(2x)+12\sin(2x)&\mbox{}\\ \implies &\displaystyle -4A\sin(2x)+4B\cos(2x)=8\cos(2x)+12\sin(2x)&\mbox{}\\ \end{array} $$ Thus, $-4A=12$ and $4B=8$ so that $A=-3$ and $B=2.$
Our particular solution is then $$ y_p=x(-3\cos(2x)+2\sin(2x)) $$ The general solution is $$ y=y_h+y_p=C_1\cos(2x)+C_2\sin(2x)+x(-3\cos(2x)+2\sin(2x)) $$
However, our choice of $y_p$ solves the homogeneous equation!
What ever shall we do?????
We amend our guess to $$ y_p=x\left(A\cos(2x)+B\sin(2x)\right) $$ Then, $$ \begin{array}{lll} &\displaystyle y_p''+4y_p=8\cos(2x)+12\sin(2x) &\mbox{}\\ \implies &\displaystyle (x\left(A\cos(2x)+B\sin(2x)\right))''+4(x\left(A\cos(2x)+B\sin(2x)\right))=8\cos(2x)+12\sin(2x)&\mbox{}\\ \implies &\displaystyle (A\cos(2x)+B\sin(2x)+x(-2A\sin(2x)+2B\cos(2x)))'+4Ax\cos(2x)+4Bx\sin(2x)=8\cos(2x)+12\sin(2x)&\mbox{}\\ \implies &\displaystyle -2A\sin(2x)+2B\cos(2x)+(-2A\sin(2x)+2B\cos(2x))+x(-4A\cos(2x)-4B\sin(2x))+4Ax\cos(2x)+4Bx\sin(2x)=8\cos(2x)+12\sin(2x)&\mbox{}\\ \implies &\displaystyle -4A\sin(2x)+4B\cos(2x)-4Ax\cos(2x)-4Bx\sin(2x)+4Ax\cos(2x)+4Bx\sin(2x)=8\cos(2x)+12\sin(2x)&\mbox{}\\ \implies &\displaystyle -4A\sin(2x)+4B\cos(2x)=8\cos(2x)+12\sin(2x)&\mbox{}\\ \end{array} $$ Thus, $-4A=12$ and $4B=8$ so that $A=-3$ and $B=2.$
Our particular solution is then $$ y_p=x(-3\cos(2x)+2\sin(2x)) $$ The general solution is $$ y=y_h+y_p=C_1\cos(2x)+C_2\sin(2x)+x(-3\cos(2x)+2\sin(2x)) $$
When $f(x)$ has the Same Form as Solutions to the Homogeneous Equation
The above examples show us that when $f(x)$ has the same form as one of our linearly independent solutions to the homogeneous equation, we multiply our guess $y_g$ by suitable a power $\ell$ of $x.$
The power we choose is the smallest non-negative integer $\ell$ such that $x^{\ell} y_g$ does does not appear as a solution to the homogeneous equation.
If our guess $y_g$ has multiple terms, then $x^{\ell} y_g$ cannot contain any terms which solve the homogeneous equation.
Finding Particular Solutions to $Ly=f(x)$
$$ \begin{array}{ll} f(x) & \mbox{Form of }\,\,y_p\\ \hline a\cos(\beta x)+b\sin(\beta x) & \color{magenta}{x^{\ell}}(A\cos(\beta x)+B\sin(\beta x)) \\ p(x)\cos(\beta x)+q(x)\sin(\beta x) & \color{magenta}{x^{\ell}}(P(x)\cos(\beta x)+Q(x)\sin(\beta x)) \\ \end{array} $$ where $$ \begin{array}{lll} p(x)=a_nx^n+\cdots+a_1x+a_0,\,\,\,\,&q(x)=b_mx^m+\cdots+b_1x+b_0 &\\ P(x)=A_Nx^N+\cdots+A_1x+A_0,\,\,\,\, &Q(x)=B_Nx^N+\cdots+B_1x+B_0, & N=\max\{n,m\} \\ \end{array} $$ and $\ell$ is the smallest non-negative integer such that $y_p=x^{\ell}y_g$ has no terms which solve the homogeneous equation.
Examples
Choose the correct form of a particular solution $y_p$ to the following equations.
$ y''+3y'+2y=(16+20x)\cos x+10\sin x $
The solution to the homogeneous equation is $y_h=C_1e^{-x}+C_2e^{-2x}.$
So, we may choose the form for $y_p$ to be $$ y_p=(A_1x+A_0)\cos x+(B_1x+B_0)\sin x $$ since none of the individual terms solve the homogeneous equation.
So, we may choose the form for $y_p$ to be $$ y_p=(A_1x+A_0)\cos x+(B_1x+B_0)\sin x $$ since none of the individual terms solve the homogeneous equation.
The solution to the homogeneous equation is $y_h=C_1\cos x+C_2\sin x.$
So, we choose the form for $y_p$ to be $$ y_p=x[(A_1x+A_0)\cos x+(B_1x+B_0)\sin x] $$ We must multiply by $x$ since the expression $(A_1x+A_0)\cos x+(B_1x+B_0)\sin x$ contains terms which solve the homogeneous equation.
So, we choose the form for $y_p$ to be $$ y_p=x[(A_1x+A_0)\cos x+(B_1x+B_0)\sin x] $$ We must multiply by $x$ since the expression $(A_1x+A_0)\cos x+(B_1x+B_0)\sin x$ contains terms which solve the homogeneous equation.
We now turn our attention to equations of the form $$ Ly=p(x)e^{\alpha x}\cos(\beta x)+q(x)e^{\alpha x}\sin(\beta x) $$
Finding Particular Solutions to $Ly=f(x)$
$$ \begin{array}{ll} f(x) & \mbox{Form of }\,\,y_p\\ \hline ae^{\alpha x}\cos(\beta x)+be^{\alpha x}\sin(\beta x) & \color{magenta}{x^{\ell}}(Ae^{\alpha x}\cos(\beta x)+Be^{\alpha x}\sin(\beta x)) \\ p(x)e^{\alpha x} \cos(\beta x)+q(x)e^{\alpha x}\sin(\beta x) & \color{magenta}{x^{\ell}}(P(x)e^{\alpha x}\cos(\beta x)+Q(x)e^{\alpha x}\sin(\beta x)) \\ \end{array} $$ where $$ \begin{array}{lll} p(x)=a_nx^n+\cdots+a_1x+a_0,\,\,\,\,&q(x)=b_mx^m+\cdots+b_1x+b_0 &\\ P(x)=A_Nx^N+\cdots+A_1x+A_0,\,\,\,\, &Q(x)=B_Nx^N+\cdots+B_1x+B_0, & N=\max\{n,m\} \\ \end{array} $$ and $\ell$ is the smallest non-negative integer such that $y_p=x^{\ell}y_g$ has no terms which solve the homogeneous equation.
Examples
$ y''-3y'+2y=2e^{-2x}\cos 3x-(34-150x)e^{-2x}\sin 3x $
The solution to the homogeneous equation is $y_h=C_1e^{x}+C_2e^{2x}.$
So, we may choose the form for $y_p$ to be $$ y_p=(A_1x+A_0)e^{-2x}\cos (3x)+(B_1x+B_0)e^{-2x}\sin (3x) $$ since none of the individual terms solve the homogeneous equation.
So, we may choose the form for $y_p$ to be $$ y_p=(A_1x+A_0)e^{-2x}\cos (3x)+(B_1x+B_0)e^{-2x}\sin (3x) $$ since none of the individual terms solve the homogeneous equation.
The characteristic equation for the homogeneous equation is $r^2+2r+5=0$ which has complex roots $r=-1\pm 2i.$
Thus, the homogeneous solution is $y_h=C_1e^{-x}\cos(2x)+C_2e^{-x}\sin(2x).$
It follows that the form of our particular solution is $$ y_p=x[(A_1x+A_0)e^{-x}\cos(2x)+(B_1x+B_0)e^{-x}\sin(2x)] $$ We must multiply by $x$ since the expression $(A_1x+A_0)e^{-x}\cos(2x)+(B_1x+B_0)e^{-x}\sin(2x)$ contains terms which solve the homogeneous equation.
Thus, the homogeneous solution is $y_h=C_1e^{-x}\cos(2x)+C_2e^{-x}\sin(2x).$
It follows that the form of our particular solution is $$ y_p=x[(A_1x+A_0)e^{-x}\cos(2x)+(B_1x+B_0)e^{-x}\sin(2x)] $$ We must multiply by $x$ since the expression $(A_1x+A_0)e^{-x}\cos(2x)+(B_1x+B_0)e^{-x}\sin(2x)$ contains terms which solve the homogeneous equation.
Finding Particular Solutions to $Ly=f(x)$
$$ \begin{array}{ll} f(x) & \mbox{Form of }\,\,y_p\\ \hline a_nx^n+\cdots+a_1x+a_0 & \color{magenta}{x^{\ell}}\left(A_nx^n+\cdots+A_1x+A_0\right)\\ ae^{\alpha x} & \color{magenta}{x^{\ell}}Ae^{\alpha x}\\ (a_nx^n+\cdots+a_1x+a_0 )e^{\alpha x} & \color{magenta}{x^{\ell}}\left(A_nx^n+\cdots+A_1x+A_0\right)e^{\alpha x}\\ a\cos(\beta x)+b\sin(\beta x) & \color{magenta}{x^{\ell}}(A\cos(\beta x)+B\sin(\beta x)) \\ p(x)\cos(\beta x)+q(x)\sin(\beta x) & \color{magenta}{x^{\ell}}(P(x)\cos(\beta x)+Q(x)\sin(\beta x)) \\ ae^{\alpha x}\cos(\beta x)+be^{\alpha x}\sin(\beta x) & \color{magenta}{x^{\ell}}(Ae^{\alpha x}\cos(\beta x)+Be^{\alpha x}\sin(\beta x)) \\ p(x)e^{\alpha x}\cos(\beta x)+q(x)e^{\alpha x}\sin(\beta x) & \color{magenta}{x^{\ell}}(P(x)e^{\alpha x}\cos(\beta x)+Q(x)e^{\alpha x}\sin(\beta x)) \\ \end{array} $$ where $$ \begin{array}{lll} p(x)=a_nx^n+\cdots+a_1x+a_0,\,\,\,\,&q(x)=b_mx^m+\cdots+b_1x+b_0 &\\ P(x)=A_Nx^N+\cdots+A_1x+A_0,\,\,\,\, &Q(x)=B_Nx^N+\cdots+B_1x+B_0, & N=\max\{n,m\} \\ \end{array} $$ and $\ell$ is the smallest non-negative integer such that $y_p=x^{\ell}y_g$ has no terms which solve the homogeneous equation.
Bonus Example
Choose the form of a particular solution $y_p$ to the following equations, all of which have the form $$ y''+2y'-3y=f(x) $$ Note that the solution to the homogeneous equation is $y_h=C_1e^x+C_2e^{-3x}.$
$y''+2y'-3y=4\cos(3x)$
$$
y_p=A\cos(3x)+B\sin(3x)
$$
$$
y_p=Axe^{-3x}
$$
$$
y_p=(A_2x^2+A_1x+A_0)\cos(3 x)+(B_2x^2+B_1x+B_0)\sin(3 x)
$$
$$
y_p=(A_1x+A_0)e^x\cos x+(B_1x+B_0)e^x\sin x
$$
$$
y_p=x(A_2x^2+A_1x+A_0)e^x
$$
The method of undetermined coefficients is useless here.