Contact
CoCalc Logo Icon
StoreFeaturesDocsShareSupport News AboutSign UpSign In
| Download

All published worksheets from http://sagenb.org

Views: 168698
Image: ubuntu2004
# integrate the function z on the broken line 0 to 1 to 1+i
f(z) = z #define the integrand
c1(t) = t #parametrize with c1(t):[0,1] c2(t) = 1+I*t # parametrize with c2(t):[0,1]
start = 0 stop = 1 N = 1000 #c1(t) and c2(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] z1 = map(c1,line_points) z2 = map(c2,line_points) #N+1 points on curve #The points are denoted z[0], z[1], ..., z[N]
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 # this is adding the approximate integral of z dz with the two integrands
0.999*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 #We break down into two parametrizations and we take the integral of these separate parametrizations, and we then add them to get the solution answer
I
float(answer.real_part())+float(answer.imag_part())*I
Traceback (most recent call last): File "<stdin>", line 1, in <module> File "_sage_input_22.py", line 10, in <module> exec compile(u'open("___code___.py","w").write("# -*- coding: utf-8 -*-\\n" + _support_.preparse_worksheet_cell(base64.b64decode("ZmxvYXQoYW5zd2VyLnJlYWxfcGFydCgpKStmbG9hdChhbnN3ZXIuaW1hZ19wYXJ0KCkpKkk="),globals())+"\\n"); execfile(os.path.abspath("___code___.py"))' + '\n', '', 'single') File "", line 1, in <module> File "/tmp/tmpWFjxXH/___code___.py", line 2, in <module> exec compile(u'float(answer.real_part())+float(answer.imag_part())*I' + '\n', '', 'single') File "", line 1, in <module> File "element.pyx", line 331, in sage.structure.element.Element.__getattr__ (sage/structure/element.c:2884) File "parent.pyx", line 327, in sage.structure.parent.getattr_from_other_class (sage/structure/parent.c:3236) AttributeError: 'sage.rings.number_field.number_field_element_quadratic.NumberFieldElement_quadratic' object has no attribute 'real_part'
# Eventhough I'm unable to somehow find the solution for the previous cell, we see that the approximation sum and parametrization solution are closely similar to "I"