Contact
CoCalc Logo Icon
StoreFeaturesDocsShareSupport News AboutSign UpSign In
| Download

All published worksheets from http://sagenb.org

Views: 168703
Image: ubuntu2004
#Integrate z on the line y=x from 0 to 1+i
f(z)= z #Define the integrand
c(t) = t + I*t #parameterized the line. c(t):[0,1] -> line in C.
start = 0 stop = 1 N = 1000 #c(t) will map the interval [start,stop] on the curve where f(z) is o be integrated. N is the number of points to us in approximation of the 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 z dz on line
0.997002*I
dc(t) = c.diff(t) # derivative of c(t) answer=integrate(f(c(t))*dc(t),(t,start,stop)) # integrate using parametrization answer
I
float(answer.real_part())+float(answer.imag_part())*I #check if answer from parameterization agrees with approximation taking its floating-point value
Traceback (most recent call last): File "<stdin>", line 1, in <module> File "_sage_input_4.py", line 10, in <module> exec compile(u'open("___code___.py","w").write("# -*- coding: utf-8 -*-\\n" + _support_.preparse_worksheet_cell(base64.b64decode("ZmxvYXQoYW5zd2VyLnJlYWxfcGFydCgpKStmbG9hdChhbnN3ZXIuaW1hZ19wYXJ0KCkpKkkKICAjY2hlY2sgaWYgYW5zd2VyIGZyb20gcGFyYW1ldGVyaXphdGlvbiBhZ3JlZXMgd2l0aCBhcHByb3hpbWF0aW9uIHRha2luZyBpdHMgZmxvYXRpbmctcG9pbnQgdmFsdWU="),globals())+"\\n"); execfile(os.path.abspath("___code___.py"))' + '\n', '', 'single') File "", line 1, in <module> File "/tmp/tmpzHLXPD/___code___.py", line 2, in <module> exec compile(u'float(answer.real_part())+float(answer.imag_part())*I\n #check if answer from parameterization agrees with approximation taking its floating-point value' + '\n', '', 'single') File "", line 1, in <module> NameError: name 'answer' is not defined
# Even though the previous cell was not able to somehow compare the parametrization and sum approximation of the integral, we see that they are both close to the solution of "I"