在scipy

时间:2016-11-14 15:56:09

标签: python numpy scipy

我在域func中定义了一个函数[-5, 5] x [-5, 5]。我正在使用scipy.integrate.dblquad在此域上执行此功能的集成。

由于功能定义,它有一个非常扁平和“无趣”的部分和一个中心部分(或多或少是域中心的单位圆),它是“有趣的”。这个“有趣”部分的高质量分辨率对于积分的质量至关重要。

我做了一个快速测试,以了解评估函数的位置,并生成一个图,其中标记点是函数的评估点。我将其与域名的“有趣”部分进行比较。图片应该说明一切:只有少数或点位于有趣的部分,而大部分位于外部,这是使用高斯求积时的预期。

Visualization of interesting domain

以下是我如何生成这个情节:

xx, yy = [], []

def func(y, x):
    xx.append(x)
    yy.append(y)
    return 1

dblquad(func, -5, 5, lambda x: -5, lambda x: 5)

fig, ax = plt.subplots(dpi=140)
ax.plot(xx, yy, 'x')

circle = plt.Circle((0, 0), radius=1.2, facecolor='#ffcccc', edgecolor='#ff3333')
ax.add_patch(circle)
ax.annotate(xy=[-1, -1], s='Interesting part', color='r',
        xytext=[-4, -2.6], arrowprops={'arrowstyle':'->', 'color':'r'})

我应该将我的域细分为较小的部分并对所有这些部分应用dblquad,然后将结果加起来?或者dblquad如果它识别出某些区域需要更多分辨率的功能,它会自动执行吗?

修改: 在给dblquad复杂函数后,我收到了以下警告:

/usr/lib/python3.5/site-packages/scipy/integrate/quadpack.py:356: IntegrationWarning: The maximum number of subdivisions (50) has been achieved. If increasing the limit yields no improvement it is advised to analyze the integrand in order to determine the difficulties. If the position of a local difficulty can be determined (singularity, discontinuity) one will probably gain from splitting up the interval and calling the integrator on the subranges. Perhaps a special-purpose integrator should be used. warnings.warn(msg, IntegrationWarning)

尽管我没有找到关于dblquad文档的明确陈述,但很明显该函数是根据被积函数动态选择多个细分。在我之前显示的情况下,被积函数在任何地方都只有1,因此集成起来非常简单。当函数不那么简单时,scipy会细分域。

对于记录,我的函数如下所示: Integrand

0 个答案:

没有答案