如何对函数向量进行scipy-do积分

2024-04-26 12:10:34 发布

您现在位置:Python中文网/ 问答频道 /正文

我通常使用scipy通过python进行集成。这是我的密码

from scipy import integrate
    def f(x, y, z):`
        return [x**2 + y**2 +3*z, x + y]
a = integrate.quad(f, 0, 1, (2,2))
print(a)

我想同时对两个元素进行相同的集成,比如map。我执行后,它显示:

你知道吗quadpack.error错误:提供的函数不返回有效的浮点值。你知道吗


Tags: 函数fromimport元素密码mapreturndef
1条回答
网友
1楼 · 发布于 2024-04-26 12:10:34

f返回2个数字的列表:

In [122]: def f(x, y, z):
     ...:      return [x**2 + y**2 +3*z, x + y]
     ...: 
In [123]: f(0,2,2)
Out[123]: [10, 2]
In [124]: f(1,2,2)
Out[124]: [11, 3]

quad想要你给它一个浮点数。你知道吗

您必须分别迭代或以其他方式求解这些函数。或者提出你自己的quad等价物。这种整合并没有什么特别奇特的地方。你知道吗

更多信息请参见(复制?)你知道吗

Integrating functions that return an array in Python

相关问题 更多 >