import numpy as np
import matplotlib.pyplot as plt
# 定义两个函数
def f(t):
return np.exp(-t) # e的-t次方
def g(t):
return t * np.exp(-t) # t乘以e的-t次方
# 定义时间轴
t = np.linspace(0, 1, 1000)
# 计算卷积
conv_f_g = np.convolve(f, g, 'same')
# 绘制函数和卷积结果
plt.figure(figsize=(10, 6))
plt.plot(t, f(t), label='f(t)')
plt.plot(t, g(t), label='g(t)')
plt.plot(t, conv_f_g, label='conv_f_g')
plt.legend()
plt.show()