jsMath

druga

# Ponavljanje 
       
broj=2+8 
       
type(broj) 
       
<type 'sage.rings.integer.Integer'>
broj.binary() 
       
'1010'
30.factor() 
       
2 * 3 * 5
a=RR(2); b=QQ(12/5); c=a+b; type(c) 
       
<type 'sage.rings.real_mpfr.RealNumber'>
d=a+RR(2); type(d) 
       
<type 'sage.rings.real_mpfr.RealNumber'>
# Primjer 
       
n(exp(pi*sqrt(163)),digits=20) 
       
2.6253741264076874400e17
f=exp(pi*sqrt(163))-262537412640768744 
       
numerical_approx(f, digits=15) # n ili N 
       
448.000000000000
numerical_approx(f, digits=20) 
       
-0.0026855468750000000000
# Naredba plot 
       
f(x)=(x+1)/(x-1); plot(f(x),x,-1,3, ymin=-10, ymax=10,detect_poles=true, exclude=x-2==0) 
       
plot.options 
       
{'fillalpha': 0.5, 'detect_poles': False, 'plot_points': 200,
'thickness': 1, 'alpha': 1, 'adaptive_tolerance': 0.01, 'fillcolor':
'automatic', 'adaptive_recursion': 5, 'exclude': None,
'legend_label': None, 'rgbcolor': (0, 0, 1), 'fill': False}
p=plot(x+sin(x),x,-1,100, plot_points=6); show(p), p[0] 
       

(None, Line defined by 60 points)
slika = animate([circle((i,i), 0.1+i, hue=i/10) for i in srange(0,2,0.2)], xmin=-1,xmax=4,figsize=[4,2]); show(slika) # Zaustaviti i pokrenuti animaciju. 
       
eq=x^4+x+1==0; s=solve(eq,x); s 
       
[x == -1/6*sqrt((3*(1/18*I*sqrt(3)*sqrt(229) + 1/2)^(2/3) +
4)/(1/18*I*sqrt(3)*sqrt(229) + 1/2)^(1/3))*sqrt(3) -
1/2*sqrt(-(1/18*I*sqrt(3)*sqrt(229) + 1/2)^(1/3) +
2*sqrt(3)/sqrt((3*(1/18*I*sqrt(3)*sqrt(229) + 1/2)^(2/3) +
4)/(1/18*I*sqrt(3)*sqrt(229) + 1/2)^(1/3)) -
4/3/(1/18*I*sqrt(3)*sqrt(229) + 1/2)^(1/3)), x ==
-1/6*sqrt((3*(1/18*I*sqrt(3)*sqrt(229) + 1/2)^(2/3) +
4)/(1/18*I*sqrt(3)*sqrt(229) + 1/2)^(1/3))*sqrt(3) +
1/2*sqrt(-(1/18*I*sqrt(3)*sqrt(229) + 1/2)^(1/3) +
2*sqrt(3)/sqrt((3*(1/18*I*sqrt(3)*sqrt(229) + 1/2)^(2/3) +
4)/(1/18*I*sqrt(3)*sqrt(229) + 1/2)^(1/3)) -
4/3/(1/18*I*sqrt(3)*sqrt(229) + 1/2)^(1/3)), x ==
1/6*sqrt((3*(1/18*I*sqrt(3)*sqrt(229) + 1/2)^(2/3) +
4)/(1/18*I*sqrt(3)*sqrt(229) + 1/2)^(1/3))*sqrt(3) -
1/2*sqrt(-(1/18*I*sqrt(3)*sqrt(229) + 1/2)^(1/3) -
2*sqrt(3)/sqrt((3*(1/18*I*sqrt(3)*sqrt(229) + 1/2)^(2/3) +
4)/(1/18*I*sqrt(3)*sqrt(229) + 1/2)^(1/3)) -
4/3/(1/18*I*sqrt(3)*sqrt(229) + 1/2)^(1/3)), x ==
1/6*sqrt((3*(1/18*I*sqrt(3)*sqrt(229) + 1/2)^(2/3) +
4)/(1/18*I*sqrt(3)*sqrt(229) + 1/2)^(1/3))*sqrt(3) +
1/2*sqrt(-(1/18*I*sqrt(3)*sqrt(229) + 1/2)^(1/3) -
2*sqrt(3)/sqrt((3*(1/18*I*sqrt(3)*sqrt(229) + 1/2)^(2/3) +
4)/(1/18*I*sqrt(3)*sqrt(229) + 1/2)^(1/3)) -
4/3/(1/18*I*sqrt(3)*sqrt(229) + 1/2)^(1/3))]
[k.rhs().n() for k in s] 
       
[-0.727136084491197 + 0.430014288329716*I, -0.727136084491197 -
0.430014288329716*I, 0.727136084491197 + 0.934099289460529*I,
0.727136084491197 - 0.934099289460529*I]
solve(sin(x)==cos(x),x) 
       
[sin(x) == cos(x)]
find_root(sin(x)==cos(x),0,50) # sin(x)==sin(2*x) # 
       
29.059732045705587
[find_root(sin(x)==cos(x),i,i+pi) for i in srange(0,30,pi)] 
       
[0.78539816339744839, 3.9269908169872414, 7.0685834705770345,
10.210176124166829, 13.351768777756622, 16.493361431346415,
19.634954084936208, 22.776546738526001, 25.918139392115794,
29.059732045705587]
find_root.func_code 
       
<code object find_root at 0x58bfc60, file
"/opt/sage/local/lib/python2.6/site-packages/sage/numerical/optimize\
.py", line 16>
# Diferenciranje i integriranje 
       
g=x^4 
       
type(g) 
       
<type 'sage.symbolic.expression.Expression'>
diff(g,x) 
       
4*x^3
diff(g,x,2) 
       
12*x^2
integral(g,x) 
       
1/5*x^5
integral(g,x,0,1) 
       
1/5
integral(g,(x,0,1)) 
       
1/5
integral(g,[x,0,1]) 
       
1/5
integral(g,(x,0,1)) 
       
1/5
integral(g,[x,0,1]) 
       
1/5
numerical_integral(g, 0,1) # 
       
(0.19999999999999993, 2.2204460492503123e-15)
numerical_integral(1/x, 0.000000,1) 
       
(69.454624666692752, 13.11226951649312)
# Liste 
       
type(L) 
       
<type 'list'>
L=[1,2,3]; L[2], L[-1], L[-2], L[-3] 
       
(3, 3, 2, 1)
var("p"); a=[1,'2',5,p,1]; b=[4,7] 
       
p
a+2*b 
       
[1, '2', 5, p, 1, 4, 7, 4, 7]
union(a) 
       
[p, 1, '2', 5]
union(a,b) 
       
[1, 4, 5, 7, p, '2']
# a. + <TAB> # 
       
a.count(1) 
       
2
len(a) 
       
5
s=[[1,2,3], [4,5,6,7]] 
       
type(s) 
       
<type 'list'>
s[1][3]; s[1] 
       
7
[4, 5, 6, 7]
[range(1,i) for i in range(2,9)] 
       
[[1], [1, 2], [1, 2, 3], [1, 2, 3, 4], [1, 2, 3, 4, 5], [1, 2, 3, 4,
5, 6], [1, 2, 3, 4, 5, 6, 7]]
list_plot([[i,primes_first_n(i)[-1]/i] for i in range(1,100)]) 
       
# Vektori i matrice 
       
r=vector([1, 2, 3]); v=vector([0,-1,3]); type(r) 
       
<type
'sage.modules.vector_integer_dense.Vector_integer_dense'>
r.degree() 
       
3
r.row() # r.column, r.degree() 
       
[1 2 3]
r+2*v 
       
(1, 0, 9)
A=Matrix([[1,2],[0,3]]); type(A) 
       
<type 'sage.matrix.matrix_integer_dense.Matrix_integer_dense'>
A.columns() 
       
[(1, 0), (2, 3)]
x=vector([1,2]); A*x 
       
(5, 6)
x*A 
       
(1, 8)
kernel(A) 
       
Free module of degree 2 and rank 0 over Integer Ring
Echelon basis matrix:
[]
identity_matrix(RR,3) # (3,3), (RR,3) 
       
[ 1.00000000000000 0.000000000000000 0.000000000000000]
[0.000000000000000  1.00000000000000 0.000000000000000]
[0.000000000000000 0.000000000000000  1.00000000000000]