87.16.15 problem 15

Internal problem ID [23584]
Book : Ordinary differential equations with modern applications. Ladas, G. E. and Finizio, N. Wadsworth Publishing. California. 1978. ISBN 0-534-00552-7. QA372.F56
Section : Chapter 2. Linear differential equations. Exercise at page 119
Problem number : 15
Date solved : Thursday, October 02, 2025 at 09:43:12 PM
CAS classification : [[_2nd_order, _linear, _nonhomogeneous]]

\begin{align*} x y^{\prime \prime }-2 y^{\prime }+\frac {\left (x^{2}+2\right ) y}{x}&=4+\tan \left (x \right ) \end{align*}
Maple. Time used: 0.007 (sec). Leaf size: 53
ode:=x*diff(diff(y(x),x),x)-2*diff(y(x),x)+(x^2+2)/x*y(x) = 4+tan(x); 
dsolve(ode,y(x), singsol=all);
 
\[ y = x \sin \left (x \right ) c_2 +x \cos \left (x \right ) c_1 -\int \frac {\sin \left (x \right ) \left (4+\tan \left (x \right )\right )}{x^{2}}d x x \cos \left (x \right )+\sin \left (x \right ) \left (\operatorname {Ci}\left (x \right ) x -4 \,\operatorname {Si}\left (x \right ) x -4 \cos \left (x \right )-\sin \left (x \right )\right ) \]
Mathematica. Time used: 14.698 (sec). Leaf size: 103
ode=x*D[y[x],{x,2}]-2*D[y[x],x]+(x^2+2)/x*y[x]==4+Tan[x]; 
ic={}; 
DSolve[{ode,ic},y[x],x,IncludeSingularSolutions->True]
 
\begin{align*} y(x)&\to \frac {1}{2} e^{-i x} x \left (2 \int _1^x\frac {i e^{i K[1]} (\tan (K[1])+4)}{2 K[1]^2}dK[1]-i e^{2 i x} \int _1^x\frac {e^{-i K[2]} (\tan (K[2])+4)}{K[2]^2}dK[2]-i c_2 e^{2 i x}+2 c_1\right ) \end{align*}
Sympy
from sympy import * 
x = symbols("x") 
y = Function("y") 
ode = Eq(x*Derivative(y(x), (x, 2)) - tan(x) - 2*Derivative(y(x), x) - 4 + (x**2 + 2)*y(x)/x,0) 
ics = {} 
dsolve(ode,func=y(x),ics=ics)
 
NotImplementedError : The given ODE Derivative(y(x), x) - (x*(x*y(x) + x*Derivative(y(x), (x, 2)) -