[SciPy-User] How to create a request to change a function?

Augusto Dufloth dufloth at gmail.com
Fri Jan 31 17:40:22 EST 2020


Thanks for your email!

My point is: for the sake of the formal definition of ode, the function is
lacking a convenient feature.

Since you have to input as an argument a time array, it would be super
useful to have the option to also input time-varying arguments of the same
length as t.

Checking stackoverflow you find that many people would benefit from this
addition.

Because of the lack of this feature, I had to create my own ODE as a C
function. In a practical example the time to solve my system was reduced by
20 fold. As compared to the solution you provided (and I also tried in the
past). I believe this could be even faster, but I lack the skills of code
optimization.

Kind regards



On Sat, Feb 1, 2020 at 0:18 Fabrice Silva <silva at lma.cnrs-mrs.fr> wrote:

> see https://pastebin.com/TKt12AEE for a readable version of the code
> sample
>
> Le vendredi 31 janvier 2020, Fabrice Silva a écrit :
>
> Le vendredi 31 janvier 2020, Augusto Dufloth a écrit :
>
> Hello,
>
> I have a request to change one of scipy’s function.
>
> I am trying to use odeint to integrate a set of equations of motion. My
> state equations rely on time dependent inputs. And these inputs are numpy
> arrays.
>
> When I do a flight path reconstruction, the inputs comes from the inertial
> system of the aircraft and I plug it into the state equations, so I get the
> deterministic position of the aircraft and than I can compare it to the
> measured values.
>
> The issue is that I can’t input an array. Searching stackoverflow I saw
> solutions using for-loops and assigning an arg for each time step. This is
> counter productive and create a huge time calculation for long arrays.
>
> I created my own C-dll to deal with this for loop issue, but it’s super
> counter productive.
>
> Can we get an option that the input args are arrays if same size of t, and
> as the state is integrated, the index of the arg follows the states?
>
>
> Hi,
> As far as I understand, you want to use time-varying parameters (which
> includes right-hand side terms of ODEs) specified as numpy array (i.e., at
> discrete time values) while ODEs are defined in the continuous-time domain.
> Specification of an extrapolation method is required for the well-posedness
> of the problem: the most trivial is the "Sample-and-hold" process which
> maintain values until next sample step.
>
> One simple solution (maybe one that you arleady tested) is to use the ode
> class and its integrate method.
> Adapting the example given in the docs
>
> https://docs.scipy.org/doc/scipy/reference/generated/scipy.integrate.ode.html#scipy.integrate.ode
>
> from scipy.integrate import ode
>
>
> def f(t, y, arg1):
>
>     return [1j*arg1*y[0] + y[1], -arg1*y[1]**2]
>
> def jac(t, y, arg1):
>
>     return [[1j*arg1, 1], [0, -arg1*2*y[1]]]
>
>
> r = ode(f, jac).set_integrator('zvode', method='bdf')
>
>
> t = np.arange(0, 10, 1)
>
> results = np.empty((len(t), 1 + len(y0)), dtype=float) + np.nan
>
>
> r.set_initial_value([1.0j, 2.0], t[0])
>
> for ind in range(len(t) - 1):
>
>     r.set_f_params(param[ind]).set_jac_params(param[ind])
>
>     tmp_result = r.integrate(t[ind+1])
>
>     if not r.successful():
>
>         break
>
>     results[ind] = tmp_result
>
>
> This introduced a reasonnable overhead in performance while begin quite
> readable.
>
> Best regards
>
> Fabrice
>
>
> _______________________________________________
> SciPy-User mailing list
> SciPy-User at python.org
> https://mail.python.org/mailman/listinfo/scipy-user
>
-- 
"The greatest challenge to any thinker is stating the problem in a way that
will allow a solution."
- Bertrand Russell
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/scipy-user/attachments/20200201/1261dab7/attachment.html>


More information about the SciPy-User mailing list