python - 在 Python 类中调用 odeint
问题描述
我正在尝试在 python 类的方法中调用 odeint:
从 scipy.integrate 导入 odeint
类测试:
@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 吗?
解决方案
您还可以分享您如何导入模块吗?并且由于它是一个静态方法,因此您需要使用您的类来调用它。像这样 :
y = odeint(SomeClass.mathfunc, y0, t, args(self.param1, self.param2))
希望能帮助到你。
推荐阅读
- azure - 使用powershell覆盖天蓝色资源组上的标签名称
- python - Python 类型提示:Callable 后跟 TypeVar 是什么意思?
- c - Malloc 结构中的字符串
- python-3.x - 如何使用 pdfplumber 查找页数?
- python - Python:从请求库转换为 urllib3
- reactjs - InvalidStateError:无法在“MediaRecorder”上执行“stop”:MediaRecorder 的状态为“inactive”
- javascript - 滚动“要修复,取消所有订阅”时,useEffect 和导航栏处于活动状态的问题
- ip-address - Maxmind Geoip2 API vs 可下载数据库
- javascript - 父母和孩子之间的角度导航路由
- python - Python 不能正常使用回车符(新行)