I am trying to develop a function that calculates the sum of sines.
The first function that I tried was:
def S(t,n,T):
return (4/pi)*sum((1/(2*i-1))*sin(2*(2*i-1)*pi*t/T) for i in range(1,n+1))
and then I got an answer of 0.2381
when I called the function using the arguments below:
S(0.01*2*pi,3,2*pi)
As I am relatively new to Python I tried to amend this code to:
def S1(t1,n1,T1):
s1 = 0
for i in range(1,n1+1):
s1 = s1 + (4/pi)*sum((1/(2*i-1))*sin(2*(2*i-1)*pi*t1/T1))
return s1
but when I call the function S1 using the same arguments I get an error saying that:
TypeError: 'float' object is not iterable.
Can someone explain why this is? I reviewed some of the other answers in relation to this TypeError
but I do not understand them.
sum((1/(2*i-1)) ...
?