# Preface

This is a tutorial made solely for the purpose of education and it was designed for students taking Applied Math 0330. It is primarily for students who have very little experience or have never used Mathematica before and would like to learn more of the basics for this computer algebra system. As a friendly reminder, don't forget to clear variables in use and/or the kernel.

Finally, the commands in this tutorial are all written in bold black font, while Mathematica output is in normal font. This means that you can copy and paste all commands into Mathematica, change the parameters and run them. You, as the user, are free to use the scripts for your needs to learn the Mathematica program, and have the right to distribute this tutorial and refer to this tutorial as long as this tutorial is accredited appropriately.

Return to computing page for the first course APMA0330
Return to computing page for the second course APMA0340
Return to Mathematica tutorial for the second course APMA0330
Return to Mathematica tutorial for the first course APMA0340
Return to the main page for the course APMA0340
Return to the main page for the course APMA0330
Return to Part IV of the course APMA0330

# Method Undetermined Coefficients

Let $$\texttt{D} = {\text d}/{\text d}x$$ be the derivative operator. We consider linear differential operators that are generated by a polynomial of degree n: $L[\lambda ] = a_n \lambda^n + a_{n-1} \lambda^{n-1} + \cdots + a_1 \lambda + a_0 ,$ which is referred to as the characteristic polynomial to the corresponding differential operator $L \left[ \texttt{D} \right] = a_n \texttt{D}^n + a_{n-1} \texttt{D}^{n-1} + \cdots + a_1 \texttt{D} + a_0 .$ It is always assumed that the coefficients of the above operator are continuous functions in some interval. Moreover, we always suppose that the leading coefficient $$a_n \ne 0.$$ Therefore, it could be factored out or set to be 1.

Our main objective is to show how to find a particular solution to the nonhomogeneous equation

$L[\texttt{D}] y = f(x),$
where f(x) is a given function of specific form and L is a linear constant coefficient differential operator. In this section, we present the method of undetermined coefficients that allows one to find a particular solution in case when
1. the coefficients $$a_n , \ a_{n-1} , \ \ldots , \ a_1 , \ a_0$$ are constants and
2. f(x) is a constant, a polynomial functions, an exponential function eax, a sine or cosine function $$\sin \beta x \quad \mbox{or}\quad \cos \beta x,$$ or finite sums and products of these functions.
To each of these input functions, called admissible for the method of undetermined coefficients, we assign a control number, summarized in the table below.

function  formula  control number
polynomial or constant  $$p_n x^n + \cdots + p_1 x + p_0$$   0
polynomial times exponential  $$\left( p_n x^n + \cdots + p_1 x + p_0 \right) e^{\alpha \,x}$$  α
polynomial times exponential & sine  $$\left( p_n x^n + \cdots + p_1 x + p_0 \right) e^{\alpha \,x} \, \sin \beta x$$  α + β j or α - β j
polynomial times exponential & cosine  $$\left( p_n x^n + \cdots + p_1 x + p_0 \right) e^{\alpha\, x}\, \cos \beta x$$  α + β j or α - β j

A control number is just a root of the characteristic polynomial that corresponds to the operator annihilating the function. For instance, if a control number is known to be α, we know that the annihilating polynomial for such function must be $$\left( \texttt{D} - \alpha \right)^m ,$$ for some positive integer m (called the multiplicity). Since the characteristic polynomial for any constant coefficient differential operator can be factored into simple terms, it is natural to start analyzing with some such simple multiple.

The following functions all have zero control number:
$f(x) = 2, \quad x^2 -7x +3 , \quad 3\,x^9 - 101\,x^8 + x -1 .$
The following functions have real control numbers, which we denote by σ,
$f(x) = e^{2x}, \quad \sigma =2, \qquad \left( x^2 -7x +3 \right) e^{-3x} , \quad \sigma = -3, \quad \left( 3\,x^9 - 101\,x^8 + x -1 \right) e^{\pi x} , \quad \sigma = \pi .$
The final set of admissible functions presents input functions with complex control numbers:
$f(x) = e^{2x}\, \sin 3x, \quad \sigma =2+ 3{\bf j}, \qquad x^2 e^{-3x} \cos 5x , \quad \sigma = -3+ 5{\bf j}, \quad \left( 3\,x^9 - 101\,x^8 + x -1 \right) e^{\pi x} \sin \pi x, \quad \sigma = \pi + \pi {\bf j}.$

The following theorem explains why the method undetermined coefficients works.

Theorem: If L and A are both linear differential operators of positive order, and f is a function annihilated by A, i.e., such that A(f) = 0, then

1. every solution of $$L[y] = f$$ belongs to Ker(AL);
2. in every subspace V of Ker(AL) complementary to Ker(L) (i.e., in every V such that $$\mbox{Ker}(L) \oplus V = \mbox{Ker}(AL)),$$ there is a unique solution to $$L(y) = f.$$

Corollary: If L and A commute then Ker(A) is a subspace of Ker(AL). If, in addition, Ker(L) and Ker(A) have only 0 in common, then in Ker(A) there is a unique solution to $$L( y) = f. \qquad$$

If L and A have constant coefficients, then L and A commute. This motivates the standard practice of undetermined coefficients; however, the complement of Ker(L) in Ker(AL) needs have very little similarity to Ker(A), depending on just how large $$\mbox{Ker}(L) \cap \mbox{Ker}(A)$$ is.

It is not the fact that L and A are differential operators which makes the theorem work, but the fact that for operators of these types, dim(Ker(AL)) = dim(Ker(A)) + dim(Ker(L)).

The theorem explains exactly which nonhomogeneous linear differential equations permit finding a particular solution by the method of undetermined coefficients: the right-hand side must be annihilated by some linear differential operator of positive order. In the constant coefficients case for either topic, it is clear from the theory how to obtain A and all of the basis functions specified by the theorem. In fact, the bases for Ker(L) and Ker(AL) so obtained will always give a basis for Ker(L) as a subset of a basis for Ker(AL). This means that one can immediately identify a basis for a subspace complementary to Ker(L) as those basis elements in Ker(AL) which were not in Ker(L). One then knows the form of a particular solution since the existence of a unique solution in this complementary subspace is guaranteed. These ideas are illustrated by the following examples.

Example: Consider the differential operator of degree four $$L = \left( \texttt{D} - 2 \right)^2 \left( \texttt{D} +3 \right)\left( \texttt{D} - 4 \right) .$$ Let $$f(x) = 2x^3 e^{2x}$$ be a function whose control number is 2. This means that $$A= \left( \texttt{D} -2 \right)^4$$ annihilates it. Since $$AL=LA$$ has the basis of functions

$e^{2x} , \ x\,e^{2x} , \ x^2 e^{2x} , \ x^3 e^{2x} , \ x^4 e^{2x} , \ x^5 e^{2x} , \ e^{-3x}, \ e^{4x} ,$
while L has
$e^{2x} , \ x\,e^{2x} , \ e^{-3x}, \ e^{4x} ,$
A has
$e^{2x} , \ x\,e^{2x} , \ x^2 e^{2x} , \ x^3 e^{2x} ,$
and the complement space V is spanned on
$x^2 e^{2x} , \ x^3 e^{2x} , \ x^4 e^{2x} , \ x^5 e^{2x} .$
Now assume a particular solution of the form
$y_p (x) = c_1 x^2 e^{2x} + c_2 x^3 e^{2x} + c_3 x^4 e^{2x} + c_4 x^5 e^{2x} = x^2 \left( c_1 + c_2 x + c_3 x^2 + c_4 x^3 \right) e^{2x} ,$
which is a product of x2 (power is 2 because the characteristic polynomial has double root λ = 2) times exactly the same form as the input functions; namely, it is a polynomial of degree 3 multiplied by the exponential function. Note that the form of the assumed solution is from the form of the basis for Ker(A) because $$\dim (\mbox{Ker}(L) \cap \mbox{Ker}`(A)) = 2.$$

Lemma: Let us consider the linear nonhomogeneous differential equation with constant coefficients of order n:

$L \left[ \frac{\text d}{{\text d}x} \right] y = f(x) ,$
where $$L[\lambda ] = a_n \lambda^n + \cdots + a_1 \lambda + a_0$$ is its characteristic polynomial, and f(x) is a polynomial of degree m. Then the differential equation $$L[\texttt{D}] y = f(x)$$ has a polynomial solution. Moreover,
1. if $$a_0 \ne 0 ,$$ then the degrees of the polynomials f and g are the same;
2. if $$k = \max \left\{ j \, : \, a_l =0, \ l \le j \right\} ,$$ exists, then we can admit that <$$g(x) = x^{k+1} h(x) ,$$ where h and f have the same degree; /li>
3. if all coefficients are real, the g and h are real.

Theorem: Let f(x) be a nonzero real polynomial and (γ, δ) be a pair of numbers such that γ is a complex number, but δ is always real number, with the condition that δ = 0 if γ is real. Let $$L[\texttt{D}]$$ be a constant coefficient differential operator, with the characteristic polynomial $$L[\lambda ] = a_n \lambda^n + \cdots + a_1 \lambda + a_0 .$$ Then the nonhomogeneous differential equation

$L \left[ \frac{\text d}{{\text d}x} \right] y = f(x)\, e^{\gamma\,x + {\bf j} \delta} ,$
has a particular solution $$y_p (x) = g(x)\, e^{\gamma\,x + {\bf j} \delta} ,$$ where g(x) is an arbitrary polynomial satisfying the differential equation,
$L \left[ \texttt{D} + \gamma \right] g(x) \equiv a_n g^{(n)} + L^{(n-1)} (\gamma ) \,\frac{1}{(n-1)!}\, g^{(n-1)} + \cdots + L' (\gamma )\, g' (x) + L(\gamma )\, g(x) = f(x) .$
Moreover,
1. If γ is a real number, then g(x) is a real valued solution of the above differential equation, and a particular solution of $$L[\texttt{D}] y = g(x)\, e^{\gamma\,x + {\bf j} \delta}$$ becomes $$y_p (x) = g(x)\, e^{\gamma\,x} .$$
2. If γ is complex, then $$z (x) = g(x)\, e^{\gamma\,x + {\bf j} \delta}$$ is a complex-valued solution of $$L[\texttt{D}] y = g(x)\, e^{\gamma\,x + {\bf j} \delta} .$$ If $$\gamma = \alpha + {\bf j} \beta ,$$ where α and β are real numbers, then the real part $$Y_r (x) = \Re \left[ z(x) \right] = \mbox{Re} \left[ z(x) \right]$$ and the imaginary part $$Y_i (x) = \Im \left[ z(x) \right] = \mbox{Im} \left[ z(x) \right]$$ are solutions of the differential equation
$L[\texttt{D}] Y_r (x) = g(x)\,e^{\alpha\, x} \,\cos \left( \beta x + \delta \right) , \qquad L[\texttt{D}] Y_i (x) = g(x)\,e^{\alpha\, x} \,\sin \left( \beta x + \delta \right) .$
3. If $$L[\gamma ] \ne 0 ,$$ then the degree of the polynomial g(x) is the same as the degree of the polynomial f(x).
4. If γ is a root of multiplicity m of the characteristic equation $$L[\gamma ] =0 ,$$ then we can choose a polynomial $$g(x) = x^m h(x) ,$$ where h(x) has the same degree as f(x). ■

The above theorem shows that we can always reduce the problem of finding a particular solution to a nonhomogeneous equation to the case when the input function does not contain an exponential multiple. We illustrate the method of undetermined coefficients in the series of examples.

Example: Consider the differential equation of third order

$L[\texttt{D}] y (x) = \left( \texttt{D}^3 -2\,\texttt{D}^2 -5\,\texttt{D} +6 \right) y \equiv y''' -2\,y'' -5\,y' +6\,y = x^3 ,$
with input function $$p(x) = x^3$$ being a polynomial in x. Since the characteristic polynomial $$L[\lambda ] = \lambda^3 -2\,\lambda^2 -5\,\lambda +6 = \left( \lambda -1 \right) \left( \lambda -2 \right) \left( \lambda -3 \right)$$ has three positive distinct roots while the input function has the control number 0, we seek a particular solution in the same form as the driven term, namely, as a polynomial of degree 3:
$y_p (x) = c_0 + c_1 x + c_2 x^2 + c_3 x^3 ,$
where coefficients c's should be determined upon substituting yp into the given differential equation:
$L[\texttt{D}] y_p (x) = 6 \left( c_0 + c_1 x + c_2 x^2 + c_3 x^3 \right) -5 \left( c_1 + 2c_2 x + 3 c_3 x^2 \right) -2\left( 2c_2 + 6 c_3 x \right) + 6c_3 = x^3 .$
Equating coefficients of like powers of x (because xk and xn are linearly independent for $$k \ne n$$ ), we obtain four equations:
$\begin{split} 6c_0 -5c_1 +4c_2 +6 c_3 &= 0, \\ 6c_1 -10c_2 -12c_3 &=0, \\ 6c_2 -15c_3 &=0, \\ 6c_3 &=1 . \end{split}$
It is not hard to solve the above system of algebraic equation; however, we delegate this job to Mathematica:
Clear[x,y];
L[x_, y_] = y'''[x] - 2 y''[x] - 5 y'[x] + 6 y[x]
rhs = x^3
L[x,y] == rhs
assume[x_] = a0 + a1*x + a2*x^2 + a3*x^3
result = Collect[L[x, assume], x ]
eqns = CoefficientList[result, x] == CoefficientList[rhs, x]
yp[x_] = assume[x] /. Solve[eqns][[1]]
Out[40]= 209/216 + (37 x)/36 + (5 x^2)/12 + x^3/6

Example: Consider the differential equation with the same differential operator as in the previous example, but having exponential input:

$L[\texttt{D}] y (x) = \left( \texttt{D}^3 -2\,\texttt{D}^2 -5\,\texttt{D} +6 \right) y \equiv y''' -2\,y'' -5\,y' +6\,y = x^3 \, e^{-x} .$
Since the driving function $$f(x) = x^3 e^x$$ has the control number -1, which does not match the roots of characteristic equation, the method suggests to seek a particular solution in the same form and the input function:
$y_p (x) = \left( c_0 + c_1 x + c_2 x^2 + c_3 x^3 \right) e^{-x} .$
Next step is to find derivatives of the above function
$\begin{split} y'_p &= \left( c_1 + 2c_2 x + 3c_3 x^2 \right) e^{-x} - y_p (x) , \\ y''_p &= \left( 2c_2 + 6c_3 x \right) e^{-x} - 2 \left( c_1 + 2c_2 x + 3c_3 x^2 \right) e^{-x} + y_p , \\ y'''_p &= 6c_3 e^{-x} -3 \left( 2c_2 + 6c_3 x \right) e^{-x} + 3 \left( c_1 + 2c_2 x + 3c_3 x^2 \right) e^{-x} - y_p (x) . \end{split}$
Then we substitute the derivatives into the given nonhomogeneous equation, canceling the exponential multiple $$e^{-x} ,$$ and obtain
$e^x \,L \left[ \texttt{D} \right] y_p (x) = \left( 6 c_3 -10c_2 + 3c_1 + 8 c_0 \right) + x \left( 8 c_1 + 4 c_2 -30 c_3 \right) + x^2 \left( 6c_3 + 8 c_2 \right) + 8c_3 x^3 = x^3 .$
Two polynomials are equal only when all coefficients are the same. This yields
$\begin{split} 4c_0 + c_1 -5c_2 +3 c_3 &= 0, \\ 8c_1 +4c_2 -30c_3 &=0, \\ 6c_3 +8c_2 &=0, \\ 8c_3 &=1 . \end{split}$
We ask Mathematica for help and verification:
DSolve[y'''[x] - 2*y''[x] - 5*y'[x] + 6*y[x] == x^3 *Exp[-x], y, x]
{{y -> Function[{x}, 1/256 E^-x (-87 + 132 x - 24 x^2 + 32 x^3) + E^(-2 x) C[1] + E^x C[2] + E^(3 x) C[3]]}}
y[x_]=c0 +c1*x +c2*x^2 + c3*x^3
Simplify[D[y[x], x, x, x] - 2*D[y[x], x, x] - 5*D[y[x], x] + 6*y[x]]
2 E^-x (4 c0 + c1 - 5 c2 + 3 c3 + 4 c1 x + 2 c2 x - 15 c3 x + 4 c2 x^2 + 3 c3 x^2 + 4 c3 x^3)
As we see, practical application of the method of undetermined coefficients requires a lot of calculations; so a computer algebra is very helpful. To reduce tedious calculations, we apply the formula from the annihilating method:
$e^{-\gamma\,x} L\left[ \texttt{D} \right] f(x)\, e^{\gamma\, x} = L\left[ \texttt{D} + \gamma \right] f(x) , \qquad \mbox{where } \texttt{D} = \frac{{\text d}}{{\text d}x} . \tag{A}$
We apply Eq(A) with γ = -1 and reduce the differential operator to the following one:
$L\left[ \texttt{D} -1 \right] = \left( \texttt{D} -1 \right)^3 -2 \left( \texttt{D} -1 \right)^2 -5 \left( \texttt{D} -1 \right) +6 = \texttt{D}^3 -5 \texttt{D}^2 +2 \texttt{D} +8 ,$
which we denote by $$M \left[ \texttt{D} \right] = \texttt{D}^3 -5 \texttt{D}^2 + 2 \texttt{D} +8 .$$ Then instead of the original nonhomogeneous problem with the driving term containing exponential multiple, we get equivalent problem with polynomial right-hand side term:
$M \left[ \texttt{D} \right] y = x^3 \qquad \mbox{or} \qquad y''' -5 y'' + 2y' +8y =x^3 .$
Since the characteristic polynomial corresponding to the differential operator M has three distinct real roots $$\lambda = -1, \ 2, \ 4$$ that do not match zero (control number of x3), we seek its particular solution in the form
$y_p (x) = c_0 + c_1 x + c_2 x^2 + c_3 x^3 .$
Substituting this function into the differential equation $$y''' -5 y'' + 2y' +8y =x^3 ,$$ we obtain exactly the same system of algebraic equations:
$\begin{split} 4c_0 + c_1 -5c_2 +3 c_3 &= 0, \\ 4c_1 +2c_2 -15c_3 &=0, \\ 3c_3 +4c_2 &=0, \\ 8c_3 &=1 . \end{split}$

Example: Consider the differential equation with the same differential operator as in the previous example, but having exponential input:

$L[\texttt{D}] y (x) = \left( \texttt{D}^3 -2\,\texttt{D}^2 -5\,\texttt{D} +6 \right) y \equiv y''' -2\,y'' -5\,y' +6\,y = x^3 \, e^{x} .$
We have two options to determine a particular solution: either seek a function having exponential multiple or reduce the problem to the polynomial input without exponential multiple. We demonstrate both approaches.

The control number of the driving term is σ = 1, which matches one of the roots of the characteristic equation $$\lambda^3 -2 \lambda^2 -5 \lambda + 6 = \left( \lambda -1 \right) \left( \lambda -2 \right)\left( \lambda -3 \right) =0$$ of multiplicity 1. Therefore, we seek its particular solution in the form:

$y_p (x) = x \left( c_0 + c_1 x + c_2 x^2 + c_3 x^3 \right) e^{x} .$
Substituting this function into the given equation and equating coefficients of like powers of x, we obtain the following system of algebraic equations
$\begin{split} 3c_0 - c_1 -3c_2 &= 0, \\ 6c_1 -3c_2 -12c_3 &=0, \\ 9c_2 -6c_3 &=0, \\ -24c_3 &=1 . \end{split}$
Solving the above system of algebraic equations, we find a particular solution:
$y_p (x) = -x \left( \frac{13}{216} + \frac{7}{72}\, x + \frac{1}{36}\, x^2 + \frac{1}{24}\, x^3 \right) e^{x} .$
Now we use Eq.(A) and reduce the problem to the following differential equation:
$M\left[ \texttt{D} \right] y \equiv L \left[ \texttt{D} +1 \right] y = x^3 \qquad \Longleftrightarrow \qquad y''' + y'' -6y' = x^3 .$
Since the characteristic polynomial $$\lambda^3 + \lambda^2 -6 \lambda = \lambda \left( \lambda -2 \right) \left( \lambda +3 \right)$$ has a root that matches the control number σ = 0 of the input polynomial, we seek its particular solution in the form:
$y_p (x) = x^2 \left( c_0 + c_1 x + c_2 x^2 + c_3 x^3 \right) .$
Substituting this function into the differential equation $$M\left[ \texttt{D} \right] y = x^3$$ yields exactly the same solution.

Example: Consider the differential equation with the fourth order differential operator that has a polynomial input:

$L[\texttt{D}] y (x) = \texttt{D}^2 \left( \texttt{D}^2 +\texttt{D} -2 \right) y \equiv \texttt{D}^2 \left( \texttt{D}+2 \right) \left( \texttt{D} -1 \right) y \equiv y^{(4)} + y''' -2\,y'' = x^3 .$
The characteristic polynomial $$L[\lambda ] = \lambda^2 \left( \lambda +2 \right) \left( \lambda -1 \right)$$ has three real roots, one of which, λ = 0, is of multiplicity 2. Since the control number σ = 0 matches this root, we seek a particular solution in the form of a polynomial of degree 3 multiplied by x2:
$y_p (x) = x^2 \left( c_0 + c_1 x + c_2 x^2 + c_3 x^3 \right) .$
Substituting this function into the given differential equation and equating like powers of x, we obtain the following system of algebraic equation:
$\begin{split} -4c_0 +5 c_1 +24c_2 &= 0, \\ -c_1 +2c_2 +10c_3 &=0, \\ -2c_2 +5c_3 &=0, \\ -40c_3 &=1 . \end{split}$
Solving the above system of equations, we obtain a particular solution
$y_p (x) = -x^2 \left( \frac{15}{16} + \frac{3}{8}\, x + \frac{1}[16}\, x^2 + \frac{1}{40}\, x^3 \right) .$

Example: Consider the differential equation with the fourth order differential operator when the input has an exponential term:

$L[\texttt{D}] y (x) = \left( \texttt{D}^4 -5\, \texttt{D}^3 +6\,\texttt{D}^2 +4\,\texttt{D} -8 \right) y \equiv \left( \texttt{D} -2 \right)^3 \left( \texttt{D} +1 \right) y \equiv y^{(4)} -5\,y''' +6\,y'' +4\,y' -8\,y = x^3 \, e^{2x} .$
The characteristic polynomial $$L[\lambda ] = \left( \lambda -2 \right)^3 \left( \lambda +1 \right)$$ has one triple root λ = 2 and one simple root λ = -1. Since the control number σ = 2 matches this root, we seek a particular solution as a product of a polynomial of degree 3 times the exponential term, then multiplied by x3:
$y_p (x) = x^3 \left( c_0 + c_1 x + c_2 x^2 + c_3 x^3 \right) e^{2x} .$
Substituting this function into the given differential equation, canceling the exponential multiple and equating like powers of x, we obtain the following system of algebraic equations:
$\begin{split} 3c_0 +4 c_1 &= 0, \\ -3c_1 +5c_2 &=0, \\ c_2 +2c_3 &=0, \\ 360c_3 &=1 . \end{split}$
Solving the above system of equations, we obtain a particular solution
$y_p (x) = x^3 \left( \frac{1}{360}\, x^3 - \frac{1}{180}\, x^2 + \frac{1}{108}\, x - \frac{1}{81} \right) e^{2x} .$

Example: Consider the differential equation whose characteristic polynomial has complex roots that do not match the control numbers of the input function:

$L[\texttt{D}] y (x) = \left( \texttt{D}^3 -4\,\texttt{D}^2 +14\,\texttt{D} -20 \right) y \equiv \left( \texttt{D} -2 \right) \left( \texttt{D}^2 -2\texttt{D} +10 \right) y \equiv y''' -4\,y'' +14\,y' -20\,y = x \, e^{x}\, \cos 2x .$
The characteristic polynomial $$L[\lambda ] = (\lambda -2) \left[ (\lambda -1)^2 + 9 \right]$$ has only simple roots, one is real λ = 2 and two are complex conjugate $$\lambda = 1 \pm 3{\bf j} .$$ The control number of the input function σ = 1 + 2j does not match neither of the roots. Therefore, we seek a particular solution in the same form as the driving function:
$y_p (x) = \left( a_0 + a_1 x \right) e^{x} \, \cos 2x + \left( b_0 + b_1 x \right) e^{x} \, \sin 2x ,$
where a0, a1, b0, and b1 are constants to be determined. Substituting this function into the given differential equation and canceling the exponential term, we obtain
$-\left( 5a_0 + 3a_1 -10b_0 + 4b_1 +5a_1 x -10b_1 x \right) \cos 2x - \left( 10a_0 - 4a_1 + 5b_0 + 3b_1 +10 a_1 x + 5b_1 x \right) \sin 2x = x\,\cos 2x .$
Equating polynomials of sine and cosine, we get
$\begin{split} 5a_0 +3 a_1 -10b_0 + 4b_1 &= 0, \\ 10b_1 -5a_1 &=1, \\ 10a_0 -4a_1 + 5b_0 + 3b_1 &=0, \\ 2a_1 + b_1 &=0 . \end{split}$
Solving the above system of equations, we obtain a particular solution
$y_p (x) = \frac{-1}{25} \left( 1 + x \right) e^{x} \, \cos 2x + \frac{2x}{25}\, e^{x} \, \sin 2x .$

Example: Consider the differential equation of second order whose characteristic polynomial has complex roots that do match the control numbers of the input function:

$L[\texttt{D}] y (x) = \left( \texttt{D}^2 +4 \right) y \equiv y'' +4\,y = 2\, x^2\, \sin 2x + 3x\, \cos x .$
The characteristic polynomial $$L[\lambda ] = \lambda^2 +4$$ has two complex conjugate roots $$\lambda = \pm 2{\bf j} ,$$ which matches the control number of the function $$2\, x^2\, \sin 2x .$$ Another function $$3x\, \cos x$$ has the control number σ = j (here j is a unit vector in vertical direction on the complex plane, so $${\bf j}^2 =-1$$ ). Therefore, we seek a particular solution in the form
$y_p (x) = x\left( a_0 + a_1 x + a_2 x^2 \right) \cos 2x + x \left( b_0 + b_1 x + b_2 x^2 \right) \sin 2x + \left( c_0 + c_1 x \right) \cos x + \left( c_3 + c_4 x \right) \sin x ,$
with some coefficients to be determined. Substituting yp into the differential equation, we obtain
$L[\texttt{D}] y_p (x) = 2\left[ a_1 + 2b_0 + \left( 3a_2 + 4b_1 \right) x + 6 b_2 x^2 \right] \cos 2x + 2\left[ b_1 - 2a_0 + \left( 3b_2 - 4a_1 \right) x - 6 a_2 x^2 \right] \sin 2x + \left( 3c_0 + 2c_4 + 3c_1 x \right) \cos x + \left( 3c_3 -2c_1 + 3c_4 x \right) \sin x.$
To make the result equal to the input function $$2\, x^2\, \sin 2x + 3x\, \cos x ,$$ we choose coefficients so that
$\begin{split} a_1 +2 b_0 &= 0, \\ 3a_2 +4b_1 &=0, \\ 6b_2 &=0, \\ b_1 -2a_0 &=0, \\ 3b_2 - 4 a_1 &=0 , \\ -6a_2 &= 1; \end{split} \qquad \mbox{and} \qquad \begin{split} 3c_0 +2 c_3 &= 0, \\ 3c_1 &=1, \\ 3c_2 -2c_1 &=0, \\ c_3 &=0 . \end{split}$
Solving these two systems of algebraic equations, we get the particular solution
$y_p (x) = x \left( \frac{1}{16} - \frac{x^2}{6} \right) \cos 2x - \frac{x^2}{8}\, \sin 2x + \frac{x}{3}\,\cos x + \frac{2}{9}\, \sin x .$
We verify with Mathematica:
y[x_] = Cos[2*x]*(a0 + a1*x + a2 ** x^2)*x + Sin[2*x]*(b0 + b1*x + b2*x^2)*x
D[y[x], x, x] + 4*y[x]
Simplify[%]
2 a1 Cos[2 x] + 4 b0 Cos[2 x] + 8 b1 x Cos[2 x] + 12 b2 x^2 Cos[2 x] + 2 x Cos[2 x] 0 ** (2 x) + x Cos[2 x] a2 ** 2 + 2 Cos[2 x] a2 ** (2 x) - 4 a0 Sin[2 x]
+ 2 b1 Sin[2 x] - 8 a1 x Sin[2 x] + 6 b2 x Sin[2 x] - 4 x a2 ** (2 x) Sin[2 x] - 4 a2 ** x^2 Sin[2 x] + 0 ** x^2 ((2 + x) Cos[2 x] - 4 x Sin[2 x])
If you try to solve the problem directly, Mathematica will provide you the answer that is hard to intrepid.
DSolve[z''[x] + 4*z[x] == x^2*Cos[2*x], z, x]
{{z -> Function[{x}, C[1] Cos[2 x] + C[2] Sin[2 x] +
1/384 (-3 Cos[2 x] Cos[4 x] + 24 x^2 Cos[2 x] Cos[4 x] + 32 x^3 Sin[2 x] + 12 x Cos[4 x] Sin[2 x] - 12 x Cos[2 x] Sin[4 x] - 3 Sin[2 x]

Example: Consider the differential equation of fourth order whose characteristic polynomial has complex roots that do match the control numbers of the input function:

$L[\texttt{D}] y (x) = \left( \texttt{D}^2 +4 \right)^2 y \equiv \left( \texttt{D}^4 + 8 \texttt{D}^2 +16 \right) y \equiv y^{(4)} +8\,y'' +16\,y' -y = 2\, x^2\, \sin 2x + 3x\, \cos x .$
Since the input function, $$2\, x^2\, \sin 2x + 3x\, \cos x ,$$ is the sum of two functions of control numbers σ = 2j and σ = j, it is annihilated by the differential operator $$M\left[ \texttt{D} \right] = \left( \texttt{D}^2 +4 \right)^3 \left( \texttt{D}^2 +1 \right)^2 .$$ Multiplying both sides of the given differential equation by $$M\left[ \texttt{D} \right] ,$$ we reduce it to a homogeneous equation
$M[\texttt{D}] \, L[\texttt{D}] y (x) \equiv L[\texttt{D}] \, M[\texttt{D}] y (x) \equiv \left( \texttt{D}^2 +4 \right)^5 \left( \texttt{D}^2 +1 \right)^2 y(x) =0 .$
Therefore, we seek a particular solution in the form:
$y_p (x) = x^2 \left( a_0 + a_1 x + a_2 x^2 \right) \cos 2x + x^2 \left( b_0 + b_1 x + b_2 x^2 \right) \sin 2x + \left( c_1 + c_2 x \right) \cos x + \left( c_3 + c_4 x \right) \sin x ,$
with some coefficients to be determined. Substituting yp into the differential equation, we obtain
$L[\texttt{D}] y_p (x) = -8 \left[ 4a_1 - 3a_2 - 6b_1 +3 \left( 4a_1 - 8b_2 \right) x + 8 a_2 x^2 \right] \cos 2x - 8\left[ 6a_1 + 4b_0 -3b_2 + 12\left( 2a_2 + b_1 \right) x + 24 b_2 x^2 \right] \sin 2x + \left( 3c_0 + 2c_4 + 3c_1 x \right) \cos x + \left( 3c_3 -2c_1 + 3c_4 x \right) \sin x.$
To make the result equal to the input function $$2\, x^2\, \sin 2x + 3x\, \cos x ,$$ we choose coefficients so that
$\begin{split} 4a_0 -3a_2 -6 b_1 &= 0, \\ 4a_1 - 8b_2 &=0, \\ a_2 &=0, \\ 6a_1 +4 b_0 -3b_2 &=0, \\ 2a_2 + b_1 &=0 , \\ -96b_2 &= 1; \end{split} \qquad \mbox{and} \qquad \begin{split} 17c_1 -4 c_4 &= 0, \\ 17c_2 &=1, \\ 4c_2 + 17 c_3 &=0, \\ 17 c_4 &=0 . \end{split}$
Solving these two systems of algebraic equations, we get the particular solution
$y_p (x) = - \frac{x^3}{48} \, \cos 2x + x^2 \left( \frac{3}{128} - \frac{x^2}{96}\right) \sin 2x + \frac{x}{17}\,\cos x - \frac{4}{289}\, \sin x .$