CoCalc Shared FilesPromenne.sagewsOpen in CoCalc with one click!
Author: Roman Plch
Views : 57
Description: Proměnné a jejich vyhodnocování v programu Sage
reset() #Resetuje všechny proměnné.
%typeset_mode True
a,b,c=var('a,b,c')
solve(a*x^2+b*x+c,x)
[x=b+b24ac2a\displaystyle x = -\frac{b + \sqrt{b^{2} - 4 \, a c}}{2 \, a}, x=bb24ac2a\displaystyle x = -\frac{b - \sqrt{b^{2} - 4 \, a c}}{2 \, a}]
pol=9*x^3-37*x^2+47*x-19;pol
9x337x2+47x19\displaystyle 9 \, x^{3} - 37 \, x^{2} + 47 \, x - 19
pol.roots()
[(199\displaystyle \frac{19}{9}, 1\displaystyle 1), (1\displaystyle 1, 2\displaystyle 2)]
pol.subs(x=19/9)
0\displaystyle 0
x;pol
x\displaystyle x
9x337x2+47x19\displaystyle 9 \, x^{3} - 37 \, x^{2} + 47 \, x - 19
x=19/9;x
199\displaystyle \frac{19}{9}
pol
9x337x2+47x19\displaystyle 9 \, x^{3} - 37 \, x^{2} + 47 \, x - 19
pol(x=19/9)
0\displaystyle 0
x;'x'
199\displaystyle \frac{19}{9}
x
x=x+1;x
x+2\displaystyle x + 2
restore('x');x
x\displaystyle x
'p+q-i-p+3*q'
p+q-i-p+3*q
reset()
var('a,b,c')
(a\displaystyle a, b\displaystyle b, c\displaystyle c)
a=b;b=c;c=3; print a,b,c
b c 3
a
b\displaystyle b
eval(str(a)); print a
c\displaystyle c
b

Záleží na pořadí příkazů....

var('a,b,c')
(a\displaystyle a, b\displaystyle b, c\displaystyle c)
c=3;b=c;a=b; print a,b,c
3 3 3
reset()
var('a,b,c')
(a\displaystyle a, b\displaystyle b, c\displaystyle c)
c=3;b='c';a='b'; print a, b, c
b c 3
P.<x> = PolynomialRing(QQ)
f=x^3+x+1;g=x^2+x+1
f.quo_rem(g)
Error in lines 1-1 Traceback (most recent call last): File "/cocalc/lib/python2.7/site-packages/smc_sagews/sage_server.py", line 1234, in execute flags=compile_flags), namespace, locals) File "", line 1, in <module> NameError: name 'f' is not defined
k, i = var('k, i')
i=2;i
2\displaystyle 2
sum(i, 'i',1,5)
10\displaystyle 10
sum('i','i',1,5)
15\displaystyle 15

Jména proměnných

Proměnné, kterým nebyla přiřazena hodnota, musí deklarovat příkazem var. Proměnné, kterým byla přiřazena hodnota, nazýváme objekty a nemusíme je předem deklarovat.
x=var('x')
x.is_real()
False\displaystyle \mathrm{False}
x=var('x', domain='real')
x.is_real()
True\displaystyle \mathrm{True}
'Odpoved:'
Odpoved:
type(pi)
<type 'sage.symbolic.expression.Expression'>
pi=3.14
type(pi)
<type 'sage.rings.real_mpfr.RealLiteral'>
restore('pi')
type(pi)
<type 'sage.symbolic.expression.Expression'>
reset()
var('m,n');simplify((-1)^(m+n))
(m\displaystyle m, n\displaystyle n)
(1)m+n\displaystyle \left(-1\right)^{m + n}
assume(m,'odd');assume(n,'odd')
simplify((-1)^(m+n))
1\displaystyle 1
assumptions()
m is odd n is odd
[]
assume(m>0)
assumptions()
m is odd n is odd
[m>0\displaystyle m > 0]
forget()
assumptions()
[]
expr=sqrt(x^2)
simplify(expr)
x2\displaystyle \sqrt{x^{2}}
assume(x>0);simplify(expr)
x\displaystyle x
forget();assume(x<0);simplify(expr);
x\displaystyle -x
x.is_real()
True\displaystyle \mathrm{True}
forget()
x.is_real()
False\displaystyle \mathrm{False}
maxima('features')
[integer,noninteger,even,odd,rational,irrational,real,imaginary,complex,analytic,increasing,decreasing,oddfun,evenfun,posfun,constant,commutative,lassociative,rassociative,symmetric,antisymmetric,integervalued]\displaystyle \left[ {\it integer} , {\it noninteger} , {\it even} , {\it odd} , {\it rational} , {\it irrational} , {\it real} , {\it imaginary} , {\it complex} , {\it analytic} , {\it increasing} , {\it decreasing} , {\it oddfun} , {\it evenfun} , {\it posfun} , {\it constant} , {\it commutative} , {\it lassociative} , {\it rassociative} , {\it symmetric} , {\it antisymmetric} , {\it integervalued} \right]
assume(x>0)
x.is_positive()
True\displaystyle \mathrm{True}
assumptions()
[x>0\displaystyle x > 0]
a,b,m,n=var('a,b,m,n')
assume(n+1>0,m+1>0);
integrate(a*x^n+b*x^m, x);
bxm+1m+1+axn+1n+1\displaystyle \frac{b x^{m + 1}}{m + 1} + \frac{a x^{n + 1}}{n + 1}
forget()
type(5.0)
<type 'sage.rings.real_mpfr.RealLiteral'>
type(1)
<type 'sage.rings.integer.Integer'>
type(1/2)
<type 'sage.rings.rational.Rational'>
(5.0).is_real()
True\displaystyle \mathrm{True}
1.is_integer()
True\displaystyle \mathrm{True}
from sage.rings.rational import is_Rational
is_Rational(1/2); 1/2 in QQ
True\displaystyle \mathrm{True}
True\displaystyle \mathrm{True}
(1+2*I) in CC
True\displaystyle \mathrm{True}
0.75.exact_rational()
34\displaystyle \frac{3}{4}