# week6

## 433 days ago by wldnd1217

var('x,y,a,b,t')
 (x, y, a, b, t) (x, y, a, b, t)
#example1 f(x)=ln(tan(x))/(sin(x))^2 integral(f(x),x)
 -log(tan(x))/tan(x) - 1/tan(x) -log(tan(x))/tan(x) - 1/tan(x)
#example2 f(x)=x integral(f(x),x,a,b)
 -1/2*a^2 + 1/2*b^2 -1/2*a^2 + 1/2*b^2
#example3 f(x)=4*x-6*x^2 integral(f(x),x,-1,2)
 -12 -12
#example4 f(t)=3*sin(t) integral(f(t),t,0,x)
 Traceback (click to the left of this block for traceback) ... Is x positive, negative, or zero? Traceback (most recent call last): File "", line 1, in File "_sage_input_10.py", line 10, in exec compile(u'open("___code___.py","w").write("# -*- coding: utf-8 -*-\\n" + _support_.preparse_worksheet_cell(base64.b64decode("I2V4YW1wbGU0CmYodCk9MypzaW4odCkKaW50ZWdyYWwoZih0KSx0LDAseCk="),globals())+"\\n"); execfile(os.path.abspath("___code___.py")) File "", line 1, in File "/tmp/tmprYrO15/___code___.py", line 4, in exec compile(u'integral(f(t),t,_sage_const_0 ,x) File "", line 1, in File "/root/sage-5.8/local/lib/python2.7/site-packages/sage/misc/functional.py", line 740, in integral return x.integral(*args, **kwds) File "expression.pyx", line 9302, in sage.symbolic.expression.Expression.integral (sage/symbolic/expression.cpp:38413) File "/root/sage-5.8/local/lib/python2.7/site-packages/sage/symbolic/integration/integral.py", line 688, in integrate return definite_integral(expression, v, a, b) File "function.pyx", line 429, in sage.symbolic.function.Function.__call__ (sage/symbolic/function.cpp:5064) File "/root/sage-5.8/local/lib/python2.7/site-packages/sage/symbolic/integration/integral.py", line 173, in _eval_ return integrator(*args) File "/root/sage-5.8/local/lib/python2.7/site-packages/sage/symbolic/integration/external.py", line 21, in maxima_integrator result = maxima.sr_integral(expression, v, a, b) File "/root/sage-5.8/local/lib/python2.7/site-packages/sage/interfaces/maxima_lib.py", line 744, in sr_integral raise ValueError, "Computation failed since Maxima requested additional constraints; using the 'assume' command before integral evaluation *may* help (example of legal syntax is 'assume(" + s[4:k] +">0)', see assume? for more details)\n" + s ValueError: Computation failed since Maxima requested additional constraints; using the 'assume' command before integral evaluation *may* help (example of legal syntax is 'assume(x>0)', see assume? for more details) Is x positive, negative, or zero?
#example5 f(x)=sqrt(x^2+x)*(2*x+1) integral(f(x),x,0,4)
 16/3*(5*sqrt(5)) 16/3*(5*sqrt(5))
#example6 f(x)=(sin(x))^3*cos(2*x) integral(f(x),x,0,pi/4)
 3/10*sqrt(2) - 2/5 3/10*sqrt(2) - 2/5
#example7 f(x)=cos(sqrt(x))/sqrt(x) integral(f(x),x,pi^2/9,pi^2/4)
 -sqrt(3) + 2 -sqrt(3) + 2
#example? f(x)=(ln(x))^2 integral(f(x),x,1,2)
 2*log(2)^2 - 4*log(2) + 2 2*log(2)^2 - 4*log(2) + 2
#homework1 f(x)=1/(sin(x))^2 integral(f(x),x,pi/4,pi/3)
 -1/3*sqrt(3) + 1 -1/3*sqrt(3) + 1
#homework2 f(x)=sqrt(3-2*x-x^2) integral(f(x),x,-1,1)
 pi pi
#homework3 f(x)=(sqrt(x)+1/sqrt(x))^2 integral(f(x),x,1,3)
 log(3) + 8 log(3) + 8
#6.1 approximation integral #example1 def midpoint_rule(fcn,a,b,n): Deltax = (b-a)*1.0/n xs=[a+Deltax*i for i in range(n+1)] ysmid=[fcn((xs[i]+xs[i+1])/2) for i in range(n)] return Deltax*sum(ysmid) midpoint_rule(1/x^2,1,2,5).n()
 0.497127154652505 0.497127154652505
#example2 def trapezoid_rule(fcn,a,b,n): Deltax = (b-a)*1.0/n coeffs = [2]*(n-1) coeffs = [1]+coeffs+[1] valsf = [fcn(a+Deltax*i) for i in range(n+1)] return (Deltax/2)*sum([coeffs[i]*valsf[i] for i in range(n+1)]) trapezoid_rule((sin(x))^2,0,2,8).n()
 1.18524242212386 1.18524242212386
#example3 def simpsons_rule(fcn,a,b,n): Deltax = (b-a)*1.0/n n2=int(n/2) coeffs = [4,2]*n2 coeffs = [1] +coeffs[:n-1]+[1] valsf = [fcn(a+Deltax*i) for i in range(n+1)] return (Deltax/3)*sum([coeffs[i]*valsf[i] for i in range(n+1)]) simpsons_rule(1/(1+x^2),0,3,6).n()
 1.24708222811671 1.24708222811671
#homework1 #a simpsons_rule(e^(x^3),0,1,10).n()
 1.34202513680030 1.34202513680030
#b abs(integral(e^(x^3),x,0,1)-abs(simpsons_rule(e^(x^3),0,1,10)))
 abs(-1/3*gamma(1/3) - abs(0.0333333333333333*e + 1.25141574251834) + 1/3*gamma(1/3, -1)) abs(-1/3*gamma(1/3) - abs(0.0333333333333333*e + 1.25141574251834) + 1/3*gamma(1/3, -1))
#homework2 trapezoid_rule(e^(-x^2),-1,2,5).n()
 1.60450896786763 1.60450896786763
#6.2 area #example1 f(x)=x^2/3-4 print(solve(f(x)==0,x)) abs(integral(f(x),x,-2,3))
 [ x == -2*sqrt(3), x == 2*sqrt(3) ] 145/9 [ x == -2*sqrt(3), x == 2*sqrt(3) ] 145/9
#example2 f(x)=x^3-3*x^2-x+3 print solve(f(x)==0,x) integral(abs(f(x)),x,-1,2)
 [ x == 1, x == -1, x == 3 ] 23/4 [ x == 1, x == -1, x == 3 ] 23/4
#example3 f(y)=2*y^2 g(y)=y+1 print solve(f(y)==g(y),y) abs(integral(f(y)-g(y),y,1,-1/2))
 [ y == 1, y == (-1/2) ] 9/8 [ y == 1, y == (-1/2) ] 9/8
#example4 f(x)=x^4 g(x)=2*x-x^2 print solve(f(x)==g(x),x) abs(integral(f(x)-g(x),x,0,1))
 [ x == -1/2*I*sqrt(7) - 1/2, x == 1/2*I*sqrt(7) - 1/2, x == 1, x == 0 ] 7/15 [ x == -1/2*I*sqrt(7) - 1/2, x == 1/2*I*sqrt(7) - 1/2, x == 1, x == 0 ] 7/15
#example5 f(y)=y+1 g(y)=y^2/2-3 print solve(f(y)==g(y),y) integral(abs(f(y)-g(y)),y,-2,4)
 [ y == -2, y == 4 ] 18 [ y == -2, y == 4 ] 18
#homework1 f(x)=1/x g(x)=x print solve(f(x)==g(x),x) integral(abs(f(x)-g(x)),x,1,2)
 [ x == -1, x == 1 ] -log(2) + 3/2 [ x == -1, x == 1 ] -log(2) + 3/2
#homework2 f(y)=2*y^2 g(y)=y+1 print solve(f(y)==g(y),y) integral(abs(f(y)-g(y)),y,-1/2,1)
 [ y == 1, y == (-1/2) ] 9/8 [ y == 1, y == (-1/2) ] 9/8
#homework3 f(x)=2*x^2+10 g(x)=4*x+16 integral(abs(f(x)-g(x)),x,-2,-5)
 -102 -102
#6.3 volume #example1 f(x)=sqrt(x) integral((f(x))^2*pi,x,0,4)
 8*pi 8*pi
#homework1 f(x)=4/x integral((f(x))^2*pi,x,2,4)
 4*pi 4*pi
#homework2 f(x)=3*x-x^2 integral(2*x*pi*f(x),x,0,3)
 27/2*pi 27/2*pi
#homework3 f(y)=y g(y)=y^2 integral(f(y)^2*pi,y,0,1)-integral(g(y)^2*pi,y,0,1)
 2/15*pi 2/15*pi
#homework4 f(x)=-x+2*sin(x) integral(2*x*pi*f(x),x,0,pi/3)
 -2/81*(27*pi + pi^3 - 81*sqrt(3))*pi -2/81*(27*pi + pi^3 - 81*sqrt(3))*pi
#6.4 arc length #homework1 f(x)=2/3*(x-1)^(3/2) dx=diff(f(x),x) integral(sqrt(1+(dx)^2),x,1,4)
 14/3 14/3
#homework2 f(y)=1/4*y^4+1/(8*y^2) dy=diff(f(y),y) integral(sqrt(1+(dy)^2),y,1,2)
 123/32 123/32
#6.5 average value of a function #homework1 f(x)=e^(-x^2)*sin(x) c=(f(2)-f(0))/(2-0) print c dx=diff(f(x),x) assume(0<x<2) p=solve(dx==c,x) print p
 1/2*e^(-4)*sin(2) [ x == 1/4*(2*e^4*cos(x) - e^(x^2)*sin(2))*e^(-4)/sin(x) ] 1/2*e^(-4)*sin(2) [ x == 1/4*(2*e^4*cos(x) - e^(x^2)*sin(2))*e^(-4)/sin(x) ]