python numpy.convolve解决从0到t的限制,而不是-t到t的卷积积分 [英] python numpy.convolve to solve convolution integral with limits from 0 to t instead -t to t

查看:108
本文介绍了python numpy.convolve解决从0到t的限制,而不是-t到t的卷积积分的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个类型的卷积积分:

I have a convolution integral of the type:

要在数值上求解该积分,我想使用numpy.convolve().现在,您可以在在线帮助中看到,卷积从-infinity到+ infinity正式完成,这意味着数组完全沿着彼此移动以进行评估-这不是我所需要的.我显然需要确保选择正确的卷积部分-您能确认这是正确的方法吗,还是可以告诉我如何正确地进行卷积,以及(也许更重要)为什么?

To solve this integral numerically, I would like to use numpy.convolve(). Now, as you can see in the online help, the convolution is formally done from -infinity to +infinity meaning that the arrays are moved along each other completely for evaluation - which is not what I need. I obviously need to be sure to pick the correct part of the convolution - can you confirm that this is the right way to do it or alternatively tell me how to do it right and (maybe even more important) why?

res = np.convolve(J_t, dF, mode="full")[:len(dF)]

J_t是一个解析函数,我可以根据需要评估任意多个点,dF是测量数据的导数.对于此尝试,我选择len(J_t) = len(dF)是因为根据我的理解,我不需要更多.

J_t is an analytical function and I can evaluate as many points as I need, dF are derivatives of measurement data. for this attempt I choose len(J_t) = len(dF) because from my understanding I do not need more.

一如既往,感谢您的想法,感谢您的帮助!

Thank you for your thoughts, as always, I appreciate your help!

背景信息(针对可能感兴趣的人)

Background information (for those who might be interested)

这些类型的积分可用于评估物体的粘弹性行为(或者,如果您对此主题比较熟悉,则可以评估电压变化期间的电路响应).对于粘弹性,J(t)是蠕变柔度函数,而F(t)可以是随时间变化的偏应变,然后该积分将产生偏应力. 如果您现在具有以下形式的J(t):

These type of integrals can be used to evaluate viscoelastic behaviour of bodies (or the response of an electric circuit during change of voltage, if you feel more familiar on this topic). For viscoelasticity, J(t) is the creep compliance function and F(t) can be the deviatoric strains over time, then this integral would yield the deviatoric stresses. If you now e.g. have a J(t) of the form:

J_t = lambda p, t: p[0] + p[1]*N.exp(-t/p[2])

p = [J_elastic, J_viscous, tau]一起使用,将是著名的" 标准线性实体.积分极限是测量的开始时间t_0 = 0和感兴趣的时刻t.

with p = [J_elastic, J_viscous, tau] this would be the "famous" standard linear solid. The integral limits are the start of the measurement t_0 = 0 and the moment of interest, t.

推荐答案

为正确起见,我选择了以下两个功能:

To get it right, I have chosen the following two functions:

a(t) = t
b(t) = t**2

很容易进行数学运算,并发现它们在您的情况下定义的卷积"需要 在值上:

It is easy to do the math and find that their "convolution" as defined in your case, takes on the values:

c(t) = t**4 / 12

因此,请尝试一下:

>>> delta = 0.001
>>> t = np.arange(1000) * delta
>>> a = t
>>> b = t**2
>>> c = np.convolve(a, b) * delta
>>> d = t**4 / 12
>>> plt.plot(np.arange(len(c)) * delta, c)
[<matplotlib.lines.Line2D object at 0x00000000025C37B8>]
>>> plt.plot(t[::50], d[::50], 'o')
[<matplotlib.lines.Line2D object at 0x000000000637AB38>]
>>> plt.show()

因此,通过执行上述操作,如果您的ab都具有n元素,则可以在c的前一个n元素中获得正确的卷积值.

So by doing the above, if both your a and b have n elements, you get the right convolution values in the first n elements of c.

不确定下面的解释是否有意义,但是可以理解...如果您将卷积视为沿y轴镜像功能之一,然后将其沿x轴滑动并计算在每个点乘积,很容易看出来,因为在numpy定义区域之外,它们就像用零填充一样,因此您实际上是在设置从0到t的积分间隔,​​因为第一个函数是零以下的零,第二个是t之上的零,因为它最初是零以下的零,但已被镜像并向右移动t.

Not sure if the following explanation will make any sense, but here it goes... If you think of convolution as mirroring one of the functions along the y-axis, then sliding it along the x axis and computing the integral of the product at each point, it is easy to see how, since outside of the area of definition numpy takes them as if padded with zeros, you are effectively setting an integration interval from 0 to t, since the first function is zero below zero, and the second is zero above t, since it originally was zero below zero, but has been mirrored and moved t to the right.

这篇关于python numpy.convolve解决从0到t的限制,而不是-t到t的卷积积分的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆