I'm trying to solve the following boundary value problem on $[0,\infty]$:
$$f^{\prime \prime}=-\frac{1}{r} f^{\prime}+\frac{1}{r^{2}} f+m^{2} f+2 \lambda f^{3}$$
$$f(0)=0 \ ; f(\infty)=\sqrt{-m^2/(2\lambda)} $$
for some constants $m^2<0, \lambda>0$. There is no closed form but we should have $f$ monotonically increasing from $0$ to $\sqrt{-m^2/(2\lambda)}$. There is a removable singularity at $r=0$. The problem is just Bessel's equation plus a term in $f^3$.
I'm trying to solve this with Scipy's integrate.solve_bvp
which can solve multi-boundary problems with a singularity at one boundary, defining $y=\begin{bmatrix}
f \\
rf' \\
\end{bmatrix}$ so that
$$y'=\begin{bmatrix} 0 \\ r(m^2f+2\lambda f^3) \\ \end{bmatrix}+\frac{1}{r}\begin{bmatrix} 0 \ \ 1 \\ 1 \ \ 0 \\ \end{bmatrix}y$$
I impose the boundary condition at infinity at some large value max_x
. Unfortunately my code, following the structure of the example at https://docs.scipy.org/doc/scipy/reference/generated/scipy.integrate.solve_bvp.html, gives the wrong solution:
import scipy.integrate
import numpy as np
import matplotlib.pyplot as plt
m_squared=-1
Lambda=1
asymptote=np.sqrt(-m_squared/(2*Lambda))
#evaluate infinity b.c here
max_x=100
def fun(r,v):
z=(m_squared*v[0]+(2*Lambda)*(v[0]**3) )*r
return np.vstack((z-z, z))
#boundary condition
def bc(ya,yb):
return np.array([ya[0], yb[0]-asymptote])
# to treat singularity
S=np.array([[0,1],[1,0]])
x=np.linspace(0,max_x,5000)
# guess for vector y at points x
y=np.zeros((2, len(x)))
y[0,-1]=asymptote
print(y)
#solve
res=scipy.integrate.solve_bvp(fun, bc, x, y, p=None, S=S)
x_plot=np.linspace(0,max_x,1000)
y_plot=res.sol(x_plot)[0]
plt.plot(x_plot,y_plot,label="numerical")
plt.axhline(asymptote,linestyle="--",label="asymptote")
plt.xlabel("r")
plt.ylabel("f")
plt.legend()
I checked that modifying the above code to solve e.g $f''=f-1$ with $f(0)=0, f(\infty)=1$ works fine. There are no singularity in this case, so it suffices to modify fun
and set S=None
.
Is there an issue with my code or should I use a different boundary value solver?