CalcII Basics

241 days ago by tazzalenghe

integral(x^2, x, -1,2); # Here is a definite integral: you need the formula for f(x), the variable ofintegration x, and the limits of integration. 
       
3
3
integral(x^2, x, c, d); # Try to use symbolic limits and get a typical SAGE complaint. So we ask for help below by appending a ?--adding anything else like these comments causes confusion. 
       
Traceback (click to the left of this block for traceback)
...
SyntaxError: invalid syntax
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "_sage_input_6.py", line 10, in <module>
    exec compile(u'open("___code___.py","w").write("# -*- coding: utf-8 -*-\\n" + _support_.preparse_worksheet_cell(base64.b64decode("aW50ZWdyYWwoeF4yLCB4LCBjLCBkKTsgIyBUcnkgdG8gdXNlIHN5bWJvbGljIGxpbWl0cyBhbmQgZ2V0IGEgdHlwaWNhbCBTQUdFIGNvbXBsYWludC4gU28gd2UgYXNrIGZvciBoZWxwIApiZWxvdyBieSBhcHBlbmRpbmcgYSA/LS1hZGRpbmcgYW55dGhpbmcgZWxzZSBsaWtlIHRoZXNlIGNvbW1lbnRzIGNhdXNlcyBjb25mdXNpb24u"),globals())+"\\n"); execfile(os.path.abspath("___code___.py"))
  File "", line 1, in <module>
    
  File "/tmp/tmpKx7CFh/___code___.py", line 4
    below by appending a ?--adding anything else like these comments causes confusion.
           ^
SyntaxError: invalid syntax
integral? 
       

File: /sagenb/sage_install/sage-4.7/local/lib/python2.6/site-packages/sage/misc/functional.py

Type: <type ‘function’>

Definition: integral(x, *args, **kwds)

Docstring:

Returns an indefinite or definite integral of an object x.

First call x.integrate() and if that fails make an object and integrate it using Maxima, maple, etc, as specified by algorithm.

For symbolic expression calls sage.calculus.calculus.integral - see this function for available options.

EXAMPLES:

sage: f = cyclotomic_polynomial(10)
sage: integral(f)
1/5*x^5 - 1/4*x^4 + 1/3*x^3 - 1/2*x^2 + x
sage: integral(sin(x),x)
-cos(x)
sage: y = var('y')
sage: integral(sin(x),y)
y*sin(x)
sage: integral(sin(x), x, 0, pi/2)
1
sage: sin(x).integral(x, 0,pi/2)
1
sage: integral(exp(-x), (x, 1, oo))
e^(-1)

Numerical approximation:

sage: h = integral(tan(x)/x, (x, 1, pi/3)); h
integrate(tan(x)/x, x, 1, 1/3*pi)
sage: h.n()
0.07571599101...

Specific algorithm can be used for integration:

sage: integral(sin(x)^2, x, algorithm='maxima')
1/2*x - 1/4*sin(2*x)
sage: integral(sin(x)^2, x, algorithm='sympy')
-1/2*sin(x)*cos(x) + 1/2*x

File: /sagenb/sage_install/sage-4.7/local/lib/python2.6/site-packages/sage/misc/functional.py

Type: <type ‘function’>

Definition: integral(x, *args, **kwds)

Docstring:

Returns an indefinite or definite integral of an object x.

First call x.integrate() and if that fails make an object and integrate it using Maxima, maple, etc, as specified by algorithm.

For symbolic expression calls sage.calculus.calculus.integral - see this function for available options.

EXAMPLES:

sage: f = cyclotomic_polynomial(10)
sage: integral(f)
1/5*x^5 - 1/4*x^4 + 1/3*x^3 - 1/2*x^2 + x
sage: integral(sin(x),x)
-cos(x)
sage: y = var('y')
sage: integral(sin(x),y)
y*sin(x)
sage: integral(sin(x), x, 0, pi/2)
1
sage: sin(x).integral(x, 0,pi/2)
1
sage: integral(exp(-x), (x, 1, oo))
e^(-1)

Numerical approximation:

sage: h = integral(tan(x)/x, (x, 1, pi/3)); h
integrate(tan(x)/x, x, 1, 1/3*pi)
sage: h.n()
0.07571599101...

Specific algorithm can be used for integration:

sage: integral(sin(x)^2, x, algorithm='maxima')
1/2*x - 1/4*sin(2*x)
sage: integral(sin(x)^2, x, algorithm='sympy')
-1/2*sin(x)*cos(x) + 1/2*x
c = var('a'); d = var('b'); integral(x^2,x,a,b) # Have to tell SAGE to treat c and d as variables, not look for values and then it can integrate. That is SAGE can do indefinite integrals too. 
       
-1/3*a^3 + 1/3*b^3
-1/3*a^3 + 1/3*b^3
integral(x^2,x,a,b) #Note the nice 2-D layout which I get by checking the Typeset box at the top. 
       
\newcommand{\Bold}[1]{\mathbf{#1}}-\frac{1}{3} \, a^{3} + \frac{1}{3} \, b^{3}
\newcommand{\Bold}[1]{\mathbf{#1}}-\frac{1}{3} \, a^{3} + \frac{1}{3} \, b^{3}
integral(x^2,x); # As the help shows we just leave out the limits to get a standard indefinite integral form 
       
\newcommand{\Bold}[1]{\mathbf{#1}}\frac{1}{3} \, x^{3}
\newcommand{\Bold}[1]{\mathbf{#1}}\frac{1}{3} \, x^{3}
integral(sin(x),x); 
       
\newcommand{\Bold}[1]{\mathbf{#1}}-\cos\left(x\right)
\newcommand{\Bold}[1]{\mathbf{#1}}-\cos\left(x\right)
f = integral((sin(x))^6,x); f # Note that you must put the exponent at the right not after the sin. We'll learn the tricks SAGE is using here in Chapter 7. 
       
\newcommand{\Bold}[1]{\mathbf{#1}}\frac{1}{48} \, \sin\left(2 \, x\right)^{3} + \frac{5}{16} \, x - \frac{1}{4} \, \sin\left(2 \, x\right) + \frac{3}{64} \, \sin\left(4 \, x\right)
\newcommand{\Bold}[1]{\mathbf{#1}}\frac{1}{48} \, \sin\left(2 \, x\right)^{3} + \frac{5}{16} \, x - \frac{1}{4} \, \sin\left(2 \, x\right) + \frac{3}{64} \, \sin\left(4 \, x\right)
g = derivative(f); g; h=g.simplify_trig();h; #SAGE differentiates too. More impressively it knows all the trig identities (and can use them!). 
       
\newcommand{\Bold}[1]{\mathbf{#1}}\frac{1}{8} \, \sin\left(2 \, x\right)^{2} \cos\left(2 \, x\right) - \frac{1}{2} \, \cos\left(2 \, x\right) + \frac{3}{16} \, \cos\left(4 \, x\right) + \frac{5}{16}
\newcommand{\Bold}[1]{\mathbf{#1}}\sin\left(x\right)^{6}
\newcommand{\Bold}[1]{\mathbf{#1}}\frac{1}{8} \, \sin\left(2 \, x\right)^{2} \cos\left(2 \, x\right) - \frac{1}{2} \, \cos\left(2 \, x\right) + \frac{3}{16} \, \cos\left(4 \, x\right) + \frac{5}{16}
\newcommand{\Bold}[1]{\mathbf{#1}}\sin\left(x\right)^{6}
print "If f(x)=", f, "\nthen f'(x)=", g, "\n---or, after simplifying---", h # We can get the answer in human readbale form by using a print statement. See the Sage tutorial for details on this. The \n just starts a new line. 
       
If f(x)= 1/48*sin(2*x)^3 + 5/16*x - 1/4*sin(2*x) + 3/64*sin(4*x) 
then f'(x)= 1/8*sin(2*x)^2*cos(2*x) - 1/2*cos(2*x) + 3/16*cos(4*x) +
5/16 
---or, after simplifying--- sin(x)^6
If f(x)= 1/48*sin(2*x)^3 + 5/16*x - 1/4*sin(2*x) + 3/64*sin(4*x) 
then f'(x)= 1/8*sin(2*x)^2*cos(2*x) - 1/2*cos(2*x) + 3/16*cos(4*x) + 5/16 
---or, after simplifying--- sin(x)^6