Contact
CoCalc Logo Icon
StoreFeaturesDocsShareSupport News AboutSign UpSign In
| Download

All published worksheets from http://sagenb.org

Views: 168703
Image: ubuntu2004
# integrate e^z from 0 to 1 to 1+i
f(z) = e^z # define the integrand
c1(t) = t # parametrized where c1(t):[0,1] c2(t) = 1+I*t # parametrized where c2(t):[0,1]
start = 0 stop = 1 N = 1000
line_points = srange(float(start), float(stop), (stop-start)/N,include_endpoint=True) z1=map(c1,line_points) z2=map(c2,line_points)
X = sum(f(z1[i])*(z1[i+1]-z1[i]) for i in range(0,N-1)) Y = sum(f(z2[i])*(z2[i+1]-z2[i]) for i in range(0,N-1)) X+Y # Approximation of the integral sums
0.468549044512 + 2.28650890995*I
dc1(t)=c1.diff(t) # derivative of c1(t) dc2(t)=c2.diff(t) # derivative of c2(t) answer1=integrate(f(c1(t))*dc1(t),(t,start,stop)) answer2=integrate(f(c2(t))*dc2(t),(t,start,stop)) answer=answer1+answer2 answer # final solution of adding the two integrals
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
# Now as we can see, the approximation sums and parametrization solutions are very close