We will look for solutions to a non homogeneous linear system of order $$n$$ with constant coefficients. Nevertheless, we will have to add a restriction to the method that we will introduce.
If our ODE is: $$$a_n \cdot y^{(n)}(x)+a_{n-1} \cdot y^{(n-1)}(x)+ \ldots + a_1 \cdot y'(x) +a_0 \cdot y(x)= f(x)$$$ (linear with constant coefficients) we require $$f(x)$$ to be a polynomial, an exponential, a sine or a cosine or any combination of these.
Then we will be prepared to solve, for example: $$$y''+y=3 \cos x+e^2x$$$
For the same reason as in linear systems, a general solution to this equation is a sum of the general solution to the homogeneous part and a particular solution to the non homogeneous part.
We are going to solve the ODE for the method of the cancelling polynomial or the method of indeterminate coefficients.
Let's suppose that we have the ODE previously given and $$f(x)$$ is a function that satisfies the conditions that we have been restricted to. Therefore:
- We solve the homogeneous part. So we obtain $$n$$ linearly independent solutions.
In the example that we have given, solutions are:$$$y_1(x)=\cos x \\ y_2(x)=\sin x$$$
- We look for a polynomial that cancels $$f(x)$$. This operation consists in finding a polynomial whose coefficients multiply the derivatives. That is to say:$$$Q(D)=b_nD^n+b_{n-1}D^{n-1}+ \ldots+b_1D+b_0Id$$$where $$D^k$$ means to derive $$k$$ times the function that multiplies it. This way,$$$Q(D)f(x)=\Big(b_nD^n+b_{n-1}D^{n-1}+ \ldots +b_1D+b_0Id\Big) f(x)=\\=b_nD^nf(x)+b_{n-1}D^{n-1}f(x)+ \ldots + b_1 D f(x)+b_0Id\cdot f(x)= \\ =b_n f^n (x)+b_{n-1}f^{n-1}(x)+ \ldots +b_1 f'(x)+b_0f(x)=0$$$This is like finding what linear and homogeneous ODE satisfies $$f (x)$$. To do so, we proceed in the inverse way (to the way we did to find solutions in the homogeneous case).
In the previous example, we had to find a polynomial that cancels $$f(x)=3 \cos x+e^{2x}$$.
Let's proceed in the inverse way to the way we did to find the solutions, that is to say: $$\cos x$$ comes of $$\lambda=ie^{2x}$$ it comes of $$\lambda=2$$.
Therefore the cancelling polynomial is: $$Q(D)=\Big(D^2+ID\Big) \cdot (D \cdot 2Id)$$.
In fact, $$$Q(D)f(x)=\Big(D^2+Id \Big) \cdot \Big(D-2Id\Big) f(x)=\Big( D^3-2D^2+D-2Id\Big)f(x)=\\ =f'''(x)-ef''(x)+f'(x)-2f(x)=\\=3 \sin x+8e^{2x}+6 \cos x- 8e^{2x}-3 \sin x+2e^{2x}-6\cos x-2e^{2x}=0$$$
- Let's notice that, when introducing this notation, our initial ODE can be written as $$P(D)y(x)=f(x)$$ , with $$$P(D)=a_nD^n+a_{n-1}D^{n-1}+\ldots+a_1D+a_0Id$$$ Applying the polynomial $$Q (D)$$ to the previous equality we have: $$$P(D)y(x)=f(x) \Longrightarrow Q(D)P(D)y(x)=Q(D)f(x)=0$$$ and therefore we have a new equation, but homogeneous of order $$k$$ (greater that $$n$$). Then we solve this problem, obtaining $$k$$ functions, of which $$n$$ first are solutions found in (1).$$$y^\star (x)=C_1y_1(x)+C_2y_2(x)+\ldots+C_ny_n(x)+D_1\widetilde{y}_{n+1}(x)+ \ldots +D_k \widetilde{y}_k(x)$$$
In the previous example, then, we have $$Q(D)P(D)=(D^2+Id)(D^2+Id)(D-2Id)$$ that has as its roots (and therefore as its associated solutions): $$\lambda = \pm i$$ with multiplicity $$2$$ that gives solutions $$\cos x, \sin x, x \cdot \cos x, x \cdot \sin x$$, $$\lambda=2 $$ that gives for solution $$e^{2x}$$.
Therefore we have that $$$y^\star (x)=C_1\cos x+C_2 \sin x+D_1 x\cdot \cos x+D_2 x \cdot \sin x+D_3 e^{2x}$$$
- We look for a particular solution to the non homogeneous equation of the form: $$y_p(x)=D_1\widetilde{y}_{n+1}(x)+\ldots+D_k\widetilde{y}_k(x)$$ that is, we take the solutions that have appeared in (3), which we did not have in (1) and we look for certain coefficients to obtain the solution.
In our example, we must look for a particular solution of the form: $$y_p(x)=D_1\cdot \cos x$$.
Let's designate that this is a solution: $$$y''_p+y_p=3 \cos x+e^{2x} \\ y''_p+y_p=-2D_1\sin x-D_1x\cos x+2D_2\cos x-D_2x\sin x+4D_3e^{2x}+D_1x \cos x+$$$ $$$+D_2 x \sin x+D_3 e^{2x}= \\ =-2D_1 \sin x +2 D_2 \cos x+ 5D_3e^{2x}$$$ Equaling the coefficients, we obtain: $$$D_1=0 \\ D_2=\displaystyle \frac{3}{2} \\ D_3= \displaystyle \frac{1}{5}$$$ Therefore, the particular solution is: $$\displaystyle y_p(x)=\frac{3}{2}x \cdot \sin x+\frac{1}{5}e^{2x}$$
- Finally, the general solution to our initial non homogeneous ODE is:$$$y(x)=y_h(x)+y_p(x)$$$
To finish with our example, the general solution is: $$$y(x)=c_1\cos x +c_2 \sin x+\displaystyle \frac{3}{2} x \cdot \sin x+\frac{1}{5}e^{2x}$$$