首页 > 解决方案 > 在 Python 类中调用 odeint

问题描述

我正在尝试在 python 类的方法中调用 odeint:

从 scipy.integrate 导入 o​​deint

类测试:

@staticmethod
def mathfunc(y, t arg1, arg2):
    x , xdot = y
    #some equations
    return xdot, xddot

def numericalsim(self, y0, t):
    y = odeint(mathfunc, y0, t, args(self.param1, self.param2))
    return y

但是,我收到错误消息:未定义名称“mathfunc”。请你能帮我在课堂上调用 odeint 吗?

标签: pythonclassscipy

解决方案


您还可以分享您如何导入模块吗?并且由于它是一个静态方法,因此您需要使用您的类来调用它。像这样 :

y = odeint(SomeClass.mathfunc, y0, t, args(self.param1, self.param2))

希望能帮助到你。


推荐阅读