Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from sympy import *
- from sympy.abc import t, n
- T = 3
- ti = -1
- tf = 2
- f = Piecewise((1, (t < 1) & (t > -1)), (0, (t < 2) & (t > 1)))
- print ("n"+"Función = ")
- pprint(f)
- ao = integrate(2 / T * f, (t, ti, tf))
- print ("n"+"a0 = ")
- pprint(ao)
- an = together(integrate((2 / T) * cos(2 * n * t * pi / T) * f, (t, ti, tf)))
- print ("n"+"an = ")
- pprint(an)
- bn = together(integrate((2 / T) * sin(2 * n * t * pi / T) * f, (t, ti, tf)))
- print ("n"+"bn = ")
- pprint(bn)
- armonicos = 5
- print ("n"+"Serie de Fourier " + "(" + str(armonicos) + " armonicos) = ")
- serie = (ao/2)
- for i in range(1, armonicos + 1):
- serie = serie + (an*cos(2*n*t*pi/T)).subs(n, i)
- for j in range(1, armonicos + 1):
- serie = serie + (bn*sin(2*n*t*pi/T)).subs(n, j)
- pprint(serie)
- plotting.plot(serie, ylim=(-0.5, 1.5), xlim=(-5,5))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement