# How to solve a BVP with known parameters?

I need to solve a boundary value problem (BVP) of second order, where the equation depends on several know parameters, which are geometric parameters and material constants.

I would like to solve this equation for several combinations of values of the known parameters. Is it possible to do this using solve_bvp()? I am thinking along the lines of the args parameter in solve_ivp().

In case my question is unclear, imagine I want to solve the Bratu equation from the solve_bvp() documentation for several values of k, without having to each time change the value of k in the function fun(x,y). How can this be accomplished?

• The documentation says you can write a function of the form f(x,y,p) where p will be an array of additional parameters. So you could just pass k in as an element of p. Commented Dec 12, 2021 at 1:12
• Thanks @Tyberius for your comment but the documentation says "p is a k-D vector of unknown parameters ". In my case, the parameters are known Commented Dec 12, 2021 at 11:30
• Sorry, I had glossed over that in the docs. I think I may have found an alternative solution that I added as an answer. Commented Dec 12, 2021 at 16:25

## 1 Answer

It looks like solve_ivp also didn't have args until fairly recently, see the issue on GitHub.

The workaround they suggest there is to use a lambda expression around your function, which will have the other arguments set as keywords.

For the Bratu equation, reworking the example from the documentation, I believe this would look like:

def fun(x, y,k=0):
return np.vstack((y[1], -k*np.exp(y[0])))

def bc(ya, yb):
return np.array([ya[0], yb[0]])

x = np.linspace(0, 1, 5)
y_a = np.zeros((2, x.size))

res_a = solve_bvp(lambda x,y: fun(x,y,k=1), bc, x, y_a)

• why do you define k=0 in the definition of fun? Commented Jun 6, 2023 at 18:25
• @RonShvartsman this was just to make clear that k is a keyword argument, rather than a positional one. I could also have written def fun(x,y,*,k) to make it a keyword without setting a default value. Commented Jun 6, 2023 at 18:46