Contact
CoCalc Logo Icon
StoreFeaturesDocsShareSupport News AboutSign UpSign In
| Download

All published worksheets from http://sagenb.org

Views: 168758
Image: ubuntu2004
Se define el valor de x
x = 3
el programa define la variable x
x
3
Se introduce un valor cualquiera de x para saber si el programa tiene definido, como x no vale 4 lo evalúa falso
x == 4
False
Nuevamente le damos un valor a x de 3 y ahora el programa lo evalúa como verdadero
x == 3
True
se define una desigualdad para x
x < 5
True
y = 3
x + y
6
x**3
27
x^3
27
20%3
2
50/10
5
50/7
50/7
50//7
7
100//8
12
2%5
2
numerical_approx(pi, prec=500)
3.14159265358979323846264338327950288419716939937510582097494459230781640628620899862803482534211706798214808651328230664709384460955058223172535940813
numerical_approx(pi, prec=2000)
3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342117067982148086513282306647093844609550582231725359408128481117450284102701938521105559644622948954930381964428810975665933446128475648233786783165271201909145648566923460348610454326648213393607260249141273724587006606315588174881520920962829254091715364367892590360011330530548820466521384146951941511609433057270365759591953092186117381932611793105118548074462379962749567351885752724891227938183011949129833673362440656643086021394946395224737190702179860943702770539217176293176752384674818467669405132
exp(2)
e^2
e^2
e^2
n(e^(3))
20.0855369231877
sqrt(pi)
sqrt(pi)
sqrt(pi).numerical_approx(8)
1.8
sqrt(pi).numerical_approx(5)
1.8
sqrt(pi).numerical_approx()
1.77245385090552
sqrt(pi).numerical_approx(digits=4)
1.772
sin(10)
sin(10)
sin(10).n(digits=5)
-0.54402
sin(10).n(digits=6)
-0.544021
sin(10).n(digits=17)
-0.54402111088936981
a = 6
type (a)
<type 'sage.rings.integer.Integer'>
a = 6/4
type (a)
<type 'sage.rings.rational.Rational'>
a = 'Berenice'
type (a)
<type 'str'>
022
18
0432
282
15 + 3
18
n = 18
n.str(8)
'22'
integer?
sudoku?
n = 2
def is_even(n): return n%3 == 0
is_even(9)
True
def is_even(n): return n%4 == 2
is_even(18)
True
is_even(1234560)
True
def is_divisible_by(number,divisor=7): return number%divisor == 0
is_divisible_by(14,14)
True
is_divisible_by (7)
True
is_divisible_by (63,63)
True
def is_divisible_by(number,divisor=8): return number%divisor == 0
is_divisible_by (64,8)
True
def is_divisible_by(number,divisor=9): return number%divisor == 0
is_divisible_by (18,9)
True
is_divisible_by (54,18)
True
def is_divisible_by (number,divisor=9): return number%divisor == 1
is_divisible_by (28,9)
True
is_divisible_by (19,divisor=9)
True
def is_divisible_by (number,divisor=9): return number%divisor == 1
is_divisible_by (19,divisor=9)
True
is_divisible_by (divisor=9,number=19)
True
def even(n): v = [] for i in range(3,n): if i % 2 == 0: v.append(i) return v
Syntax Error: return v
def even(n): v = [] for i in range(3,n): if i % 2 == 0: v.append(i) return v
even(10)
[4, 6, 8]
def even(n): v = [] for i in range(6,n): if i % 3 == 1: v.append(i) return v
even(100)
[7, 10, 13, 16, 19, 22, 25, 28, 31, 34, 37, 40, 43, 46, 49, 52, 55, 58, 61, 64, 67, 70, 73, 76, 79, 82, 85, 88, 91, 94, 97]
a = 7; b = a + 3; c = b^2; c
100
a = 3; b= a^2; c = b - 8; c
1
3 + \ 4
7
for i in range(7): print i
0 1 2 3 4 5 6
for i in range (14): print i
0 1 2 3 4 5 6 7 8 9 10 11 12 13
for i in range(1,14): print i
1 2 3 4 5 6 7 8 9 10 11 12 13
for i in range(2,8,2): print i
2 4 6
for i in range(15): print '%10s %10s %10s'%(i, i^2, i^3)
0 0 0 1 1 1 2 4 8 3 9 27 4 16 64 5 25 125 6 36 216 7 49 343 8 64 512 9 81 729 10 100 1000 11 121 1331 12 144 1728 13 169 2197 14 196 2744
range(9,20)
[9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19]
v = [1, "berenice", 2/3, sin(x^3), 134]
v[1]
'berenice'
len(v)
5
v.append(9)
v
[1, 'berenice', 2/3, sin(x^3), 134, 1.80000000000000, 9]
del v [5]
v
[1, 'berenice', 2/3, sin(x^3), 134, 9]
d = {'sonia':5, 3/8:pi, e:pi}
d['sonia']
5
d[e]
pi
d = {'offray':10, 5/9:pi, e:2}
d[5/9]
pi
d = {'offray':10, 5/9:pi, e:2, 2:2}
d[2]
2
d[e]
2
d = {'offray':10, 5/9:pi, e:2, 1:3}
d[5]
2
class Evens(list): def __init__(self, n): self.n = n list.__init__(self, range(4, n+1, 4)) def __repr__(self): return "Sebastian"
f = Evens (20)
f
Sebastian
list(f)
[4, 8, 12, 16, 20]
f.n
20
f[3]
16
x = var('x')
solve(x^2 + 3*x + 2, x)
[x == -2, x == -1]
x, b, c = var('x b c')
solve([x^2 + b*x + c == 0],x)
[x == -1/2*b - 1/2*sqrt(b^2 - 4*c), x == -1/2*b + 1/2*sqrt(b^2 - 4*c)]
x, y = var('x, y')
solve([x+y==6, x-y==4], x, y)
[[x == 5, y == 1]]
var('x y p q')
(x, y, p, q)
eq1 = p+q==9
eq2 = q*y+p*x==-6
eq3 = q*y^2+p*x^2==24
solve([eq1,eq2,eq3,p==1],p,q,x,y)
[[p == 1, q == 8, x == -4/3*sqrt(10) - 2/3, y == 1/6*sqrt(2)*sqrt(5) - 2/3], [p == 1, q == 8, x == 4/3*sqrt(10) - 2/3, y == -1/6*sqrt(2)*sqrt(5) - 2/3]]
solve([eq1,eq2,eq3,p==2],p,q,x,y)
[[p == 2, q == 7, x == -1/3*sqrt(70) - 2/3, y == 2/21*sqrt(2)*sqrt(5)*sqrt(7) - 2/3], [p == 2, q == 7, x == 1/3*sqrt(70) - 2/3, y == -2/21*sqrt(2)*sqrt(5)*sqrt(7) - 2/3]]
solns = solve([eq1,eq2,eq3,p==1],p,q,x,y, solution_dict=True)
[[s[p].n(10), s[q].n(10), s[x].n(10), s[y].n(10)] for s in solns]
[[1.0, 8.0, -4.9, -0.14], [1.0, 8.0, 3.6, -1.2]]
[[s[p].n(30), s[q].n(30), s[x].n(30), s[y].n(30)] for s in solns]
[[1.0000000, 8.0000000, -4.8830369, -0.13962039], [1.0000000, 8.0000000, 3.5497035, -1.1937129]]
[[s[p].n(20), s[q].n(20), s[x].n(20), s[y].n(20)] for s in solns]
[[1.0000, 8.0000, -4.8830, -0.13962], [1.0000, 8.0000, 3.5497, -1.1937]]
theta = var('theta')
[sin(theta) == cos(theta)]
[sin(theta) == cos(theta)]
find_root(cos(theta)==sin(theta),0,pi/2)
0.78539816339744839
rho = var('rho')
[ sin(rho) == cos(rho)]
[sin(rho) == cos(rho)]
find_root(cos(rho)==sin(rho),0,pi/2)
Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/home/sage/sagenb/sage_notebook/worksheets/sonia.ortiz/7/code/66.py", line 7, in <module> exec compile(ur'find_root(cos(rho)==sin(rho),_sage_const_0 ,pi/_sage_const_2 )' + '\n', '', 'single') File "", line 1, in <module> File "/home/sage/sage_install/sage/local/lib/python2.6/site-packages/sage/numerical/optimize.py", line 67, in find_root return f.find_root(a=a,b=b,xtol=xtol,rtol=rtol,maxiter=maxiter,full_output=full_output) File "expression.pyx", line 5714, in sage.symbolic.expression.Expression.find_root (sage/symbolic/expression.cpp:22957) File "/home/sage/sage_install/sage/local/lib/python2.6/site-packages/sage/numerical/optimize.py", line 70, in find_root a = float(a); b = float(b) File "expression.pyx", line 878, in sage.symbolic.expression.Expression.__float__ (sage/symbolic/expression.cpp:5524) TypeError: float() argument must be a string or a number
heta = var('theta')
solve(cos(theta)==sin(theta))
Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/home/sage/sagenb/sage_notebook/worksheets/sonia.ortiz/7/code/68.py", line 6, in <module> exec compile(ur'solve(cos(theta)==sin(theta))' + '\n', '', 'single') File "", line 1, in <module> File "/home/sage/sage_install/sage/local/lib/python2.6/site-packages/sage/symbolic/relation.py", line 480, in solve return f.solve(*args,**kwds) File "expression.pyx", line 5511, in sage.symbolic.expression.Expression.solve (sage/symbolic/expression.cpp:21729) TypeError: solve() takes at least 1 positional argument (0 given)
[sin(theta) == cos(theta)]
[sin(theta) == cos(theta)]
find_root(cos(theta)==sin(theta),0,pi/2)
Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/home/sage/sagenb/sage_notebook/worksheets/sonia.ortiz/7/code/70.py", line 7, in <module> exec compile(ur'find_root(cos(theta)==sin(theta),_sage_const_0 ,pi/_sage_const_2 )' + '\n', '', 'single') File "", line 1, in <module> File "/home/sage/sage_install/sage/local/lib/python2.6/site-packages/sage/numerical/optimize.py", line 67, in find_root return f.find_root(a=a,b=b,xtol=xtol,rtol=rtol,maxiter=maxiter,full_output=full_output) File "expression.pyx", line 5714, in sage.symbolic.expression.Expression.find_root (sage/symbolic/expression.cpp:22957) File "/home/sage/sage_install/sage/local/lib/python2.6/site-packages/sage/numerical/optimize.py", line 70, in find_root a = float(a); b = float(b) File "expression.pyx", line 878, in sage.symbolic.expression.Expression.__float__ (sage/symbolic/expression.cpp:5524) TypeError: float() argument must be a string or a number
(cos(theta)==sin(theta),0,pi/2)
Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/home/sage/sagenb/sage_notebook/worksheets/sonia.ortiz/7/code/1.py", line 9, in <module> exec compile(ur'(cos(theta)==sin(theta),_sage_const_0 ,pi/_sage_const_2 )' + '\n', '', 'single') File "", line 1, in <module> NameError: name 'theta' is not defined
x, y, z = var('x,y,z')
f(x, y, z) = 4*x^2 * (x^2 + y^2 + z^2 + z) + y^2 * (y^2 + z^2 - 1)
implicit_plot3d(f, (x, -0.5, 0.5), (y, -1, 1), (z, -1, 1))
x, y = var('x,y')
plot3d(x^2 + y^2, (x,-2,2), (y,-2,2))
Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/home/sage/sagenb/sage_notebook/worksheets/sonia.ortiz/7/code/8.py", line 7, in <module> exec compile(ur'plot2d(x**_sage_const_2 + y**_sage_const_2 , (x,-_sage_const_2 ,_sage_const_2 ), (y,-_sage_const_2 ,_sage_const_2 ))' + '\n', '', 'single') File "", line 1, in <module> NameError: name 'plot2d' is not defined