立即解決問題是你deriv
功能正試圖通過float
值乘以普通的Python list
,Cv_data
(傳過來Cv
)。如果要向量化此操作,請使用NumPy數組:
Ap_data = np.array([2, 7, 91, 1.6, 0.4, 5])
tdata= np.array([0, 1, 4, 5, 4, 20])
Cv_data = np.array([43, 580, 250, 34, 30, 3])
解決此問題。現在您擁有了odeint
失敗了,你給它輸入問題...
intdy-- t (=r1) illegal
in above message, r1 = 0.4000000000000D+01
t not in interval tcur - hu (= r1) to tcur (=r2)
in above, r1 = 0.4287484688360D+01 r2 = 0.5551311182627D+01
lsoda-- trouble from intdy. itask = i1, tout = r1ls
in above message, i1 = 1
in above message, r1 = 0.4000000000000D+01
Illegal input detected (internal error).
Run with full_output = 1 to get quantitative information.
[[ 21.6 ]
[ 20.37432613]
[ 17.09897165]
[ 16.12866355]
[ 16.12866355]
[ -0.90614016]]
,或許你能給什麼你的方程,以及它如何與Cv_data
更多的信息。尤其是,您的衍生產品不取決於t
,但此參數的值範圍爲Cv
。
更新:它因爲你有趣的時間系列而失敗。 odeint
正常工作,如果它是單調的,例如:
from scipy.integrate import odeint
import numpy as np
Ap_data = [2, 7, 91, 1.6, 0.4, 5]
tdata= np.array([0, 1, 4, 5, 10, 20])
Cv_data = np.array([43, 580, 250, 34, 30, 3])
#Define parameters
kn = 1E-5 #change
ks = 1E+5 #change
kd = 0.058
def deriv (CAi,t, Cv):
CA0 = (-kd-kn*Cv)*CAi/(1+(CAi/ks))
return CA0
#Initial conditions
CA_init = 21.6
#Solve the ODE
(CAb_soln) = odeint (deriv, CA_init, tdata, (Cv_data,))
print CAb_soln
結果:
[[ 21.6 ]
[ 20.37432613]
[ 17.09897165]
[ 16.12866355]
[ 12.04306424]
[ 6.71431758]]
在您的示例中,並未實際調用「deriv」。你能否改變你的示例代碼? – Carsten 2015-02-06 23:01:33