<html dir="ltr"><head></head><body style="text-align:left; direction:ltr;"><div>see <a href="https://pastebin.com/TKt12AEE">https://pastebin.com/TKt12AEE</a> for a readable version of the code sample</div><div><br></div><div>Le vendredi 31 janvier 2020, Fabrice Silva a écrit :</div><blockquote type="cite" style="margin:0 0 0 .8ex; border-left:2px #729fcf solid;padding-left:1ex"><div>Le vendredi 31 janvier 2020, Augusto Dufloth a écrit :</div><blockquote type="cite" style="margin:0 0 0 .8ex; border-left:2px #729fcf solid;padding-left:1ex"><div dir="auto">Hello,</div><div dir="auto"><br></div><div dir="auto">I have a request to change one of scipy’s function.</div><div dir="auto"><br></div><div dir="auto">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.</div><div dir="auto"><br></div><div dir="auto">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.</div><div dir="auto"><br></div><div dir="auto">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.</div><div dir="auto"><br></div><div dir="auto">I created my own C-dll to deal with this for loop issue, but it’s super counter productive. </div><div dir="auto"><br></div><div dir="auto">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?</div></blockquote><div><br></div><div>Hi,</div><div>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.</div><div><br></div><div>One simple solution (maybe one that you arleady tested) is to use the ode class and its integrate method.</div><div>Adapting the example given in the docs </div><div><a href="https://docs.scipy.org/doc/scipy/reference/generated/scipy.integrate.ode.html#scipy.integrate.ode">https://docs.scipy.org/doc/scipy/reference/generated/scipy.integrate.ode.html#scipy.integrate.ode</a></div><div><br></div><pre>from scipy.integrate import ode</pre><br><pre>def f(t, y, arg1):</pre><pre>    return [1j*arg1*y[0] + y[1], -arg1*y[1]**2]</pre><pre>def jac(t, y, arg1):</pre><pre>    return [[1j*arg1, 1], [0, -arg1*2*y[1]]]</pre><br><pre>r = ode(f, jac).set_integrator('zvode', method='bdf')</pre><br><pre>t = np.arange(0, 10, 1)</pre><pre>results = np.empty((len(t), 1 + len(y0)), dtype=float) + np.nan</pre><br><pre>r.set_initial_value([1.0j, 2.0], t[0])</pre><pre>for ind in range(len(t) - 1):</pre><pre>    </pre><font color="#ff0000"><pre>r.set_f_params(param[ind]).set_jac_params(param[ind])</pre></font><pre>    tmp_result = r.integrate(t[ind+1])</pre><pre>    if not r.successful():</pre><pre>        break</pre><pre>    results[ind] = tmp_result</pre><div><br></div><div>This introduced a reasonnable overhead in performance while begin quite readable.</div><div><br></div><div>Best regards</div><div><br></div><div>Fabrice</div>
</blockquote><div><br></div></body></html>