Advertisement
Guest User

Untitled

a guest
Jun 16th, 2019
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.78 KB | None | 0 0
  1. from sympy import *
  2. from sympy.abc import t, n
  3. T = 3
  4. ti = -1
  5. tf = 2
  6. f = Piecewise((1, (t < 1) & (t > -1)), (0, (t < 2) & (t > 1)))
  7. print ("n"+"Función = ")
  8. pprint(f)
  9. ao = integrate(2 / T * f, (t, ti, tf))
  10. print ("n"+"a0 = ")
  11. pprint(ao)
  12. an = together(integrate((2 / T) * cos(2 * n * t * pi / T) * f, (t, ti, tf)))
  13. print ("n"+"an = ")
  14. pprint(an)
  15. bn = together(integrate((2 / T) * sin(2 * n * t * pi / T) * f, (t, ti, tf)))
  16. print ("n"+"bn = ")
  17. pprint(bn)
  18. armonicos = 5
  19. print ("n"+"Serie de Fourier " + "(" + str(armonicos) + " armonicos) = ")
  20. serie = (ao/2)
  21. for i in range(1, armonicos + 1):
  22. serie = serie + (an*cos(2*n*t*pi/T)).subs(n, i)
  23. for j in range(1, armonicos + 1):
  24. serie = serie + (bn*sin(2*n*t*pi/T)).subs(n, j)
  25. pprint(serie)
  26. plotting.plot(serie, ylim=(-0.5, 1.5), xlim=(-5,5))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement