Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import sympy as sp
- t, tau = sp.symbols('t tau')
- sol = sp.integrate(sp.sin(t - tau) * sp.cos(tau), (tau, 0, t))
- print(sol)
- # t*sin(t)/2
- import numpy as np
- from scipy import signal
- t = np.linspace(-10, 10, 1000)
- f = np.sin(t)
- g = np.cos(t)
- conv = 0.5 * t * np.sin(t)
- print(conv)
- # [-2.72 -2.63 -2.54 -2.449 -2.357 -2.264 -2.171 -2.078 -1.984 -1.89 ...,
- # -1.89 -1.984 -2.078 -2.171 -2.264 -2.357 -2.449 -2.54 -2.63 -2.72 ]
- print(signal.convolve(f, g, mode='same'))
- # [ 138.098 134.167 130.164 126.092 121.953 117.747 113.476 109.142
- # 104.746 100.29 ..., -95.775 -100.29 -104.746 -109.142 -113.476
- # -117.747 -121.953 -126.092 -130.164 -134.167]
- n = 1000
- t = np.linspace(0, 10, n)
- dt = t[1] - t[0]
- f = np.sin(t)
- g = np.cos(t)
- conv = 0.5 * t * np.sin(t)
- conv2 = signal.convolve(f, g, mode='full')[:n] * dt
- plt.plot(t, conv) # assuming import matplotlib.pyplot as plt
- plt.show()
- plt.plot(t, conv2)
- plt.show()
Add Comment
Please, Sign In to add comment