我一直遇到一個問題,我的代碼不斷告訴我“中的值t_eval沒有正確排序”。我曾嘗試使用排序功能和手動排序(如下)。我沒有看到什么?我不知道如何解決這個問題。我幾乎可以肯定這是我忽略的非常簡單的事情,但我找不到它,而且作業將在一個小時后到期。
def pff(t, y, p):
if (2 < t) and (t < 4):
z = 1
else:
z = 0
dy = np.zeros(2)
dy[0]= (p[0] * (y[1] z)**p[3]) / (1 (y[1] z)**p[3]) - (p[2] * y[0])
dy[1]= (p[1] * (y[0] z)**p[3]) / (1 (y[0] z)**p[3]) - (p[2] * y[1])
alpha = 2
beta = 2
gamma = .5
n = 2
k = 1
p = [gamma, k, n, alpha, beta]
x_0 = np.zeros([0,])
t_span = [0, 20]
sol = integrate.solve_ivp(pff, t_span, x_0, 'RK45', p)
追溯:
ValueError Traceback (most recent call last)
~\AppData\Local\Temp/ipykernel_36808/2811005318.py in <module>
9 t_span = [0, 20]
10
---> 11 sol = integrate.solve_ivp(pff, t_span, x_0, 'RK45', p)
~\anaconda3\lib\site-packages\scipy\integrate\_ivp\ivp.py in solve_ivp(fun, t_span, y0, method, t_eval, dense_output, events, vectorized, args, **options)
527 d = np.diff(t_eval)
528 if tf > t0 and np.any(d <= 0) or tf < t0 and np.any(d >= 0):
--> 529 raise ValueError("Values in `t_eval` are not properly sorted.")
530
531 if tf > t0:
ValueError: Values in `t_eval` are not properly sorted.
uj5u.com熱心網友回復:
來自 solve_ivp 檔案
args tuple, optional
Additional arguments to pass to the user-defined functions. If given, the
additional arguments are passed to all user-defined functions. So if, for
example, fun has the signature fun(t, y, a, b, c), then jac (if given) and
any event functions must have the same signature, and args must be a tuple
of length 3.
t_eval應該排序的那個是哪里- 如果提供。
t_eval array_like or None, optional
Times at which to store the computed solution, must be sorted and lie
within t_span. If None (default), use points selected by the solver.
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/372122.html
