I have the following second order differential equation I want to solve numerically in Python (or Matlab):
\begin{equation}
\frac{d^2y}{dx^2}=a \left[ \left(\frac{y}{b}\right)^{-3} – \left(\frac{y}{b}\right)^{-6} \right]
\end{equation}
with initials conditions $y(0)=b$ and $\frac{dy}{dx}(0)=c$, where where $a$,$b$,$c$ are some constants.
Now I reduced it to 2 first order ODEs when setting $p_1=\frac{dy}{dx}$ and $p_2=y(x)$:
\begin{equation}
\frac{dp_1}{dx}=a \left[ \left(\frac{y}{b}\right)^{-3} – \left(\frac{y}{b}\right)^{-6} \right], \hspace{3em} \frac{dp_2}{dx}=p_1
\end{equation}
But how to continue from here?
Best Answer
Here is how I solved it in MATLAB:
I tried to do the same in Python, but get strange results (think that MATLABs smart mesh is the difference):
EDIT: as suggested by @LutzLehmann, the equivalent to ODE45 in Python is
scipy.integrate.solve_ivp
: