【发布时间】:2023-03-24 19:18:02
【问题描述】:
我有以下耦合的一阶微分方程:
- dB(t)/dt=-a*A(t);
- dA(t)/dt=b*B(t);
- dJ(t)/dt=cA(t)-dB(t)
在 0 到 200 的时间间隔内,使用您自己选择的参数 a = 0.05、b = 0.02、c = 0.03 和 d = 0.04 求解系统。 这是我的代码:
a=0.05
b=0.02
c=0.03
d=0.04
def function(x,t):
x1, x2, x3 = x[0], x[1], x[2]
#x1, x2, x3 = A, B, J
dx1=b*x1
dx2=-a*x0
dx3=c*x0-d*x1
return [dx1, dx2, dx3]
x0 = [100,100, 1]
t = linspace(0, 200, 200)
x = odeint(function, x0, t)
我得到的输出是:
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-11-f8f398346307> in function(x, t)
8 #x1, x2, x3 = A, B, J
9 dx1=b*x1
---> 10 dx2=-a*x0
11 dx3=c*x0-d*x1
12 return [dx1, dx2, dx3]
TypeError: can't multiply sequence by non-int of type 'float'
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-11-f8f398346307> in function(x, t)
8 #x1, x2, x3 = A, B, J
9 dx1=b*x1
---> 10 dx2=-a*x0
11 dx3=c*x0-d*x1
12 return [dx1, dx2, dx3]
TypeError: can't multiply sequence by non-int of type 'float'
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-11-f8f398346307> in function(x, t)
8 #x1, x2, x3 = A, B, J
9 dx1=b*x1
---> 10 dx2=-a*x0
11 dx3=c*x0-d*x1
12 return [dx1, dx2, dx3]
TypeError: can't multiply sequence by non-int of type 'float'
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-11-f8f398346307> in function(x, t)
8 #x1, x2, x3 = A, B, J
9 dx1=b*x1
---> 10 dx2=-a*x0
11 dx3=c*x0-d*x1
12 return [dx1, dx2, dx3]
TypeError: can't multiply sequence by non-int of type 'float'
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-11-f8f398346307> in function(x, t)
8 #x1, x2, x3 = A, B, J
9 dx1=b*x1
---> 10 dx2=-a*x0
11 dx3=c*x0-d*x1
12 return [dx1, dx2, dx3]
TypeError: can't multiply sequence by non-int of type 'float'
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-11-f8f398346307> in function(x, t)
8 #x1, x2, x3 = A, B, J
9 dx1=b*x1
---> 10 dx2=-a*x0
11 dx3=c*x0-d*x1
12 return [dx1, dx2, dx3]
TypeError: can't multiply sequence by non-int of type 'float'
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-11-f8f398346307> in function(x, t)
8 #x1, x2, x3 = A, B, J
9 dx1=b*x1
---> 10 dx2=-a*x0
11 dx3=c*x0-d*x1
12 return [dx1, dx2, dx3]
TypeError: can't multiply sequence by non-int of type 'float'
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-11-f8f398346307> in function(x, t)
8 #x1, x2, x3 = A, B, J
9 dx1=b*x1
---> 10 dx2=-a*x0
11 dx3=c*x0-d*x1
12 return [dx1, dx2, dx3]
TypeError: can't multiply sequence by non-int of type 'float'
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-11-f8f398346307> in function(x, t)
8 #x1, x2, x3 = A, B, J
9 dx1=b*x1
---> 10 dx2=-a*x0
11 dx3=c*x0-d*x1
12 return [dx1, dx2, dx3]
TypeError: can't multiply sequence by non-int of type 'float'
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-11-f8f398346307> in function(x, t)
8 #x1, x2, x3 = A, B, J
9 dx1=b*x1
---> 10 dx2=-a*x0
11 dx3=c*x0-d*x1
12 return [dx1, dx2, dx3]
TypeError: can't multiply sequence by non-int of type 'float'
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-11-f8f398346307> in function(x, t)
8 #x1, x2, x3 = A, B, J
9 dx1=b*x1
---> 10 dx2=-a*x0
11 dx3=c*x0-d*x1
12 return [dx1, dx2, dx3]
TypeError: can't multiply sequence by non-int of type 'float'
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-11-f8f398346307> in function(x, t)
8 #x1, x2, x3 = A, B, J
9 dx1=b*x1
---> 10 dx2=-a*x0
11 dx3=c*x0-d*x1
12 return [dx1, dx2, dx3]
TypeError: can't multiply sequence by non-int of type 'float'
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-11-f8f398346307> in function(x, t)
8 #x1, x2, x3 = A, B, J
9 dx1=b*x1
---> 10 dx2=-a*x0
11 dx3=c*x0-d*x1
12 return [dx1, dx2, dx3]
TypeError: can't multiply sequence by non-int of type 'float'
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-11-f8f398346307> in function(x, t)
8 #x1, x2, x3 = A, B, J
9 dx1=b*x1
---> 10 dx2=-a*x0
11 dx3=c*x0-d*x1
12 return [dx1, dx2, dx3]
TypeError: can't multiply sequence by non-int of type 'float'
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-11-f8f398346307> in function(x, t)
8 #x1, x2, x3 = A, B, J
9 dx1=b*x1
---> 10 dx2=-a*x0
11 dx3=c*x0-d*x1
12 return [dx1, dx2, dx3]
TypeError: can't multiply sequence by non-int of type 'float'
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-11-f8f398346307> in function(x, t)
8 #x1, x2, x3 = A, B, J
9 dx1=b*x1
---> 10 dx2=-a*x0
11 dx3=c*x0-d*x1
12 return [dx1, dx2, dx3]
TypeError: can't multiply sequence by non-int of type 'float'
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-11-f8f398346307> in function(x, t)
8 #x1, x2, x3 = A, B, J
9 dx1=b*x1
---> 10 dx2=-a*x0
11 dx3=c*x0-d*x1
12 return [dx1, dx2, dx3]
TypeError: can't multiply sequence by non-int of type 'float'
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-11-f8f398346307> in function(x, t)
8 #x1, x2, x3 = A, B, J
9 dx1=b*x1
---> 10 dx2=-a*x0
11 dx3=c*x0-d*x1
12 return [dx1, dx2, dx3]
TypeError: can't multiply sequence by non-int of type 'float'
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-11-f8f398346307> in function(x, t)
8 #x1, x2, x3 = A, B, J
9 dx1=b*x1
---> 10 dx2=-a*x0
11 dx3=c*x0-d*x1
12 return [dx1, dx2, dx3]
TypeError: can't multiply sequence by non-int of type 'float'
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-11-f8f398346307> in function(x, t)
8 #x1, x2, x3 = A, B, J
9 dx1=b*x1
---> 10 dx2=-a*x0
11 dx3=c*x0-d*x1
12 return [dx1, dx2, dx3]
TypeError: can't multiply sequence by non-int of type 'float'
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-11-f8f398346307> in function(x, t)
8 #x1, x2, x3 = A, B, J
9 dx1=b*x1
---> 10 dx2=-a*x0
11 dx3=c*x0-d*x1
12 return [dx1, dx2, dx3]
TypeError: can't multiply sequence by non-int of type 'float'
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-11-f8f398346307> in function(x, t)
8 #x1, x2, x3 = A, B, J
9 dx1=b*x1
---> 10 dx2=-a*x0
11 dx3=c*x0-d*x1
12 return [dx1, dx2, dx3]
TypeError: can't multiply sequence by non-int of type 'float'
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-11-f8f398346307> in function(x, t)
8 #x1, x2, x3 = A, B, J
9 dx1=b*x1
---> 10 dx2=-a*x0
11 dx3=c*x0-d*x1
12 return [dx1, dx2, dx3]
TypeError: can't multiply sequence by non-int of type 'float'
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-11-f8f398346307> in function(x, t)
8 #x1, x2, x3 = A, B, J
9 dx1=b*x1
---> 10 dx2=-a*x0
11 dx3=c*x0-d*x1
12 return [dx1, dx2, dx3]
TypeError: can't multiply sequence by non-int of type 'float'
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-11-f8f398346307> in function(x, t)
8 #x1, x2, x3 = A, B, J
9 dx1=b*x1
---> 10 dx2=-a*x0
11 dx3=c*x0-d*x1
12 return [dx1, dx2, dx3]
TypeError: can't multiply sequence by non-int of type 'float'
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-11-f8f398346307> in function(x, t)
8 #x1, x2, x3 = A, B, J
9 dx1=b*x1
---> 10 dx2=-a*x0
11 dx3=c*x0-d*x1
12 return [dx1, dx2, dx3]
TypeError: can't multiply sequence by non-int of type 'float'
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-11-f8f398346307> in function(x, t)
8 #x1, x2, x3 = A, B, J
9 dx1=b*x1
---> 10 dx2=-a*x0
11 dx3=c*x0-d*x1
12 return [dx1, dx2, dx3]
TypeError: can't multiply sequence by non-int of type 'float'
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-11-f8f398346307> in function(x, t)
8 #x1, x2, x3 = A, B, J
9 dx1=b*x1
---> 10 dx2=-a*x0
11 dx3=c*x0-d*x1
12 return [dx1, dx2, dx3]
TypeError: can't multiply sequence by non-int of type 'float'
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-11-f8f398346307> in function(x, t)
8 #x1, x2, x3 = A, B, J
9 dx1=b*x1
---> 10 dx2=-a*x0
11 dx3=c*x0-d*x1
12 return [dx1, dx2, dx3]
TypeError: can't multiply sequence by non-int of type 'float'
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-11-f8f398346307> in function(x, t)
8 #x1, x2, x3 = A, B, J
9 dx1=b*x1
---> 10 dx2=-a*x0
11 dx3=c*x0-d*x1
12 return [dx1, dx2, dx3]
TypeError: can't multiply sequence by non-int of type 'float'
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-11-f8f398346307> in function(x, t)
8 #x1, x2, x3 = A, B, J
9 dx1=b*x1
---> 10 dx2=-a*x0
11 dx3=c*x0-d*x1
12 return [dx1, dx2, dx3]
TypeError: can't multiply sequence by non-int of type 'float'
Repeated convergence failures (perhaps bad Jacobian or tolerances).
Run with full_output = 1 to get quantitative information.
我的代码有什么问题?
【问题讨论】: