对于这5种情况中的每一种,我都试图通过odeint函数(弹簧质量函数)进行数值积分,参数F随时间变化。但是,它显示的错误:
第 244 行,in odeint int(布尔(第一))
值错误:设置具有序列的数组元素。
from scipy.integrate import odeint as ode
import matplotlib.pyplot as graph
import numpy as np
def spring(y,t,par):
m = par[0]
k = par[1]
c = par[2]
F = par[3]
ydot=[0,0]
ydot[0] = y[1]
F = np.array(F)
ydot[1] = F/m-c*y[1]/m-k*y[0]/m
return ydot
#cases:[ti,tf,x0,xdot0,c]
A=[0.0,0.3,0.1,0.0,37.7]
B=[0.0,3.0,0.0,1.0,37.7]
C=[0.0,3.0,0.1,1.0,377]
D=[0.0,5.0,0.0,0.0,37.7]
E=[0.0,3.0,0.0,0.0,37.7]
cases = [A, B, C, D, E] #0,1,2,3,4
m=10.0
k=3553.0
par = [m,k]
h = 0.01
cont = 0
for case in cases:
x0 = case[2]
xdot0 = case[3]
y = [x0,xdot0]
par.append(case[4])
ti = case[0]
tf = case[1]
t = np.arange(ti, tf,h)
F = []
for time in t:
if cont == 3:
F.append(1000*np.sin(np.pi*time+np.pi/2))
elif (cont == 4) and (time >= 0.5):
F.append(1000)
else:
F.append(0)
cont = cont + 1
par.append(F) #F is a vector
Y = ode(spring,y,t,args=(par,))
Xn = Y[:,0]
Vn = Y[:,1]
graph.plot(t,Xn)
graph.show()
graph.plot(t,Vn)
graph.show()
graph.plot(Xn,Vn)
graph.show()
炎炎设计
MM们
慕丝7291255
相关分类