python - python中的2dof质量弹簧阻尼系统,odeint错误
问题描述
我是一个刚开始使用Python的初学者。我选择了机械工程专业,并通过学习 Python 来编写我的力学计算。现在我正在制作一个 2DOF 质量弹簧阻尼器模型。我在互联网上找到了 1DOF 模型,并且(http://ifcuriousthenlearn.com/blog/2015/06/09/mechanical-vibrations-with-python/)我想应用它来实现 2DOF。
但是发生了错误。
这是代码和错误。
import matplotlib.pylab as pylab
from scipy.integrate import odeint
from pylab import plot, xlabel, ylabel, title, legend, figure, subplot
from pylab import cos, pi, arange, sqrt, array
def MassSpringDamper(state1,state2,t):
k1=124e3 # spring constant, kN/m
k2=50e3
m1=10 # mass, Kg
m2=20
c1=5 # damping coefficient
c2=3
# unpack the state vector
x1,x1d = state1
x2,x2d = state2 # displacement,x and velocity x'
g = 9.8 # metres per second**2
x1dd = (c1+c2)/m1*x1d-c2/m1*x2d+(k1+k2)/m1*x1-k2/m1*x2-g
x2dd = -c2/m2*x1d+c2/m2*x2d-k2/m2*x1+k2/m2*x2-g
return [x1d, x1dd, x2d, x2dd]
state0 = [0.0, 1.2] # initial conditions [x0 , v0] [m, m/sec]
ti = 0.0 # initial time
tf = 4.0 # final time
step = 0.001 # step
t = arange(ti, tf, step)
state1 = odeint(MassSpringDamper, state0, t)
state2 = odeint(MassSpringDamper, state0, t)
x1 = array(state1[:,[0]])
x1d = array(state1[:,[1]])
x2 = array(state2[:,[0]])
x2d = array(state2[:,[1]])
这里出错。
类型错误:MassSpringDamper() 缺少 1 个必需的位置参数:'t'
我能怎么做?
感谢您阅读我的问题。
解决方案
推荐阅读
- ios - 在 iOS 应用中升级 SDK 后 Firebase Crashlytics 不显示日志
- django - 我如何将多个用户添加到 manytomanyFiled at one
- c - gtk_container_add 函数崩溃
- unit-testing - 起订量和单元测试 AspBoilerPlate .Net Core 3 抛出异常“动态程序集中不支持调用的成员”
- javascript - 将字典从 javascript 函数传递给烧瓶 python 函数:始终为 None
- graph - 绘制按列而不是行排列的数据
- shell - 如何在没有期望、sshpass 或任何第 3 方 SFTP 客户端的情况下在 shell 脚本中传递 SFTP 命令的密码
- php - 在 Laravel Blade 中使用 PHP FOR 循环生成一张额外幻灯片的问题
- asp.net - ASP.NET IIS 10 服务 .svc 错误 406 不可接受
- sql - 在 SAP HANA 中将 IN 运算符与变量一起使用