I am trying to integrate the following formula:
Below is my attempt to perform this integration using a homemade scheme for f(a) = sin(a).
def func(x):
return math.sin(x)
def integration (f, n, r, a, dtheta ):
summation = 0
theta = 0
while theta <= 2*np.pi:
f_arg = a + r*np.exp(1j*theta)
second = np.exp(-1j*theta*n)
summation += f(f_arg) * second * dtheta
theta += dtheta
return math.factorial(n)*summation / (2*np.pi*r**n)
integration(func, n=1, r=1, a=0, dtheta=2*np.pi/10000)
The first derivative (n=1) of f(a) = sin(a) is f'(a) = cos(a). When evaluated at a = 0, this should give cos(0) = 1, however, it does not. Where am I going wrong?

return math.factorial(n) / (2*np.pi*r**n)doesn't seem to involvef,theta,dtheta, or anything you did in thewhileloop.