<div><div dir="auto">Thanks for your email!</div><div dir="auto"><br></div><div dir="auto">My point is: for the sake of the formal definition of ode, the function is lacking a convenient feature. </div><div dir="auto"><br></div><div dir="auto">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.</div><div dir="auto"><br></div><div dir="auto">Checking stackoverflow you find that many people would benefit from this addition.</div><div dir="auto"><br></div><div dir="auto">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.</div><div dir="auto"><br></div><div dir="auto">Kind regards</div></div><div dir="auto"><br></div><div dir="auto"><br></div><div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Sat, Feb 1, 2020 at 0:18 Fabrice Silva <<a href="mailto:silva@lma.cnrs-mrs.fr">silva@lma.cnrs-mrs.fr</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;padding-left:1ex;border-left-color:rgb(204,204,204)"><div style="text-align:left;direction:ltr"><div>see <a href="https://pastebin.com/TKt12AEE" target="_blank">https://pastebin.com/TKt12AEE</a> for a readable version of the code sample</div></div><div style="text-align:left;direction:ltr"><div><br></div><div>Le vendredi 31 janvier 2020, Fabrice Silva a écrit :</div><blockquote type="cite" style="margin:0px 0px 0px 0.8ex;border-left-width:2px;border-left-style:solid;padding-left:1ex;border-left-color:rgb(114,159,207)"><div>Le vendredi 31 janvier 2020, Augusto Dufloth a écrit :</div><blockquote type="cite" style="margin:0px 0px 0px 0.8ex;border-left-width:2px;border-left-style:solid;padding-left:1ex;border-left-color:rgb(114,159,207)"><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" target="_blank">https://docs.scipy.org/doc/scipy/reference/generated/scipy.integrate.ode.html#scipy.integrate.ode</a></div><div><br></div><pre style="font-family:monospace">from scipy.integrate import ode</pre><br><pre style="font-family:monospace">def f(t, y, arg1):</pre><pre style="font-family:monospace"> return [1j*arg1*y[0] + y[1], -arg1*y[1]**2]</pre><pre style="font-family:monospace">def jac(t, y, arg1):</pre><pre style="font-family:monospace"> return [[1j*arg1, 1], [0, -arg1*2*y[1]]]</pre><br><pre style="font-family:monospace">r = ode(f, jac).set_integrator('zvode', method='bdf')</pre><br><pre style="font-family:monospace">t = np.arange(0, 10, 1)</pre><pre style="font-family:monospace">results = np.empty((len(t), 1 + len(y0)), dtype=float) + np.nan</pre><br><pre style="font-family:monospace">r.set_initial_value([1.0j, 2.0], t[0])</pre><pre style="font-family:monospace">for ind in range(len(t) - 1):</pre><pre style="font-family:monospace"> </pre><font style="color:rgb(255,0,0)"><pre style="font-family:monospace">r.set_f_params(param[ind]).set_jac_params(param[ind])</pre></font><pre style="font-family:monospace"> tmp_result = r.integrate(t[ind+1])</pre><pre style="font-family:monospace"> if not r.successful():</pre><pre style="font-family:monospace"> break</pre><pre style="font-family:monospace"> 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></div>
_______________________________________________<br>
SciPy-User mailing list<br>
<a href="mailto:SciPy-User@python.org" target="_blank">SciPy-User@python.org</a><br>
<a href="https://mail.python.org/mailman/listinfo/scipy-user" rel="noreferrer" target="_blank">https://mail.python.org/mailman/listinfo/scipy-user</a><br>
</blockquote></div></div>-- <br><div dir="ltr" class="gmail_signature" data-smartmail="gmail_signature">"The greatest challenge to any thinker is stating the problem in a way that will allow a solution." <br>- Bertrand Russell</div>