scipy.integrate.solve_bvp with explicit dependence on independent variable?
![](https://secure.gravatar.com/avatar/7f9b0e03e928855e6cb070b726b9b96a.jpg?s=120&d=mm&r=g)
Hello all, I am trying to use scipy.integrate.solve_bvp to solve a boundary value problem of a function in one variable -- $\phi(r)$ -- for a cylindrical geometry. The examples here are pretty good: https://docs.scipy.org/doc/scipy-0.18.1/reference/generated/scipy.integrate.... However, when casting into a ocupled first-order system, the issue here is that I have explicit dependence on the independent variable $r$. When I write the equivalent of
def fun(x, y): ... return np.vstack((y[1], -np.exp(y[0])))
, the interpreter promptly replies "TypeError: only length-1 arrays can be converted to Python scalars" -- this makes sense, since So, can scipy.integrate.solve_bvp be used in problems where there's an explicit dependence on $r$, for functions where the right-hand side is F(dq/dx, q, r)? Cheers! -- Boyan Penkov
![](https://secure.gravatar.com/avatar/da3a0a1942fbdc5ee9a9b8115ac5dae7.jpg?s=120&d=mm&r=g)
ke, 2017-10-25 kello 16:01 -0400, Boyan Penkov kirjoitti: [clip]
So, can scipy.integrate.solve_bvp be used in problems where there's an explicit dependence on $r$, for functions where the right-hand side is F(dq/dx, q, r)?
Does "dq/dx" mean "dq/dr" and equation of type d^2 q/dr^2 = F(dq/dr, q, r) Then the yes, the independent variable is the first argument in "def fun(r, y)". If this is not what you are looking for, if you write explicitly the first order system you want to solve maybe better answers come. -- Pauli Virtanen
![](https://secure.gravatar.com/avatar/7f9b0e03e928855e6cb070b726b9b96a.jpg?s=120&d=mm&r=g)
-- Boyan Penkov www.boyanpenkov.com
On Oct 25, 2017, at 18:51, Pauli Virtanen <pav@iki.fi> wrote:
ke, 2017-10-25 kello 16:01 -0400, Boyan Penkov kirjoitti: [clip]
So, can scipy.integrate.solve_bvp be used in problems where there's an explicit dependence on $r$, for functions where the right-hand side is F(dq/dx, q, r)?
Does "dq/dx" mean "dq/dr" and equation of type
d^2 q/dr^2 = F(dq/dr, q, r)
Whoops, yeah…. you are correct, I do indeed mean dq/dr...
Then the yes, the independent variable is the first argument in "def fun(r, y)". If this is not what you are looking for, if you write explicitly the first order system you want to solve maybe better answers come.
The issue seems to be that I then generally have x = linspace(….) which makes the output of fun(x,y) have length len(x) + 1 and not just 2, as may be expected. Is there a syntactic solution to this?
-- Pauli Virtanen _______________________________________________ SciPy-User mailing list SciPy-User@python.org https://mail.python.org/mailman/listinfo/scipy-user
participants (2)
-
Boyan Penkov
-
Pauli Virtanen