| Hosted by CoCalc | Download
1+1;
2
%latex Komentar
plot(x * sin(x), (x, -2, 10))
%typeset_mode True
%typeset_mode True
Komentář x2+y2x^2+y^2.
1+1;#komentar
2\displaystyle 2
#Příkaz provedeme klávesou Shift+Enter, odřádkování Enter - změnu provedeme v nastavení účtu
1+1;2+2 #Více příkazů na jednom řádku oddělujeme středníkem (;)
2\displaystyle 2
4\displaystyle 4
factor?
File: /ext/sage/10.1/src/sage/arith/misc.py Docstring : Return the factorization of "n". The result depends on the type of "n". If "n" is an integer, returns the factorization as an object of type "Factorization". If "n" is not an integer, "n.factor(proof=proof, **kwds)" gets called. See "n.factor??" for more documentation in this case. Warning: This means that applying "factor()" to an integer result of a symbolic computation will not factor the integer, because it is considered as an element of a larger symbolic ring.EXAMPLES: sage: f(n) = n^2 sage: is_prime(f(3)) False sage: factor(f(3)) 9 INPUT: * "n" -- a nonzero integer * "proof" -- bool or "None" (default: "None") * "int_" -- bool (default: "False") whether to return answers as Python ints * "algorithm" -- string * "'pari'" -- (default) use the PARI c library * "'kash'" -- use KASH computer algebra system (requires that kash be installed) * "'magma'" -- use Magma (requires magma be installed) * "verbose" -- integer (default: 0); PARI's debug variable is set to this; e.g., set to 4 or 8 to see lots of output during factorization. OUTPUT: * factorization of n The qsieve and ecm commands give access to highly optimized implementations of algorithms for doing certain integer factorization problems. These implementations are not used by the generic "factor()" command, which currently just calls PARI (note that PARI also implements sieve and ecm algorithms, but they are not as optimized). Thus you might consider using them instead for certain numbers. The factorization returned is an element of the class "Factorization"; use "Factorization??" to see more details, and examples below for usage. A "Factorization" contains both the unit factor (+1 or -1) and a sorted list of "(prime, exponent)" pairs. The factorization displays in pretty-print format but it is easy to obtain access to the "(prime, exponent)" pairs and the unit, to recover the number from its factorization, and even to multiply two factorizations. See examples below. EXAMPLES: sage: factor(500) 2^2 * 5^3 sage: factor(-20) -1 * 2^2 * 5 sage: f=factor(-20) sage: list(f) [(2, 2), (5, 1)] sage: f.unit() -1 sage: f.value() -20 sage: factor(-next_prime(10^2) * next_prime(10^7)) -1 * 101 * 10000019 sage: factor(293292629867846432923017396246429, algorithm='flint') 3 * 4852301647696687 * 20148007492971089 sage: factor(-500, algorithm='kash') # optional - kash -1 * 2^2 * 5^3 sage: factor(-500, algorithm='magma') # optional - magma -1 * 2^2 * 5^3 sage: factor(0) Traceback (most recent call last): ... ArithmeticError: factorization of 0 is not defined sage: factor(1) 1 sage: factor(-1) -1 sage: factor(2^(2^7) + 1) 59649589127497217 * 5704689200685129054721 Sage calls PARI's https://pari.math.u-bordeaux.fr/dochtml/help/factor, which has "proof=False" by default. Sage has a global proof flag, set to "True" by default (see "sage.structure.proof.proof", or use "proof.[tab]"). To override the default, call this function with "proof=False". sage: factor(3^89 - 1, proof=False) 2 * 179 * 1611479891519807 * 5042939439565996049162197 sage: factor(2^197 + 1) # long time 3 * 197002597249 * 1348959352853811313 * 251951573867253012259144010843 Any object which has a factor method can be factored like this: sage: K.<i> = QuadraticField(-1) sage: factor(122 - 454*i) (-i) * (-i - 2)^3 * (i + 1)^3 * (-2*i + 3) * (i + 4) To access the data in a factorization: sage: f = factor(420); f 2^2 * 3 * 5 * 7 sage: [x for x in f] [(2, 2), (3, 1), (5, 1), (7, 1)] sage: [p for p,e in f] [2, 3, 5, 7] sage: [e for p,e in f] [2, 1, 1, 1] sage: [p^e for p,e in f] [4, 3, 5, 7] We can factor Python, numpy and gmpy2 numbers: sage: factor(math.pi) 3.141592653589793 sage: import numpy sage: factor(numpy.int8(30)) 2 * 3 * 5 sage: import gmpy2 sage: factor(gmpy2.mpz(30)) 2 * 3 * 5
help(factor) #Nápověda
Help on function factor in module sage.arith.misc: factor(n, proof=None, int_=False, algorithm='pari', verbose=0, **kwds) Return the factorization of ``n``. The result depends on the type of ``n``. If ``n`` is an integer, returns the factorization as an object of type :class:`Factorization`. If ``n`` is not an integer, ``n.factor(proof=proof, **kwds)`` gets called. See ``n.factor??`` for more documentation in this case. .. warning:: This means that applying :func:`factor` to an integer result of a symbolic computation will not factor the integer, because it is considered as an element of a larger symbolic ring. EXAMPLES:: sage: f(n) = n^2 # optional - sage.symbolic sage: is_prime(f(3)) # optional - sage.symbolic False sage: factor(f(3)) # optional - sage.symbolic 9 INPUT: - ``n`` -- a nonzero integer - ``proof`` -- bool or ``None`` (default: ``None``) - ``int_`` -- bool (default: ``False``) whether to return answers as Python ints - ``algorithm`` -- string - ``'pari'`` -- (default) use the PARI c library - ``'kash'`` -- use KASH computer algebra system (requires that kash be installed) - ``'magma'`` -- use Magma (requires magma be installed) - ``verbose`` -- integer (default: 0); PARI's debug variable is set to this; e.g., set to 4 or 8 to see lots of output during factorization. OUTPUT: - factorization of `n` The qsieve and ecm commands give access to highly optimized implementations of algorithms for doing certain integer factorization problems. These implementations are not used by the generic :func:`factor` command, which currently just calls PARI (note that PARI also implements sieve and ecm algorithms, but they are not as optimized). Thus you might consider using them instead for certain numbers. The factorization returned is an element of the class :class:`~sage.structure.factorization.Factorization`; use ``Factorization??`` to see more details, and examples below for usage. A :class:`~sage.structure.factorization.Factorization` contains both the unit factor (`+1` or `-1`) and a sorted list of ``(prime, exponent)`` pairs. The factorization displays in pretty-print format but it is easy to obtain access to the ``(prime, exponent)`` pairs and the unit, to recover the number from its factorization, and even to multiply two factorizations. See examples below. EXAMPLES:: sage: factor(500) 2^2 * 5^3 sage: factor(-20) -1 * 2^2 * 5 sage: f=factor(-20) sage: list(f) [(2, 2), (5, 1)] sage: f.unit() -1 sage: f.value() -20 sage: factor(-next_prime(10^2) * next_prime(10^7)) # optional - sage.libs.pari -1 * 101 * 10000019 :: sage: factor(293292629867846432923017396246429, algorithm='flint') # optional - sage.libs.flint 3 * 4852301647696687 * 20148007492971089 :: sage: factor(-500, algorithm='kash') # optional - kash -1 * 2^2 * 5^3 :: sage: factor(-500, algorithm='magma') # optional - magma -1 * 2^2 * 5^3 :: sage: factor(0) Traceback (most recent call last): ... ArithmeticError: factorization of 0 is not defined sage: factor(1) 1 sage: factor(-1) -1 sage: factor(2^(2^7) + 1) # optional - sage.libs.pari 59649589127497217 * 5704689200685129054721 Sage calls PARI's :pari:`factor`, which has ``proof=False`` by default. Sage has a global proof flag, set to ``True`` by default (see :mod:`sage.structure.proof.proof`, or use ``proof.[tab]``). To override the default, call this function with ``proof=False``. :: sage: factor(3^89 - 1, proof=False) # optional - sage.libs.pari 2 * 179 * 1611479891519807 * 5042939439565996049162197 :: sage: factor(2^197 + 1) # long time (2s) # optional - sage.libs.pari 3 * 197002597249 * 1348959352853811313 * 251951573867253012259144010843 Any object which has a factor method can be factored like this:: sage: K.<i> = QuadraticField(-1) # optional - sage.rings.number_field sage: factor(122 - 454*i) # optional - sage.rings.number_field (-i) * (-i - 2)^3 * (i + 1)^3 * (-2*i + 3) * (i + 4) To access the data in a factorization:: sage: f = factor(420); f # optional - sage.libs.pari 2^2 * 3 * 5 * 7 sage: [x for x in f] # optional - sage.libs.pari [(2, 2), (3, 1), (5, 1), (7, 1)] sage: [p for p,e in f] # optional - sage.libs.pari [2, 3, 5, 7] sage: [e for p,e in f] # optional - sage.libs.pari [2, 1, 1, 1] sage: [p^e for p,e in f] # optional - sage.libs.pari [4, 3, 5, 7] We can factor Python, numpy and gmpy2 numbers:: sage: factor(math.pi) 3.141592653589793 sage: import numpy # optional - numpy sage: factor(numpy.int8(30)) # optional - numpy sage.libs.pari 2 * 3 * 5 sage: import gmpy2 sage: factor(gmpy2.mpz(30)) # optional - sage.libs.pari 2 * 3 * 5 TESTS:: sage: factor(Mod(4, 100)) Traceback (most recent call last): ... TypeError: unable to factor 4 sage: factor("xyz") Traceback (most recent call last): ... TypeError: unable to factor 'xyz'

Sage má automatické doplňování příkazů. Zkuste napsat do následujícího políčka text fac a stisknout tabelátor. Ukážou se všechny příkazy začínající těmito slovy. Vyberte si kterýkoliv z nich, připište za něj otazník  a stiskněte opět tabelátor. Objeví se nápověda k tomutu příkazu.

v1=factorial(20)-factorial(12);v1
2432902007697638400\displaystyle 2432902007697638400
factor(v1);
2103552711341976119\displaystyle 2^{10} \cdot 3^{5} \cdot 5^{2} \cdot 7 \cdot 11^{3} \cdot 41976119
v1.next_prime()
2432902007697638557\displaystyle 2432902007697638557
(2^30/3^20)*sqrt(2) #Sage pracuje v přesné aritmetice.
107374182434867844012\displaystyle \frac{1073741824}{3486784401} \, \sqrt{2}
(2^30/3^20)*sqrt(2).n()
0.435501618497698\displaystyle 0.435501618497698
N((2^30/3^20)*sqrt(2))
0.435501618497698\displaystyle 0.435501618497698
var('i') #Narozdíl od Maplu a Maximy je třeba proměnné (kromě proměnné x) předem deklarovat.
i\displaystyle i
sum((1+i)/(1+i^4), i,1,20)
2753108915513951266418473494479966526667515770634998143458420014321653762264974190884124027285387789492160976952723410943046016049\displaystyle \frac{27531089155139512664184734944799665266675157706349981434584200143}{21653762264974190884124027285387789492160976952723410943046016049}
N(sum((1+i)/(1+i^4), i,1,20), digits=30)
1.27142289724276359903349287003\displaystyle 1.27142289724276359903349287003
sum((1+i)/(1+i^4), i,1,20).n(digits=30)
1.27142289724276359903349287003\displaystyle 1.27142289724276359903349287003
var('j')
j\displaystyle j
sum((1+j)/(1+j^4), j,1,20)
2753108915513951266418473494479966526667515770634998143458420014321653762264974190884124027285387789492160976952723410943046016049\displaystyle \frac{27531089155139512664184734944799665266675157706349981434584200143}{21653762264974190884124027285387789492160976952723410943046016049}
N(pi);n(pi)
3.14159265358979\displaystyle 3.14159265358979
3.14159265358979\displaystyle 3.14159265358979
((3+5*I)*(7+4*I)); #Komplexní jednotku zadáváme pomocí I.
47i+1\displaystyle 47 i + 1
var('y')
y\displaystyle y
(x+y)^3*(x-y)^2
(x+y)3(xy)2\displaystyle {\left(x + y\right)}^{3} {\left(x - y\right)}^{2}
((x+y)^3*(x-y)^2).expand() #roznásobení závorek
x5+x4y2x3y22x2y3+xy4+y5\displaystyle x^{5} + x^{4} y - 2 \, x^{3} y^{2} - 2 \, x^{2} y^{3} + x y^{4} + y^{5}
((x+y)^3*(x-y)^2).expand().factor() #rozklad na součin
(x+y)3(xy)2\displaystyle {\left(x + y\right)}^{3} {\left(x - y\right)}^{2}
simplify(x/2+x/5) #zjednoduseni vyrazu
710x\displaystyle \frac{7}{10} \, x

Uložení výrazu do proměnné.

f=(x^3-x)/(x^4-1);f
x3xx41\displaystyle \frac{x^{3} - x}{x^{4} - 1}
f.simplify_full()
xx2+1\displaystyle \frac{x}{x^{2} + 1}
vyraz=sin(x)^2+cos(x)^2;vyraz.simplify_trig()
1\displaystyle 1
(cos(x)^2).trig_reduce()
12cos(2x)+12\displaystyle \frac{1}{2} \, \cos\left(2 \, x\right) + \frac{1}{2}

Jedno znaméno = se v programu Sage používá pro přiřazení hodnoty do proměnné. Pro rovnice se používají dvě rovnítka za sebou.

%typeset_mode True
x^2-7==0 #rovnice
x27=0\displaystyle x^{2} - 7 = 0
(x^2-7==0).rhs();(x^2-7==0).lhs() #prava a leva strana
0\displaystyle 0
x27\displaystyle x^{2} - 7
solve(x^2-7==0, x)
[x=7\displaystyle x = -\sqrt{7}, x=7\displaystyle x = \sqrt{7}]

Získání všech řešení.

solve(sin(3*x+pi/3)==1/2,x) #neziskame vsechna reseni
[x=118π\displaystyle x = -\frac{1}{18} \, \pi]
solve(sin(3*x+pi/3)==1/2,x,to_poly_solve='force')
[x=16π+23πz1889\displaystyle x = \frac{1}{6} \, \pi + \frac{2}{3} \, \pi z_{1889}, x=118π+23πz1934\displaystyle x = -\frac{1}{18} \, \pi + \frac{2}{3} \, \pi z_{1934}]
%md Text komentáře.

Text komentáře.

eq1=y==3*x+1;eq2=y==x-1;eq1;eq2
y=3x+1\displaystyle y = 3 \, x + 1
y=x1\displaystyle y = x - 1
sol=solve([eq1,eq2],x,y); sol #reseni soustavy rovnic
[[x=(1)\displaystyle x = \left(-1\right), y=(2)\displaystyle y = \left(-2\right)]]

Práce s nn-ticemi

A=solve(x^4-2*x^2==0,x);A
[x=2\displaystyle x = -\sqrt{2}, x=2\displaystyle x = \sqrt{2}, x=0\displaystyle x = 0]
A[0] #prvni prvek (index 0)
x=2\displaystyle x = -\sqrt{2}
A[1]
x=2\displaystyle x = \sqrt{2}

Deklarace funkce

f(x)=x^2
f
x  x2\displaystyle x \ {\mapsto}\ x^{2}
f(4)
16\displaystyle 16
%typeset_mode True f=x^2 #deklarace f jako vyrazu, ne funkce
f
x2\displaystyle x^{2}
f(x=4)
16\displaystyle 16
f.subs(x=4)
16\displaystyle 16
%html Práce s grafikou
Práce s grafikou
plot(ln(x), (x,0,10))
plot(ln(x), (x,0,10)).save('obrazek.pdf')
plot(ln(x), (x,0,10))+text(r'Graf funkce $f(x)=\ln(x)$',(2,2), fontsize=12)
(plot(ln(x), (x,0,10))+text(r"Graf funkce $f(x)=\ln(x)$",(2,2), fontsize=12)).save('obrazek1.pdf')
plot(e^x, (x,-3,5),ymax=100,ymin=0)
plot(tan(x), (x,-3,3), ymax=10, ymin=-10,detect_poles=True)
%html <p>Úskalí</p>

Úskalí

plot(e^x+ln(abs(4-x)), (x,0,5))
plot(e^x+ln(abs(4-x)), (x,3.99,4.01),detect_poles=True)
rov1=sqrt(x-2)==sqrt(2*x-3);rov1
x2=2x3\displaystyle \sqrt{x - 2} = \sqrt{2 \, x - 3}
res1=solve(rov1, x, to_poly_solve='force');res1
[x=1\displaystyle x = 1]
plot(x * sin(x), (x, -2, 10))
p1=plot(sqrt(x-2), (x,2,7));p2=plot(sqrt(2*x-3), (x,1.5,7));p1+p2
rov1.subs(x=(res1[0].rhs()))
i=i\displaystyle i = i
rov2=log(x+4)+log(x-2)==log(x+3);rov2
log(x+4)+log(x2)=log(x+3)\displaystyle \log\left(x + 4\right) + \log\left(x - 2\right) = \log\left(x + 3\right)
res2=solve(rov2,x, to_poly_solve='force');res2
[x=32512\displaystyle x = -\frac{3}{2} \, \sqrt{5} - \frac{1}{2}, x=32512\displaystyle x = \frac{3}{2} \, \sqrt{5} - \frac{1}{2}]
((res2[0])).rhs().n();((res2[1])).rhs().n()
3.85410196624968\displaystyle -3.85410196624968
2.85410196624968\displaystyle 2.85410196624968
p1=plot(log(x+4)+log(x-2), (x,2,4));p2=plot(log(x+3), (x,-3,4));p1+p2
%typeset_mode True
rov4=2*(2^x)^2-7*2^x+3==0; rov4
222x72x+3=0\displaystyle 2 \cdot 2^{2 \, x} - 7 \cdot 2^{x} + 3 = 0
%typeset_mode True solve(2*(2^x)^2-7*2^x+3==0, x, to_poly_solve='force')
[]
plot(2*(2^x)^2-7*2^x+3, (x,-2,2))
solve(2*(y)^2-7*y+3==0, y, to_poly_solve='force')
[y=(12)\displaystyle y = \left(\frac{1}{2}\right), y=3\displaystyle y = 3]
solve(2^x==3, x);solve(2^x==1/2,x)
[x=log(3)log(2)\displaystyle x = \frac{\log\left(3\right)}{\log\left(2\right)}]
[x=(1)\displaystyle x = \left(-1\right)]
(solve(2^x==3, x)[0]).rhs().n()
1.58496250072116\displaystyle 1.58496250072116
find_root(2*(2^x)^2-7*2^x+3==0, 1, 2)
1.5849625007210582\displaystyle 1.5849625007210582
find_root(2*(2^x)^2-7*2^x+3==0,-2,0)
1.0\displaystyle -1.0

Stream plots show several solutions to a differential equation within the defined plot region. These often give a better sense of the flow than a slope field or vector field plot. The following shows a streamline plot for the differential equation dydt=yt\frac{dy}{dt} = y - t and one for the system {dxdt=0.1x0.2xydydt=0.2y+0.1xy\begin{cases} \frac{dx}{dt} &= 0.1 x - 0.2 x y \\ \frac{dy}{dt} &= -0.2 y + 0.1 x y \end{cases}

var('t x y') # streamline plot for a single differential equation streamline_plot(y - t, (t,0,10), (y,0,6)) # streamline plot in the phase plane for a system of two differential equations streamline_plot([0.1*x - 0.2*x*y,-0.2*y+0.1*x*y],(x,0,4),(y,0,2))
(t\displaystyle t, x\displaystyle x, y\displaystyle y)

The following plots a slope field for the differential equation dydt=yt.\frac{dy}{dt} = y - t.

var('t y') plot_slope_field(y - t, (t,0,10), (y,0,6), plot_points=25)
(t\displaystyle t, y\displaystyle y)
plot(x * sin(x), (x, -2, 10))

Compute limlim with SageMath and Maxima. Note, that oo stands for \infty. Use dir='+' or dir='-' for one-sided limits.

See Reference/Limit for more information.

var('x') print(lim((x+1)^(1/x), x = 0)) print(lim(sqrt(x^2+1) - x, x = oo)) print(lim(diff(abs(x),x), x = 0, dir='-'))
x\displaystyle x
e 0 -1