Contact
CoCalc Logo Icon
StoreFeaturesDocsShareSupport News AboutSign UpSign In
| Download

All published worksheets from http://sagenb.org

Views: 168703
Image: ubuntu2004
# integrate z^2 on the unit circle
f(z) = z^2 # define the integrand
c(t)=e^(I*t) # parametrize the unit circle. c(t):[0,2pi]
start=0 stop=2*float(pi) N=1000
line_points = srange(float(start), float(stop), (stop-start)/N,include_endpoint=True) #N+1 points on [start, stop] z = map(c,line_points) #N+1 points on curve #The points are denoted z[0], z[1], ..., z[N]
sum(f(z[i])*(z[i+1]-z[i]) for i in range(0,N-1)) # approximate integral of z^2
-9.86918230106e-05 - 0.00628239983217*I
dc(t)=c.diff(t) # derivative of c(t) answer=integrate(f(c(t))*dc(t),(t,start,stop)) # integrate using parametrization answer
-2.44929359829e-16*I
float(answer.real_part())+float(answer.imag_part())*I # check if answer from parametrization agrees with approximation by taking its floating-point value
-2.44929359829e-16*I