# Differential equations/Linear inhomogeneous differential equations
## Method of Undetermined Coefficients
### Definition

A non-homogeneous second order equation is an equation where the right hand side is equal to some constant or function of the independent variable. This technique is best when the right hand side of the equation has a fairly simple derivative.

### Solution

The solution is divided into two parts and then added together by superposition. The first part is obtained by solving the complimentary (homogeneous) equation. The second part is obtained from a set of equations. To illustrate the solution, we will take the equation $y''+2y'+y=x^{2}$ as an example.
* Solve the homogeneous equation ($y''+2y'+y=0$) and get the roots of the characteristic equation ($(m+1)^{2}=0,m=-1$) .
* Plug the roots into the general solution ($y_{c}=c_{1}\sin(x)+c_{2}\cos(x)$) to obtain the complementary (homogeneous) solution.
* To get the typical (specific) solution to the differential equation, we need to choose a "solution" from a table.
** $1$ (any constant): $A$
** $5x+7$ : $Ax+B$
** $3x^{2}-2$ : $Ax^{2}+Bx+C$
** $x^{3}-x+1$ : $Ax^{3}+Bx^{2}+Cx+D$
** $\sin(4x)$ : $A\cos(4x)+B\sin(4x)$
** $\cos(4x)$ : $A\cos(4x)+B\sin(4x)$
** $e^{5x}$ : $Ae^{5x}$
** $(9x-2)e^{5x}$ : $(Ax+B)e^{5x}$
** $x^{2}e^{5x}$ : $(Ax^{2}+Bx+C)e^{5x}$
** $e^{3x}\sin(4x)$ : $Ae^{3x}\cos(4x)+Be^{3x}\sin(4x)$
** $5x^{2}\sin(4x)$ : $(Ax^{2}+Bx+C)\cos(4x)+(Ex^{2}+Fx+G)\sin(4x)$
** $xe^{3x}\cos(4x)$ : $(Ax+B)e^{3x}\cos(4x)+(Cx+E)e^{3x}\sin(4x)$
* Choose the "solution" that best fits the right hand side of the equation. (the solution of $\textstyle x^{2}$ must take the form $\textstyle y_{p}=Ax^{2}+Bx+C$ ).
* Differentiate the "solution" to get the derivatives of the solution ($y_{p}^{'}=2Ax+B,y_{p}^{''}=2A$ ).
* Substitute those solutions into the left hand side of the original differential equation ($(2A)+2(2Ax+B)+(Ax^{2}+Bx+C)=x^{2}$ ).
* Collect and compare like terms to solve for the coefficients ($A=1,B=-4,C=6$ ).
* Substitute the coefficients back into typical "solution" ($y_{p}=x^{2}-4x+6$ ).
* Add the typical and the complementary solutions to get the complete solution
    $y=y_{c}+y_{p}=c_{1}\cos(x)+c_{2}\sin(x)+x^{2}-4x+6$

## Variation of Parameters
### Definition

A non-homogeneous second order equation is an equation where the right hand side is equal to some constant or function of the independent variable. This technique is best when the right hand side of the equation has a fairly complicated derivative.

### Solution

This technique involves solving the complementary equation and using both solutions ($y_{1}$ and $y_{2}$ ) as a basis to solve for two more particular solutions that combine to form the typical solution $y_{p}=u_{1}(x)+u_{2}(x)$ . To illustrate, let's solve the differential equation $y''-2y'-1=2xe^{3x}$ .
* Solve for the complementary solution ($(m-1)^{2}=0,m=\pm 1,y_{c}=e^{x}+xe^{x}$ ).
* Take each term in the complementary solution and make them separate functions ($y_{1}=e^{x},y_{2}=xe^{x}$ ).
* Set up the following three Wronksian matrices and take the determinants of them:
** $W={\begin{vmatrix}y_{1}(x)&y_{2}(x)\\y_{1}^{'}(x)&y_{2}^{'}(x)\end{vmatrix}}={\begin{vmatrix}e^{x}&xe^{x}\\e^{x}&e^{x}(1+x)\end{vmatrix}}=e^{2x}$
** $W_{1}={\begin{vmatrix}0&y_{2}(x)\\f(x)&y_{2}^{'}(x)\end{vmatrix}}={\begin{vmatrix}0&xe^{x}\\2xe^{3x}&e^{x}(1+x)\end{vmatrix}}=-2x^{2}e^{4x}$
** $W_{2}={\begin{vmatrix}y_{1}(x)&0\\y_{1}^{'}(x)&f(x)\end{vmatrix}}={\begin{vmatrix}e^{x}&0\\e^{x}&2xe^{3x}\end{vmatrix}}=2xe^{4x}$
* Solve for the terms $u_{1}^{'}={\frac {W_{1}}{W}}={\frac {-2x^{2}e^{4x}}{e^{2x}}}=-2x^{2}e^{2x}$ and $u_{2}^{'}={\frac {W_{2}}{W}}={\frac {2xe^{4x}}{e^{2x}}}=2xe^{2x}$ .
* Integrate them to get the terms $u_{1}={\frac {-(2x^{2}-2x+1)e^{2x}}{2}}$ and $u_{2}={\frac {(2x-1)e^{2x}}{2}}$ .
* Combine them with the complementary solution to get the complete solution ($y=y_{c}+y_{p}=c_{1}e^{x}+c_{2}xe^{x}-{\frac {(2x^{2}-2x+1)e^{2x}}{2}}+{\frac {(2x-1)e^{2x}}{2}}$) .