I recently needed to solve a second order boundary value problem and noticed that both scipy.integrate.solve_bvp and Matlab's bvp4c and bvp5c do not seem to support the passing of known parameters to the function odefun defining $\frac{dy}{dx}$ or the residual function which determines the boundary condtions bcfun.

They do however allow for unknown parameters to be simultaneously inferred while solving the problem. This seems like a strange API limitation, so I wonder if there is a reason for this.

I am used to working with solvers for initial value problems and optimizers for general minimization problems, and in both cases the APIs I'm familiar with allow defining the relevant functions such that they accept additional "known" parameters, e.g. scipy.integrate.solve_ivp allows defining $\frac{dy}{dx} = f(x, y, a, b, c)$ and then passing the values for $a$, $b$ and $c$ as a tuple when solving the problem.

  • $\begingroup$ You can fix the known parameters in the set of unknown parameters via the boundary condition function. Of course, you can also pass the constant parameters via closure/anonymous function @(x,y)odefun(x,y,a,b,c). $\endgroup$ Jan 18, 2023 at 12:08
  • $\begingroup$ @LutzLehmann, how do you specify the values for the unknown parameters? These must be defined within the bc function to define the residual. Yes, a closure is a natural solution programmatically. In my case I've just used nested scope to define the parameters outside of the functions and then use their values in their definitions. In either cause my question is if there is a reason for this API vs one where additional arguments are supported explicitly? $\endgroup$
    – user9794
    Jan 18, 2023 at 12:20
  • $\begingroup$ I think one reason is that this one interface serves a multitude of different functions. It might perhaps have made the divination of the wanted function more complicated. Another point could be that all BVP solvers are somewhat experimental, their heuristic geared towards simple-scaled problems, no universal globalization strategy available,... Thus less effort to expand the interface. // In bcfun(ya,yb,p) return residuals p(1)-para1, p(2)-para2,... along with the proper BC residuals. $\endgroup$ Jan 18, 2023 at 12:34
  • $\begingroup$ Thanks for the response. Yes, but values for para1, para2, ... para3 must be provided to the function somehow, which leaves one with the same problem of either using a explicit values in the definition or a closure/nested scope to allow dynamic definition. $\endgroup$
    – user9794
    Jan 18, 2023 at 13:07
  • $\begingroup$ Usually global variables can be used as constants in functions inside the same script without any further overhead. It depends on the context if there are obstructions to this. I'm not sure how this would work in a "one script per function" framework. I believe then one would have to use closures again, which would make this approach redundant as one can then also use a closure on the ODE function. $\endgroup$ Jan 18, 2023 at 13:42


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.