首页 > 解决方案 > 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'

我能怎么做?

感谢您阅读我的问题。

标签: pythonscipy

解决方案


推荐阅读