Contact
CoCalc Logo Icon
StoreFeaturesDocsShareSupport News AboutSign UpSign In
| Download

All published worksheets from http://sagenb.org

Views: 168746
Image: ubuntu2004
money=10000;year=0
while money<20000: years=years+1 money=money*1.0069
Traceback (most recent call last): File "<stdin>", line 1, in <module> File "_sage_input_7.py", line 10, in <module> exec compile(u'open("___code___.py","w").write("# -*- coding: utf-8 -*-\\n" + _support_.preparse_worksheet_cell(base64.b64decode("d2hpbGUgbW9uZXk8MjAwMDA6CiAgeWVhcnM9eWVhcnMrMQptb25leT1tb25leSoxLjAwNjk="),globals())+"\\n"); execfile(os.path.abspath("___code___.py"))' + '\n', '', 'single') File "", line 1, in <module> File "/tmp/tmps3MT5U/___code___.py", line 4, in <module> years=years+_sage_const_1 NameError: name 'years' is not defined
#!/usr/bin/env sage
n=10
m=0
x=range(n)
while x<100: p=random() if p<0.2: x[m]=1 else: x[m]=0 m=m+1
x
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
epsilion=0.01
x_pre=infinity
x=0.0
while abs(x-x_pre)>epsilion: x_pre=x x=x_pre**3-x_pre+1
x
1.00000000000000
x=0;x+=1;x
1
x=2;x**=2;x
4
x=[123,'xyz'];x+=[011];x
[123, 'xyz', 9]
x=y=z=123
x
123
y
123
z
123
x,y,z=1,2,3
x
1
y
2
z
3
x=666;y=888
x,y=y,x
x
888
y
666
#!/usr/bin/env sage
x=1
x+=100
x
101
load myadd.sage
Traceback (most recent call last): File "<stdin>", line 1, in <module> File "_sage_input_76.py", line 10, in <module> exec compile(u'open("___code___.py","w").write("# -*- coding: utf-8 -*-\\n" + _support_.preparse_worksheet_cell(base64.b64decode("bG9hZCBteWFkZC5zYWdl"),globals())+"\\n"); execfile(os.path.abspath("___code___.py"))' + '\n', '', 'single') File "", line 1, in <module> File "/tmp/tmpvgeEJw/___code___.py", line 2, in <module> exec compile(u'sage.misc.preparser.load(sage.misc.preparser.base64.b64decode("bXlhZGQuc2FnZQ=="),globals(),False)' + '\n', '', 'single') File "", line 1, in <module> File "/usr/local/sage2/local/lib/python2.6/site-packages/sage/misc/preparser.py", line 1503, in load exec(preparse_file(open(filename).read()), globals) IOError: [Errno 2] No such file or directory: 'myadd.sage'
x
101
attach myadd.sage
Traceback (most recent call last): File "<stdin>", line 1, in <module> File "_sage_input_78.py", line 10, in <module> exec compile(u'open("___code___.py","w").write("# -*- coding: utf-8 -*-\\n" + _support_.preparse_worksheet_cell(base64.b64decode("YXR0YWNoIG15YWRkLnNhZ2U="),globals())+"\\n"); execfile(os.path.abspath("___code___.py"))' + '\n', '', 'single') File "", line 1, in <module> File "/tmp/tmpnjCzga/___code___.py", line 2, in <module> exec compile(u'sage.misc.preparser.load(sage.misc.preparser.base64.b64decode("bXlhZGQuc2FnZQ=="),globals(),True)' + '\n', '', 'single') File "", line 1, in <module> File "/usr/local/sage2/local/lib/python2.6/site-packages/sage/misc/preparser.py", line 1503, in load exec(preparse_file(open(filename).read()), globals) IOError: [Errno 2] No such file or directory: 'myadd.sage'
x
101
x
101
#!/usr/bin/env sage
n=10
x=[int(random()*100) for each in range(n)]
print "random numbers is ",x
random numbers is [19, 19, 75, 94, 66, 19, 63, 58, 88, 4]
for each in range(n-1): for k in range(n-1): if x[k]<x[k+1]: x[k],x[k+1]=[k+1],x[k] print "sorted is",x
sorted is [[1], [1], [1], [1], [1], [1], 19, 19, 19, 4]
sage:load bubble_sort.py
Traceback (most recent call last): File "<stdin>", line 1, in <module> File "_sage_input_92.py", line 10, in <module> exec compile(u'open("___code___.py","w").write("# -*- coding: utf-8 -*-\\n" + _support_.preparse_worksheet_cell(base64.b64decode("YnViYmxlX3NvcnQucHk="),globals())+"\\n"); execfile(os.path.abspath("___code___.py"))' + '\n', '', 'single') File "", line 1, in <module> File "/tmp/tmpzHE3d0/___code___.py", line 2, in <module> exec compile(u'bubble_sort.py' + '\n', '', 'single') File "", line 1, in <module> NameError: name 'bubble_sort' is not defined
random number is [94,15,90,85,29,19,11,77,55,13]
Traceback (most recent call last): File "<stdin>", line 1, in <module> File "_sage_input_93.py", line 10, in <module> exec compile(u'open("___code___.py","w").write("# -*- coding: utf-8 -*-\\n" + _support_.preparse_worksheet_cell(base64.b64decode("cmFuZG9tIG51bWJlciBpcyBbOTQsMTUsOTAsODUsMjksMTksMTEsNzcsNTUsMTNd"),globals())+"\\n"); execfile(os.path.abspath("___code___.py"))' + '\n', '', 'single') File "", line 1, in <module> File "/tmp/tmpB8HcZg/___code___.py", line 3 random number is [_sage_const_94 ,_sage_const_15 ,_sage_const_90 ,_sage_const_85 ,_sage_const_29 ,_sage_const_19 ,_sage_const_11 ,_sage_const_77 ,_sage_const_55 ,_sage_const_13 ] ^ SyntaxError: invalid syntax
sorted is [94,190,85,77,55,29,19,15,13,11]
False
n=var('n')
a_n=(1+1/n)**n
a_n.limit(n=oo)
e
limit(sin(n*pi/3),n=oo)
ind
n=var('n')
limit((n**2-1)/(n+5),n=oo)
+Infinity
x=var('x')
diff(sin(x),x)
cos(x)
diff(sin(x),x,2)
-sin(x)
x,y=var('x,y')
f=x^2*y+x*exp(y)
f.diff(x,y)
2*x + e^y
var('x,a')
(x, a)
f=exp(sin(a-x^2))/x
f.derivative(x)
-2*e^(sin(-x^2 + a))*cos(-x^2 + a) - e^(sin(-x^2 + a))/x^2
x=var('x')
f=sin(x)
taylor(f,x,0,6)
1/120*x^5 - 1/6*x^3 + x
a=matrix(ZZ,[[3,1,1],[2,1,2]])
B=matrix(ZZ,[[1,-2,3],[4,5,-6]])
a+b
[ 4 -1 4] [ 6 6 -4]
a-b
[ 2 3 -2] [-2 -4 8]
a.transpose()
[3 2] [1 1] [1 2]
transpose(a.transpose())
[3 1 1] [2 1 2]
a*b.transpose()
[ 4 11] [ 6 1]
transpose(b)*a
[11 5 9] [ 4 3 8] [-3 -3 -9]
A=matrix(QQ,3,range(9));A
[0 1 2] [3 4 5] [6 7 8]
b=matrix(QQ,3,1,[1,2,3]);b
[1] [2] [3]
x=A\b;x
[-2/3] [ 1] [ 0]
A*x
[1] [2] [3]
A=matrix(QQ,3,range(9));A[0,0]=2;A
[2 1 2] [3 4 5] [6 7 8]
b=matrix(QQ,1,3,[1,2,3]);b
[1 2 3]
x=b*A^(-1);x
[ 0 5/3 -2/3]
x*A
[1 2 3]
(8*a)*b.transpose()
[64] [80]
8*(a*transpose(b))
[64] [80]
Q=matrix([[2,1,0,0,0],[0,2,1,0,0],[0,0,2,1,0],[0,0,0,2,1],[0,0,0,0,2]])
Q^3
[ 8 12 6 1 0] [ 0 8 12 6 1] [ 0 0 8 12 6] [ 0 0 0 8 12] [ 0 0 0 0 8]
rank(Q)
5
Q.inverse()
[ 1/2 -1/4 1/8 -1/16 1/32] [ 0 1/2 -1/4 1/8 -1/16] [ 0 0 1/2 -1/4 1/8] [ 0 0 0 1/2 -1/4] [ 0 0 0 0 1/2]
Q^(-1)*Q
[1 0 0 0 0] [0 1 0 0 0] [0 0 1 0 0] [0 0 0 1 0] [0 0 0 0 1]
A=matrix(RR,[[1,2,3],[1,3,-2],[3,7,8],[1,4,-9]])
b=matrix(RR,[[1],[1],[3],[1]])
rank(A)
3
var('a,b,c,d')
(a, b, c, d)
D=matrix\ ([[a^2,(a+1)^2,(a+2)^2,(a+3)^2],[b^2,(b+1)^2,(b+2)^2,(b+3)^2],\ [c^2,(c+1)^2,(c+2)^2,(c+3)^2],[d^2,(d+1)^2,(d+2)^2,(d+3)^2]])
D
[ a^2 (a + 1)^2 (a + 2)^2 (a + 3)^2] [ b^2 (b + 1)^2 (b + 2)^2 (b + 3)^2] [ c^2 (c + 1)^2 (c + 2)^2 (c + 3)^2] [ d^2 (d + 1)^2 (d + 2)^2 (d + 3)^2]
det(D)
0
y=matrix(RR,[[1,2],[3,4]]);y
[1.00000000000000 2.00000000000000] [3.00000000000000 4.00000000000000]