Python: проблема с scipysolve_ivp и событиемPython

Программы на Python
Гость
Python: проблема с scipysolve_ivp и событием

Сообщение Гость »


Мой код намного сложнее, но я могу воспроизвести проблему на следующем примере:

Код: Выделить всё

import numpy as np
from scipy.integrate import solve_ivp

def funct(t, y):
return -np.sqrt(y)

def event(t, y):
return y[0]-0.1

if __name__ == '__main__':
event.terminal = True
sol = solve_ivp(funct, t_span=[0, 3], y0=[1], events=event)
As one can expect, if y < 0, a warning is raised but for this specific example a solution is still found. However, my code stop working because I am using a third-party package that throws an error when something like this happen.
Now, I know that the event is computed via an iteration method, so my question would be: is it possible to avoid that during the iterations, the value of y is going below a given threshold and avoid the error/warning? So, something like "if y < 0 then reject the step" or something similar?


Источник: https://stackoverflow.com/questions/781 ... -and-event

Вернуться в «Python»