I have the ODE

$\left(\frac{y'}{x^2 \rho(x)} \right)' + \frac{4 \pi G \rho(x)}{x^2 P(x)}\, y - \left( \frac{F(x)}{x^2 \rho(x)} \right)' = 0$

with the boundary conditions $y(x=0)=0, y(x=1)=0$. The independent variable is $x$, the variable I would like to solve for is $y(x)$, the functions $\rho$, $P$, and $F$ are all known as well as the constants $G$ and $4\pi$ (duh).

I would like to solve this equation numerically using scipy's sp.integrate.bvp_solve. For this I need to turn it into a first order system.

This is my attempt:

\begin{align} y_1' &= y_2 \\ y_2' &= \left(\frac{F}{x^2 \rho} \right)' - \frac{4 \pi G \rho}{x^2 P}\, y \end{align}

but I think that it is not correct because the first term in the original equation does not seem properly represented. Can someone please help?

  • $\begingroup$ The LHside of your second ODE should be $\left( \frac{y_2}{x^2 \rho(x)}\right)^\prime$ instead of $y_2^\prime$; and of course you should have $y_1$ instead of $y$ in the RHside. $\endgroup$
    – Pacciu
    Aug 7 '20 at 18:11
  • $\begingroup$ @Pacciu thanks - that makes a lot more sense - however I am still stuck as at least the examples in scipy all have "pure" variables on the LHS. Can I maybe integrate the second ODE to get something "pure"? Or do you have advice on how to proceed from there? $\endgroup$ Aug 7 '20 at 18:17

The original ODE can be written also as

$\left(\frac{y'-F(x)}{x^2 \rho(x)} \right)' + \frac{4 \pi G \rho(x)}{x^2 P(x)}\, y = 0$

and making

$$ \cases{y_1 = y\\ y_2=\frac{y_1'-F(x)}{x^2 \rho(x)} } $$

can be represented as

$$ \cases{ y'_1 = x^2\rho(x) y_2+F(x)\\ y'_2 = -\frac{4\pi G \rho(x)}{x^2 P(x)}y_1 }. $$

  • $\begingroup$ It works, it works, oh my gosh it works! You have made me a very happy person today. Thank you! $\endgroup$ Aug 8 '20 at 10:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.