微分系统的 odeint
odeint for an differential system
我对 odeint
有疑问。我必须解决一阶微分系统,然后是二阶系统,但我对一阶系统有点困惑。你能解释一下我标记为错误的地方吗?谢谢:)
import scipy.integrate as integrate
import numpy as np
def fun(t,y):
ys = np.array([y[1], (1-y[0]**2)*y[1]-y[0]])
return(ys)
N = 3
x0 = np.array([2.00861986087484313650940188,0])
t0tf = [0, 17.0652165601579625588917206249]
T=([0 for i in range (N+1)])
T[0]= t0tf[0]
Pas = (t0tf[1]-t0tf[0])/N
for i in range (1,N+1):
T[i]= t0tf[0] + i*Pas
X = integrate.odeint(fun, x0,T,Dfun=None, col_deriv=0,full_output=True)
T = np.array(T)
T = T.reshape(N+1,1)
S = np.append(X,T,axis=1)
print(S)
返回的错误是:
ys = np.array([y[1], (1-y[0]**2)*y[1]-y[0]])
TypeError: 'float' object is not subscriptable
您需要反转导数函数参数的顺序 - 它应该是 f(y, t)
,而不是 f(t, y)
。这与 scipy.integrate.ode
class.
使用的顺序相反
此外,串联 S = np.append(X,T,axis=1)
将失败,因为 X
是一个包含积分和字典的元组。请改用 S = np.append(X[0],T,axis=1)
。
我对 odeint
有疑问。我必须解决一阶微分系统,然后是二阶系统,但我对一阶系统有点困惑。你能解释一下我标记为错误的地方吗?谢谢:)
import scipy.integrate as integrate
import numpy as np
def fun(t,y):
ys = np.array([y[1], (1-y[0]**2)*y[1]-y[0]])
return(ys)
N = 3
x0 = np.array([2.00861986087484313650940188,0])
t0tf = [0, 17.0652165601579625588917206249]
T=([0 for i in range (N+1)])
T[0]= t0tf[0]
Pas = (t0tf[1]-t0tf[0])/N
for i in range (1,N+1):
T[i]= t0tf[0] + i*Pas
X = integrate.odeint(fun, x0,T,Dfun=None, col_deriv=0,full_output=True)
T = np.array(T)
T = T.reshape(N+1,1)
S = np.append(X,T,axis=1)
print(S)
返回的错误是:
ys = np.array([y[1], (1-y[0]**2)*y[1]-y[0]])
TypeError: 'float' object is not subscriptable
您需要反转导数函数参数的顺序 - 它应该是 f(y, t)
,而不是 f(t, y)
。这与 scipy.integrate.ode
class.
此外,串联 S = np.append(X,T,axis=1)
将失败,因为 X
是一个包含积分和字典的元组。请改用 S = np.append(X[0],T,axis=1)
。