绘制高斯和指数衰减的卷积简单函数的困难
我正在尝试定义一个函数并绘制它。它是高斯 (i) 和指数衰减 (f) 的卷积。它对于某些 x 值工作正常,但对于其他值则不起作用。有人可以帮我找出原因吗?
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
from scipy.optimize import curve_fit
plt.rcParams["font.size"] = 16
plt.rcParams['figure.figsize'] = (10, 5)
#d is FWHM of the Gaussian (determines the width of convolution)
#but the initial height and shape is affected by k value
def one_exp_fit_function(t1, d, u, k1):
d_bar = d/(2*np.sqrt(np.log(2)))
i = ((d_bar*np.sqrt(2*np.pi))**(-1))*np.exp(-np.log(2)*(((2*(t1-u))/d)**2))
f = np.exp(-(k1)*t1)
k = np.convolve(i, f, mode='same')
return k
plt.plot(one_exp_fit_function(np.linspace(-5, 5, 100), 0.1, 3, 0.5), label='d=0.1, u=3, k=0.5')
plt.legend()
但是当我输入以下列表作为 x 值时,它会返回一个零列表。
one_exp_fit_function(x, 5, 908, 0.5)
输出
array([0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.],
dtype=float32)
这是我的 x 值列表
x
907.6, 907.61, 907.62, 907.63, 907.64, 907.65, 907.66, 907.67, 907.68, 907.69, 907.7, 907.71, 907.72, 907.73、907.74、907.75、907.76、907.77、907.78、907.79、907.8、907.81、907.82、907.83、907.84、907.85、907.86、 907.87、907.88、907.89、907.9、907.91、907.92、907.93、907.94、907.95、907.96、907.97、907.98、907.99、908.0、908.01、 908.02、908.03、908.04、908.05、908.06、908.07、908.08、908.09、908.1、908.11、908.12、908.13、908.14、908.15、 908.16、908.17、908.18、908.19、908.2、908.21、908.22、908.23、908.24
有人可以帮我解决问题吗?
I am trying to define a function and plot it. It is a convolution of a Gaussian (i) and exponential decay (f). It works fine for some x values but doesn't work for others. Can someone please help me find out why?
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
from scipy.optimize import curve_fit
plt.rcParams["font.size"] = 16
plt.rcParams['figure.figsize'] = (10, 5)
#d is FWHM of the Gaussian (determines the width of convolution)
#but the initial height and shape is affected by k value
def one_exp_fit_function(t1, d, u, k1):
d_bar = d/(2*np.sqrt(np.log(2)))
i = ((d_bar*np.sqrt(2*np.pi))**(-1))*np.exp(-np.log(2)*(((2*(t1-u))/d)**2))
f = np.exp(-(k1)*t1)
k = np.convolve(i, f, mode='same')
return k
plt.plot(one_exp_fit_function(np.linspace(-5, 5, 100), 0.1, 3, 0.5), label='d=0.1, u=3, k=0.5')
plt.legend()
But when I enter the following list as x values it returns a list of zeros.
one_exp_fit_function(x, 5, 908, 0.5)
output
array([0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.],
dtype=float32)
This is my list of x values
x
907.6, 907.61, 907.62, 907.63, 907.64, 907.65, 907.66, 907.67, 907.68, 907.69, 907.7, 907.71, 907.72, 907.73, 907.74, 907.75, 907.76, 907.77, 907.78, 907.79, 907.8, 907.81, 907.82, 907.83, 907.84, 907.85, 907.86, 907.87, 907.88, 907.89, 907.9, 907.91, 907.92, 907.93, 907.94, 907.95, 907.96, 907.97, 907.98, 907.99, 908.0, 908.01, 908.02, 908.03, 908.04, 908.05, 908.06, 908.07, 908.08, 908.09, 908.1, 908.11, 908.12, 908.13, 908.14, 908.15, 908.16, 908.17, 908.18, 908.19, 908.2, 908.21, 908.22, 908.23, 908.24
Can someone please help me as to what the problem might be?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论