How to do a sum in python
function, python, sum
Solution
something like:
def V(theta,N):
return sum(a0*(cos(i*theta) for i in range(1,N+1))
print V(theta,N)
or you can use `lambda`:
V =lambda theta,N : sum(a0*(cos(i*theta) for i in range(1,N+1))
print V(theta,N)
Problem
I was wondering how one can represent a sum in python without loops like here where we have: ``` def rosen(x): """The Rosenbrock function""" return sum(100.0*(x[1:]-x[:-1]**2.0)**2.0 + (1-x[:-1])**2.0) ``` My function is the following: `V(theta) = Sum(i=1->N)[a0*(cos(i*theta)]` Thank you in advance for your help :):)