ODE
\[ \left (x^2+1\right ) y''(x)+4 x y'(x)+2 y(x)=2 (\cos (x)-x) \] ODE Classification
[[_2nd_order, _exact, _linear, _nonhomogeneous]]
Book solution method
TO DO
Mathematica ✓
cpu = 0.046286 (sec), leaf count = 33
\[\left \{\left \{y(x)\to -\frac {-3 c_2 x-3 c_1+x^3+6 \cos (x)}{3 x^2+3}\right \}\right \}\]
Maple ✓
cpu = 0.021 (sec), leaf count = 31
\[ \left \{ y \left ( x \right ) ={\frac {-{x}^{3}+3\,{\it \_C1}\,x-6\,\cos \left ( x \right ) +3\,{\it \_C2}}{3\,{x}^{2}+3}} \right \} \] Mathematica raw input
DSolve[2*y[x] + 4*x*y'[x] + (1 + x^2)*y''[x] == 2*(-x + Cos[x]),y[x],x]
Mathematica raw output
{{y[x] -> -((x^3 - 3*C[1] - 3*x*C[2] + 6*Cos[x])/(3 + 3*x^2))}}
Maple raw input
dsolve((x^2+1)*diff(diff(y(x),x),x)+4*x*diff(y(x),x)+2*y(x) = 2*cos(x)-2*x, y(x),'implicit')
Maple raw output
y(x) = (-x^3+3*_C1*x-6*cos(x)+3*_C2)/(3*x^2+3)