Numerical Solution to 2nd order nonlinear ODE I have the following ODE: $$x^2 f’’(x)+x f’(x)+(x^2-s^2)f-x^2 f^3=0$$ which looks like a Bessel differential equation but with an extra nonlinear term. I wonder how it can be solved numerically if i only know f(0)=0 and f tends to 1 as x tends to infinity.  Can anyone help? I only know python and mathematica.
 A: Your differential equation is singular at the left interval end $x=0$ and ithe solution is demanded to have a bounded asymptotic behavior towards $x=\infty$.

*

*Around $x=0$ the equation is dominated or closely approximated by the Euler-Cauchy equation
$$
x^2f''(x)+xf'(x)-s^2f(x)=0.
$$
This has basis solutions $x^s$ and $x^{-s}$, of which only the first one is permitted to occur in a bounded solution. Thus the solution we seek follows $xf'(x)-sf(x)=0$, which gives a suitable boundary condition for some $x_0\gtrapprox 0$ as left interval boundary.


*For large $x$ "in the far field" your equation is close to
$$
f''+f-f^3=0
$$
which has a first integral $$E=\frac12f'^2-\frac14(f^2-1)^2.$$ This has closed orbits around the center at $(f,f')=(0,0)$ and saddle points at $(f,f')=(\pm1,0)$. To get the limit behavior, your solution needs to reach and closely follow the stable manifold of the saddle point $(f,f')=(1,0)$, so $E=0$. To stably approach this point, $f'(x)$ needs to have the opposite sign of $(f(x)-1)$, giving as the correct square root $f'(x)=\sqrt{\frac12}(1-f(x)^2)$. This gives the boundary condition for some large $x_f$ as right interval boundary.
Thus select some small $x_0$ and some largish $x_f$ and solve the full ODE with boundary conditions
$$
x_0f'(x_0)-sf(x_0)=0~\text{ and }~ \sqrt{2}f'(x_f)+(f(x_f)^2-1)=0
$$
