Ordinary Differential Equations/Nonhomogeneous second order equations:Method of undetermined coefficients

Consider a differencial equation of the form

$$y''+p(t)y'+q(t)y=g(t)$$

Clerarly, this is not homogeneous, as $$g(t)\neq0$$.

So, to solve this, we first proceeed as normal, but assume that the equation is homogeneous; set $$g(t)=0$$for now. Then the first part of the solution pans like $$ y(t)=c_{1}e^{r_{1}t}+c_{2}e^{r_{2}t}. $$.

Now we need to find the particular integral. To do this, make an appropriate substitution that relates to what $$g(t)$$ is. For instance, if $$g(t)=e^{2x}$$, then take substitution $$Ae^{2x}$$. As $$y''$$ and $$y'$$ are multiples of $$y$$ in this case, you'll simply get a linear equation in $$A$$. Then just plug the value of $$A$$ in the equation.

Hence the solution is

y = general solution + particular integral.

There is one important caveat which you should be aware though. In the previous example for instance, if the general solution already had $$e^{2x}$$, the substitution cannot be $$Ae^{2x}$$, as the particular integral cannot be equal to the general solution. In such cases, you need to take the substitution as $$Axe^{2x}$$.

Example
Solve the differential equation

$$\frac{d^2y}{dx^2}+\frac{2dy}{dx}+2y=4+e^{-2x}$$ Given that $$y(0)=4, y'(0)=-1$$

Solution
Take $$y=e^{mx}$$. Then

$$(d^2 y)/(dx^2)+2 dy/dx+2y\rightarrow(m+1)^2+1=0\rightarrow m+1=\pm i\rightarrow m=-1\pm i$$

Hence the general form of the equation becomes

$$y=e^{-x}\left(P\cos{x}+Q\sin{x}\right)$$ Now, the particular integral has to be found. To do so, we consider RHS: $$4+{2e}^{-2x}$$. The substation then becomes $$A+Be^{-2x}$$. Then $$y^\prime=-2Be^{-2x}$$ and $$y^{\prime\prime}=4Be^{-2x}$$. Then the equation reduces to $$4B-4B+2\left(A+Be^{-2x}\right)=4+2e^{-2x}\rightarrow2A+2Be^{-2x}=4+2e^{-2x}$$. Hence $$A=2,B=1$$. The equation is now

$$y=e^{-x}\left(P\cos{x}+Q\sin{x}\right)+2+e^{-2x}$$

$$y\left(0\right)=4.$$ Then $$4=P+2+1\rightarrow P=1.$$ $$y^\prime\left(0\right)=-1$$. Then $$-e^{-x}\left(P\cos{x}+Q\sin{x}\right)+e^{-x}\left(Q\cos{x}-P\sin{x}\right)-2e^{-2x}=-1=>\ Q-P-2=-1\rightarrow Q-P=1\rightarrow Q=2. $$

Hence the final equation is $$y=e^{-x}\left(\cos{x}+2\sin{x}\right)+2+e^{-2x}$$