Ask Your Question

Revision history [back]

Only t is a symbol, so you can define expr as a (Python) function of n and then sum over the good set of n's.

sage: t = var('t')
sage: j = i
sage: expr = lambda n : ((-1)^n - 1)/n * exp(2*pi*n*j*t)
sage: f(t) = 1/2 + j/(2*pi) * sum([expr(n) for n in range(-5,6) if n != 0])
sage: f(t)
-1/15*I*(3*e^(10*I*pi*t) + 5*e^(6*I*pi*t) + 15*e^(2*I*pi*t) - 15*e^(-2*I*pi*t) - 5*e^(-6*I*pi*t) - 3*e^(-10*I*pi*t))/pi + 1/2

Only t is a symbol, so you can define expr as a (Python) function of the (Python) variable n and then sum over the good set of n's.

sage: t = var('t')
sage: j = i
sage: expr = lambda n : ((-1)^n - 1)/n * exp(2*pi*n*j*t)
sage: f(t) = 1/2 + j/(2*pi) * sum([expr(n) for n in range(-5,6) if n != 0])
sage: f(t)
-1/15*I*(3*e^(10*I*pi*t) + 5*e^(6*I*pi*t) + 15*e^(2*I*pi*t) - 15*e^(-2*I*pi*t) - 5*e^(-6*I*pi*t) - 3*e^(-10*I*pi*t))/pi + 1/2