Guest User

Untitled

a guest
Nov 18th, 2017
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.92 KB | None | 0 0
  1. import sympy as sp
  2.  
  3. t, tau = sp.symbols('t tau')
  4. sol = sp.integrate(sp.sin(t - tau) * sp.cos(tau), (tau, 0, t))
  5. print(sol)
  6. # t*sin(t)/2
  7.  
  8. import numpy as np
  9. from scipy import signal
  10.  
  11. t = np.linspace(-10, 10, 1000)
  12. f = np.sin(t)
  13. g = np.cos(t)
  14. conv = 0.5 * t * np.sin(t)
  15.  
  16. print(conv)
  17. # [-2.72 -2.63 -2.54 -2.449 -2.357 -2.264 -2.171 -2.078 -1.984 -1.89 ...,
  18. # -1.89 -1.984 -2.078 -2.171 -2.264 -2.357 -2.449 -2.54 -2.63 -2.72 ]
  19.  
  20. print(signal.convolve(f, g, mode='same'))
  21. # [ 138.098 134.167 130.164 126.092 121.953 117.747 113.476 109.142
  22. # 104.746 100.29 ..., -95.775 -100.29 -104.746 -109.142 -113.476
  23. # -117.747 -121.953 -126.092 -130.164 -134.167]
  24.  
  25. n = 1000
  26. t = np.linspace(0, 10, n)
  27. dt = t[1] - t[0]
  28. f = np.sin(t)
  29. g = np.cos(t)
  30. conv = 0.5 * t * np.sin(t)
  31. conv2 = signal.convolve(f, g, mode='full')[:n] * dt
  32. plt.plot(t, conv) # assuming import matplotlib.pyplot as plt
  33. plt.show()
  34. plt.plot(t, conv2)
  35. plt.show()
Add Comment
Please, Sign In to add comment