Contact
CoCalc Logo Icon
StoreFeaturesDocsShareSupport News AboutSign UpSign In
| Download

All published worksheets from http://sagenb.org

Views: 168698
Image: ubuntu2004
# Integrate z^2 on the line y=x from 0 to 1+i
f(z) = z^2 # define the integrand
c(t) = t+I*t # Parametrized 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 z^2 on line
-0.663670998 + 0.663670998*I
dc(t)=c.diff(t) # derivaive of c(t) answer=integrate(f(c(t))*dc(t),(t,start,stop)) # integrate using parametrization answer
2/3*I - 2/3
float(answer.real_part())+float(answer.imag_part())*I
Traceback (most recent call last): File "<stdin>", line 1, in <module> File "_sage_input_12.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/tmpQIQ0Yu/___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'
# Just like as I attempted on Problem#1 part A, I was unable to calculate the previous cell. But as we look closely at the parametrized solution and approximation solution, we see that the solution are closely similar.