Why the result by hand is different from the built-in DSolve?

Yesterday, I used Mathematica to solve a differential equation using the built-in command DSolve[]:

DSolve[y''[x] + 2 y'[x] + 5 y[x] == x Cos[x], y[x], x]

{{y[x] ->
E^-x C[2] Cos[2 x] + E^-x C[1] Sin[2 x]
+ 1/200 (-25 Cos[x] Cos[2 x] + 25 x Cos[x] Cos[2 x]
- 3 Cos[2 x] Cos[3 x] + 15 x Cos[2 x] Cos[3 x]
- 25 x Cos[2 x] Sin[x] + 25 x Cos[x] Sin[2 x]
+ 4 Cos[3 x] Sin[2 x] + 5 x Cos[3 x] Sin[2 x]
- 25 Sin[x] Sin[2 x] + 25 x Sin[x] Sin[2 x]
- 4 Cos[2 x] Sin[3 x] - 5 x Cos[2 x] Sin[3 x]
- 3 Sin[2 x] Sin[3 x] + 15 x Sin[2 x] Sin[3 x])}}


However, I felt the result is too complex. So I calculate it by hand as shown below.

Characteristic equation: $r^2+2r+5=0 \Rightarrow r_1 = -1 + 2i, r_2 = -1 - i$

So the Non-homogeneous equation general solution is:$e^{-x}(C_1 \cos(2x)+C_2 \sin(2x))$

I use the Differential Operator method to calculate the non-homogeneous particular solution:

So my question is why the two results are different? Can someone tell me the reason?

-
If you simplify M answer, then it becomes: Simplify[%]; y[x] -> 1/50 E^-x (50 C[2] Cos[2 x] + E^x (-1 + 5 x) Sin[x] +Cos[x] (E^x (-7 + 10 x) + 100 C[1] Sin[x])) – Nasser Nov 17 '13 at 3:35

They are the same answer, as verified below. You can use the Simplify command to simplify things if needed:

mma = y[x] /. First@DSolve[y''[x] + 2 y'[x] + 5 y[x] == x Cos[x], y[x], x];
handH = E^(-x)*(C[2] Cos[2 x] + C[1] Sin[2 x]);
handP = (1/5 x - 7/50) Cos[x] + (1/10 x - 1/50) Sin[x];
hand = handH + handP;
Simplify[mma - hand]


                                0


QED

-

One could also feed the ODE into DifferentialRoot[] (along with arbitrary initial conditions) and then apply FunctionExpand[].

sol = FunctionExpand[DifferentialRoot[Function[{y, x},
{y''[x] + 2 y'[x] + 5 y[x] == x Cos[x],
y[0] == C[1], y'[0] == C[2]}]][x]];


Some trickery with Collect[] then displays a solution qualitatively similar to the one derived by hand:

Collect[sol, _Cos | _Sin, Simplify]
(-7/50 + x/5) Cos[x] + 1/50 E^-x (7 + 50 C[1]) Cos[2 x] +
1/50 (-1 + 5 x) Sin[x] + 1/50 E^-x (-1 + 25 C[1] + 25 C[2]) Sin[2 x]


Notice that although the multipliers for E^-x Cos[2 x] and E^-x Sin[2 x] have a complicated form, they still are arbitrary constants.

-
J.M. Thanks for your new solution(for me) :) Actually, this question was a exercise when I prepared the postgraduate entrance examination three years ago. The first built-in that I know is DSolve[], very glad to know DifferentialRoot[] and FunctionExpand[] can also deal with this problem. – Shutao TANG Apr 20 at 1:26