如何在Python中定义一个函数,该函数包含一个确定的积分,其自由参数在两个固定值之间运行?
我想定义一个具有三个参数的Python函数:C,PSI和M,但实际上它具有基于另一个称为ETA的变量的积分。
def func(x: np.float64, C: np.float64, psi: np.float64, m: np.float64) -> np.float64:
return C * (1-psi) * quad(np.power(1-eta, psi) * np.power(m/x, C/eta+1)/eta, 0, np.inf, args=(C, psi, m, x))[0]
由于我想将此功能拟合到数据集,因此我不能选择ETA作为拟合的免费参数,因此它不应在功能签名中作为参数出现。但是,Python不知道内部ETA是定义的变量。
File "c:\Users\username\Desktop\Project\my_script.py", line 277, in func
np.power(1 - eta, psi) * np.power(m / x, C/eta + 1) / eta, 0, np.inf,
NameError: name 'eta' is not defined
我如何让函数知道它不会期望用参数馈送,但是内部积分可以通过集成来照顾它。
- -谢谢,
I would like to define a python function that has three parameters: C, psi, and m but it actually internally has an integral that is running based on another variable called eta.
def func(x: np.float64, C: np.float64, psi: np.float64, m: np.float64) -> np.float64:
return C * (1-psi) * quad(np.power(1-eta, psi) * np.power(m/x, C/eta+1)/eta, 0, np.inf, args=(C, psi, m, x))[0]
Since I would like to fit this function to a dataset, I cannot choose eta to be a free parameter for fitting and hence it should not appear as a parameter in the function signature. But, python doesn't know the internal eta as a defined variable.
File "c:\Users\username\Desktop\Project\my_script.py", line 277, in func
np.power(1 - eta, psi) * np.power(m / x, C/eta + 1) / eta, 0, np.inf,
NameError: name 'eta' is not defined
How can I let the function know that it is not expecting to be fed with a parameter but the inside integral takes care of that through integration.
---Thanks,
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论