Contact
CoCalc Logo Icon
StoreFeaturesDocsShareSupport News AboutSign UpSign In
| Download

All published worksheets from http://sagenb.org

Views: 168696
Image: ubuntu2004
# Integrate e^z on the line y=x from 0 to 1+i
f(z) = e^z #define the integrand
c(t) = t+I*t # parametrize the line. c(t):[0,1] -> line in C.
start = 0 stop = 1 N = 1000 #c(t) maps the interval [start, stop] onto the curve where f(z) is to be integrated. N is number of points to use in approximation of integral.
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 e^z dz on line
0.470416979755 + 2.28222422966*I
dc(t)=c.diff(t) # derivative of c(t) answer=integrate(f(c(t))*dc(t),(t,start,stop)) # integrate using parametrization answer
e^(I + 1) - 1
float(answer.real_part())+float(answer.imag_part())*I #check if answer from parametrization agrees with approximation by taking its floating-point value
0.468693939916 + 2.28735528718*I