I'm trying to solve the following equations numerically in python
$$\begin{align} 12\pi\int_0^\infty drf(r)\phi(r)r^4&=E\\ f(r)-\frac{1}{2\mu}\bigg(\frac{d^2\phi(r)}{dr^2}+\frac{2}{r}\frac{d\phi(r)}{dr} \bigg)+m_\pi\phi(r)&=E\phi(r) \end{align} $$
where $f(r)=S\exp(-r^2/b^2)$, while $\mu$ and $m_π$ are constants.
I have tried rewriting the 2nd order differential equation into two first order equations and solving the system of equations with root finding.
import numpy as np
from scipy.integrate import odeint
import matplotlib.pyplot as plt
from scipy.integrate import trapz
from scipy.optimize import root
b=1
S=20
m=135
mn = 939.5
mu = m*mn/(mn+m)
g = (2*mu)
def f(r):
return S*np.exp(-r**2/b**2)
def diff(phi,r,E):
return (phi[1],g*(-E+m)*phi[0]-2/r*phi[1]+g*f(r))
phi0 = [b/m,b/m] #Initial
def phi_fun(E):
rs = np.linspace(1e-5,50,1000)
ys = odeint(lambda phi,r: diff(phi,r,E), phi0, rs)
integral = 12*np.pi*trapz(ys[:,0]*f(rs)*rs**4,rs)
return integral - E
E_true = root(phi_fun, -2).x
rs = np.linspace(1e-5,50,1000)
ys = odeint(lambda phi,r: diff(phi,r,E_true), phi0, rs)
phi_true = ys[:,0]
plt.plot(rs, phi_true,linewidth=2,label=r'$\phi(r)$')
print("Minimum found at E =",E_true)
This does not produce a result I would expect and maybe I have done something wrong. I was thinking about using IDEsolver but I'm not sure how to implement this. Any suggestions? Thanks in advance!