fork download
  1. import math
  2. import numpy as np
  3.  
  4. def func(x):
  5. return np.sin(x)
  6.  
  7. def integration (f, n, r, a, dtheta ):
  8.  
  9. summation = 0
  10. theta = 0
  11. while theta <= 2*np.pi:
  12.  
  13. f_arg = a + r*np.exp(1j*theta)
  14. second = np.exp(-1j*theta*n)
  15.  
  16. summation += f(f_arg) * second * dtheta
  17. theta += dtheta
  18.  
  19. return math.factorial(n)*summation / (2*np.pi*r**n)
  20.  
  21. print(integration(func, 2, 1, 0, 2*np.pi/10000))
Success #stdin #stdout 0.13s 92224KB
stdin
Standard input is empty
stdout
(2.74046406348e-13-1.57741169483e-13j)