# Solving 2nd order ODE with NDSolve

I would like to solve the following differential equation with NDSolve:

NDSolve[{(1 + Sqrt[\[Pi] x])*y[x] + x*y'[x] - (x^2)/6*y''[x] == 1, y[0] == 1, y'[0] == 0}, y[x], {x, 0, 2}]


Mathematica says it encounters an infinite expression. I've tried shifting the initial point from 0 to 0.1 or 0.01 and it gives a growing exponential function that I think is nonphysical. This DE is an approximation to another DE that has as a solution MittagLefflerE[q,-x^q] with q = 3/2 here, which is decaying. The approximation should hold for 0 < x < 2.

I also tried coding up the solution using an explicit Euler scheme but it gives the same exponential-type solution. I'm pretty sure the solution is not supposed to be growing but I guess I could be wrong.

Any help with the DE is greatly appreciated!

The reason Mathematica says it got division by zero, because your initial conditions are not valid. They produce no solution.

The analytical solution to

$$\left( 1+\sqrt {\pi\,x} \right) y \left( x \right) +x{\frac {\rm d}{ {\rm d}x}}y \left( x \right) -1/6\,{x}^{2}{\frac {{\rm d}^{2}}{{\rm d} {x}^{2}}}y \left( x \right) =0$$

Is given by Maple as (DSolve does not seem to be able to solve this, after some time waiting).

$$y \left( x \right) ={\it \_C1}\,{x}^{7/2+1/2\,\sqrt {73}} {\mbox{_0F_1}(\ ;\,1+2\,\sqrt {73};\,24\,\sqrt {\pi}\sqrt {x})}+{ \it \_C2}\,{x}^{7/2-1/2\,\sqrt {73}} {\mbox{_0F_1}(\ ;\,1-2\,\sqrt {73};\,24\,\sqrt {\pi}\sqrt {x})}$$

Where $F_1$ is hypergeom function. Taking derivative of the above gives

$${\frac {\rm d}{{\rm d}x}}y \left( x \right) ={\frac {{\it \_C1}\,{x}^{ 7/2+1/2\,\sqrt {73}} \left( 7/2+1/2\,\sqrt {73} \right) {\mbox{_0F_1}(\ ;\,1+2\,\sqrt {73};\,24\,\sqrt {\pi}\sqrt {x})}}{x }}+12\,{\frac {{\it \_C1}\,{x}^{7/2+1/2\,\sqrt {73}} {\mbox{_0F_1}(\ ;\,2+2\,\sqrt {73};\,24\,\sqrt {\pi}\sqrt {x})} \sqrt {\pi}}{ \left( 1+2\,\sqrt {73} \right) \sqrt {x}}}+{\frac {{\it \_C2}\,{x}^{7/2-1/2\,\sqrt {73}} \left( 7/2-1/2\,\sqrt {73} \right) {\mbox{_0F_1}(\ ;\,1-2\,\sqrt {73};\,24\,\sqrt {\pi}\sqrt {x})}}{x }}+12\,{\frac {{\it \_C2}\,{x}^{7/2-1/2\,\sqrt {73}} {\mbox{_0F_1}(\ ;\,2-2\,\sqrt {73};\,24\,\sqrt {\pi}\sqrt {x})} \sqrt {\pi}}{ \left( 1-2\,\sqrt {73} \right) \sqrt {x}}}$$

You can now see that at $x=0$ there is a division by zero.

So your initial conditions are not valid or something wrong with your equations (may be did not copy it correctly from the book?).

• What a formidable solution! I see this now. Thank you, I'll mark this as correct. – Buddhapus Jun 17 '17 at 6:57

The easy way out is to give a starting value to $x$ to be 10^-4 not 0.

NDSolve[{(1 + Sqrt[π x])*y[x] + x*y'[x] - (x^2)/6*y''[x] == 1, y[10^-4] == 1,
y'[10^-4] == 0}, y[x], {x, 10^-4, 2}]

Plot[y[x] /. %, {x, 10^-4, 2}]

• I was able to find this solution before but I'm not sure it's physical. I'm looking for a decaying solution. – Buddhapus Jun 16 '17 at 9:33
• @Buddhapus Then you should check your equation. – zhk Jun 16 '17 at 11:02