Discard ODE singular solutions with Mathematica?

The solution for a homogeneous second order linear ODE is generally a constant times one function plus another constant times a different function. Sometimes one of the solution functions is singular, i.e. it blows up for some value of the independent variable. An example is Bessel's ODE. If one is just looking for nonsingular solutions, is there some way to have Mathematica discard the singular function so that the required solution is nonsingular? This would be helpful in the case where a large number of ODE's are generated. Otherwise there is a lot of human intervention needed to proceed. In my case, I have the ODE's, and the specific solutions found by DSolve with the singular solutions obvious by inspection. I just want to see if Mathematica can be used to remove the singular solutions.

Here's a quick and incredibly naive way of treating at least the Bessels. Not sure how robust it would be for more complicated things.

Module[{tol = 1*^-6, a = 3, nonsingularQ},
nonsingularQ = FindMinimum[Abs[1/# /. _C -> 1], x][[1]] > tol &;
Total[Select[#, nonsingularQ]] & /@
List @@@ Expand[
y[x] /. DSolve[
x^2 Derivative[2][y][x] +
x Derivative[1][y][x] + (x^2 - a^2) y[x] == 0, y[x], x]]]

• Looks good! I'll have to check your answer out. – Skybobcat Feb 6 '13 at 1:54
• Here is an example of an ODE that I have : y''[x]+Cot[x]*y'[x]+(2-Csc[x]^2)*y[x] = 0 . The nonsingular solution is Sin[x] times a constant, and the singular solution is complicated. We have 0 < x < Pi . – Skybobcat Feb 6 '13 at 2:06
• Did you try it? It worked for me, though I get C[1] Sqrt[-Sin[x]^2] for some reason. – Xerxes Feb 6 '13 at 2:12
• Using your work above, I got Sin[x] times a constant as the output for the ODE immediately above, which is correct. The singular solution was indeed suppressed. Thank you very much! – Skybobcat Feb 6 '13 at 2:56
• Yes, I get C[1] Sqrt[-Sin[x]^2], but if C[1] is purely imaginary, then the effective answer is C[1] Sin[x] for real C[1]. Also you can directly check by substitution that C[1] Sin[x] is correct for real C[1]. – Skybobcat Feb 6 '13 at 3:02

I doubt that there is an algorithm to decide (in reasonable generality) whether a solution to an ODE has a singularity on the real line. Consider e.g. $f(z) = 1/(\cos^2(z) + \cos^2(r z))$. This has a real singularity if and only if $r$ is a rational number of 2-adic order $0$. E.g. for $r=\gamma$ this is an open problem.

• In my case the singular solutions found by DSolve are obvious and rather elementary. Your example is over my head. So I don't really know what to make of your answer. – Skybobcat Feb 6 '13 at 1:24