Contact
CoCalc Logo Icon
StoreFeaturesDocsShareSupport News AboutSign UpSign In
| Download

All published worksheets from http://sagenb.org

Views: 168728
Image: ubuntu2004
2+2
4
2^30
1073741824
10!
Traceback (most recent call last): File "<stdin>", line 1, in <module> File "_sage_input_5.py", line 10, in <module> exec compile(u'open("___code___.py","w").write("# -*- coding: utf-8 -*-\\n" + _support_.preparse_worksheet_cell(base64.b64decode("MTAh"),globals())+"\\n"); execfile(os.path.abspath("___code___.py"))' + '\n', '', 'single') File "", line 1, in <module> File "/tmp/tmpNoxjOp/___code___.py", line 3 _sage_const_10 ! ^ SyntaxError: invalid syntax
factorial(100)
93326215443944152681699238856266700490715968264381621468592963895217599993229915608941463976156518286253697920827223758251185210916864000000000000000000000000
cos(pi)
-1
n(pi)
3.14159265358979
factor(5557891)
47 * 118253
is_prime(118253)
True
n(pi, 100)
3.1415926535897932384626433833
sum(n, 1, 10)
Traceback (most recent call last): File "<stdin>", line 1, in <module> File "_sage_input_16.py", line 10, in <module> exec compile(u'open("___code___.py","w").write("# -*- coding: utf-8 -*-\\n" + _support_.preparse_worksheet_cell(base64.b64decode("c3VtKG4sIDEsIDEwKQ=="),globals())+"\\n"); execfile(os.path.abspath("___code___.py"))' + '\n', '', 'single') File "", line 1, in <module> File "/tmp/tmpYbjguo/___code___.py", line 3, in <module> exec compile(u'sum(n, _sage_const_1 , _sage_const_10 )' + '\n', '', 'single') File "", line 1, in <module> File "/sagenb/sage_install/sage-4.7.2/local/lib/python2.6/site-packages/sage/misc/functional.py", line 662, in symbolic_sum return SR(expression).sum(*args, **kwds) File "parent.pyx", line 988, in sage.structure.parent.Parent.__call__ (sage/structure/parent.c:7326) File "coerce_maps.pyx", line 82, in sage.structure.coerce_maps.DefaultConvertMap_unique._call_ (sage/structure/coerce_maps.c:3268) File "coerce_maps.pyx", line 77, in sage.structure.coerce_maps.DefaultConvertMap_unique._call_ (sage/structure/coerce_maps.c:3171) File "ring.pyx", line 285, in sage.symbolic.ring.SymbolicRing._element_constructor_ (sage/symbolic/ring.cpp:4418) TypeError
sum(range(1, 11))
55
range(1,11)
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
range(1, 11, 2)
[1, 3, 5, 7, 9]
[i^2 for i in range(1,11)]
[1, 4, 9, 16, 25, 36, 49, 64, 81, 100]
L = [i^2 for i in range(1,11) if is_prime(i)]
sum(L)
87
var('n')
n
sum(n, n, 1, 10)
55
sum(1/n^2, n, 1, oo)
1/6*pi^2
n(pi)
pi
numerical_approx(pi)
3.14159265358979
reset('n')
n(pi)
3.14159265358979
integral?

File: /sagenb/sage_install/sage-4.7.2/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
integral(x^2, x)
1/3*x^3
integral(x^2, x, 0, 1)
1/3
derivative?

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

Type: <type ‘function’>

Definition: derivative(f, *args, **kwds)

Docstring:

The derivative of f.

Repeated differentiation is supported by the syntax given in the examples below.

ALIAS: diff

EXAMPLES: We differentiate a callable symbolic function:

sage: f(x,y) = x*y + sin(x^2) + e^(-x)
sage: f
(x, y) |--> x*y + e^(-x) + sin(x^2)
sage: derivative(f, x)
(x, y) |--> 2*x*cos(x^2) + y - e^(-x)
sage: derivative(f, y)
(x, y) |--> x

We differentiate a polynomial:

sage: t = polygen(QQ, 't')
sage: f = (1-t)^5; f
-t^5 + 5*t^4 - 10*t^3 + 10*t^2 - 5*t + 1
sage: derivative(f)
-5*t^4 + 20*t^3 - 30*t^2 + 20*t - 5
sage: derivative(f, t)
-5*t^4 + 20*t^3 - 30*t^2 + 20*t - 5
sage: derivative(f, t, t)
-20*t^3 + 60*t^2 - 60*t + 20
sage: derivative(f, t, 2)
-20*t^3 + 60*t^2 - 60*t + 20
sage: derivative(f, 2)
-20*t^3 + 60*t^2 - 60*t + 20

We differentiate a symbolic expression:

sage: var('a x')
(a, x)
sage: f = exp(sin(a - x^2))/x
sage: derivative(f, x)
-2*e^(sin(-x^2 + a))*cos(-x^2 + a) - e^(sin(-x^2 + a))/x^2
sage: derivative(f, a)
e^(sin(-x^2 + a))*cos(-x^2 + a)/x

Syntax for repeated differentiation:

sage: R.<u, v> = PolynomialRing(QQ)
sage: f = u^4*v^5
sage: derivative(f, u)
4*u^3*v^5
sage: f.derivative(u)   # can always use method notation too
4*u^3*v^5
sage: derivative(f, u, u)
12*u^2*v^5
sage: derivative(f, u, u, u)
24*u*v^5
sage: derivative(f, u, 3)
24*u*v^5
sage: derivative(f, u, v)
20*u^3*v^4
sage: derivative(f, u, 2, v)
60*u^2*v^4
sage: derivative(f, u, v, 2)
80*u^3*v^3
sage: derivative(f, [u, v, v])
80*u^3*v^3