# DSolve - Unable to obtain plot of solution - 2nd order ODE

I am trying to solve the equation below with DSolve. The equation is that of a wave, expected to fall off exponentially as r approaches infinity. The solution is a combination of Spherical Bessel functions, which is great! However, I am unable to obtain a plot of the solution after multiple tries with various ranges of r. Any suggestions will be appreciated.

sol = DSolve[{-w^2 f[r] + f''[r] + 2/r f'[r] - 2/r^2 f[r] == 0,
f[10^5] == 0, f'[10^5] == 1}, f, {r, 10^3, 10^5}]
test = Plot[{Evaluate[f[r] /. sol /. w -> 0.05 ]}, {r, 1*10^3,
1*10^5}, PlotRange -> {-10, 10}]

• The solution appears to be zero to high order for the parameters chosen. – bbgodfrey Jan 9 '19 at 20:13
• Try a scaling regarding $r$ – Cesareo Jan 9 '19 at 21:15
• You can see the exponential behavior by using FunctionExpand, which rewrites the spherical Bessel functions: DSolve[{-w^2 f[r] + f''[r] + 2/r f'[r] - 2/r^2 f[r] == 0, f[10^5] == 0, f'[10^5] == 1}, f[r], r] // FunctionExpand // TrigToExp // FullSimplify. More generally, DSolve[-w^2 f[r] + f''[r] + 2/r f'[r] - 2/r^2 f[r] == 0, f[r], r] // FunctionExpand gives you the solution for arbitrary boundary conditions. – Roman Jan 9 '19 at 22:31
• @Roman this certainly helps me see the solution in a form that makes more physical sense. However, the issue of not being able to plot it still remains, even for arbitrary boundary conditions. – mv1996 Jan 10 '19 at 18:03

The numerical alternative shows a plot

F = ParametricNDSolveValue[{-w^2 f[r] + f''[r] + 2/r f'[r] -2/r^2 f[r] == 0, f[10^5] == 0, f'[10^5] == 1},f, {r, 10^3, 10^5}, w]
Plot[{Evaluate[F[0.05][r] ]}, {r, 1*10^3, 1*10^5},PlotRange -> {-10, 10} ] The line has only real points near the right boundary.

• I used {r, 10^5, 10^35} in the above equation and obtained a plot. Thank you! Interestingly, the same range in DSolve did not give me a plot. – mv1996 Jan 15 '19 at 10:16

The function values are very large and a bit tricky to use. They are so large that plotting the function itself seems to overwhelm Mathematica's plot autoscaling. The following works to plot the logarithm of the function, to get an idea of the size of the numbers:

F[r_] = f[r] /. sol[] /. w -> 1/20 // FullSimplify
ListLinePlot[Table[{r, Log[Abs[F[r]]]}, {r, 10^3, 10^5, 10^3}]]


If you just evaluate the function numerically as N[F] // Re, you get zero (this is wrong). If you use high precision as N[F, 10^3] // Re you get more meaningful answers.