CoCalc Public FilesUvod.sagewsOpen with one click!
Author: Roman Plch
Views : 139
Description: M2142 - zápisník pro první přednášku
Compute Environment: Ubuntu 20.04 (Default)
1+1
2
%typeset_mode True
1+1 #Příkaz provedeme klávesou Enter, odřádkování kombinací kláves Shift+Enter, nutno nastavit "Sage Worksheet evaluate key" na Enter
2\displaystyle 2
1+1;2+2 #Více příkazů na jednom řádku oddělujeme středníkem (;)
2 4
var('y')
y\displaystyle y
((3*x^2+5*x*y-2*y^2)*(x-y)^3)^2
(3x2+5xy2y2)2(xy)6\displaystyle {\left(3 \, x^{2} + 5 \, x y - 2 \, y^{2}\right)}^{2} {\left(x - y\right)}^{6}
expand(_)
9x1024x9y32x8y2+172x7y3146x6y4188x5y5+484x4y6428x3y7+193x2y844xy9+4y10\displaystyle 9 \, x^{10} - 24 \, x^{9} y - 32 \, x^{8} y^{2} + 172 \, x^{7} y^{3} - 146 \, x^{6} y^{4} - 188 \, x^{5} y^{5} + 484 \, x^{4} y^{6} - 428 \, x^{3} y^{7} + 193 \, x^{2} y^{8} - 44 \, x y^{9} + 4 \, y^{10}
((x^2-1)/(3*x^3-11*x^2+13*x-5)).
43x51x1\displaystyle \frac{4}{3 \, x - 5} - \frac{1}{x - 1}
integrate(x^2*sin(x),x)
(x22)cos(x)+2xsin(x)\displaystyle -{\left(x^{2} - 2\right)} \cos\left(x\right) + 2 \, x \sin\left(x\right)
Komentář
plot(x * sin(x), (x, -2, 10))
plot(sin(x), (x,-pi,pi))
32*12^4
663552
factorial(20)-factorial(12)
2432902007697638400
factor(_) #_ je odkaz na předcházející výstup
2^10 * 3^5 * 5^2 * 7 * 11^3 * 41976119
expand(_)
2432902007697638400
%typeset_mode True (2^30/3^20)*sqrt(2) #Sage pracuje v přesné aritmetice.
107374182434867844012\displaystyle \frac{1073741824}{3486784401} \, \sqrt{2}
n(_) #Aproximaci získáme příkazem n().
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(_,digits=30)
1.27142289724276359903349287003\displaystyle 1.27142289724276359903349287003
Aproximace π\pi.
n(pi)
3.14159265358979\displaystyle 3.14159265358979
pi.n() #Druhý způsob zadání.
3.14159265358979\displaystyle 3.14159265358979
pi.n(digits=30)
3.14159265358979323846264338328\displaystyle 3.14159265358979323846264338328
((3+5*I)*(7+4*I)); #Komplexní jednotku zadáváme pomocí I.
47i+1\displaystyle 47 i + 1
%typeset_mode True
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}
expand(_)
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}
factor(_)
(x+y)3(xy)2\displaystyle {\left(x + y\right)}^{3} {\left(x - y\right)}^{2}
_.show() #Pomocí show formátujeme výstup v LaTeXu.
(x+y)3(xy)2\displaystyle {\left(x + y\right)}^{3} {\left(x - y\right)}^{2}
(x^2-9).factor()
(x+3)(x3)\displaystyle {\left(x + 3\right)} {\left(x - 3\right)}
help(integrate)
Help on function integral in module sage.misc.functional: integral(x, *args, **kwds) Return an indefinite or definite integral of an object ``x``. First call ``x.integral()`` and if that fails make an object and integrate it using Maxima, maple, etc, as specified by algorithm. For symbolic expression calls :func:`sage.calculus.calculus.integral` - see this function for available options. EXAMPLES:: sage: f = cyclotomic_polynomial(10) sage: integral(f) 1/5*x^5 - 1/4*x^4 + 1/3*x^3 - 1/2*x^2 + x :: sage: integral(sin(x),x) -cos(x) :: sage: y = var('y') sage: integral(sin(x),y) y*sin(x) :: sage: integral(sin(x), x, 0, pi/2) 1 sage: sin(x).integral(x, 0,pi/2) 1 sage: integral(exp(-x), (x, 1, oo)) e^(-1) Numerical approximation:: sage: h = integral(tan(x)/x, (x, 1, pi/3)); h integrate(tan(x)/x, x, 1, 1/3*pi) sage: h.n() 0.07571599101... Specific algorithm can be used for integration:: sage: integral(sin(x)^2, x, algorithm='maxima') 1/2*x - 1/4*sin(2*x) sage: integral(sin(x)^2, x, algorithm='sympy') -1/2*cos(x)*sin(x) + 1/2*x TESTS: A symbolic integral from :trac:`11445` that was incorrect in earlier versions of Maxima:: sage: f = abs(x - 1) + abs(x + 1) - 2*abs(x) sage: integrate(f, (x, -Infinity, Infinity)) 2 Another symbolic integral, from :trac:`11238`, that used to return zero incorrectly; with Maxima 5.26.0 one gets ``1/2*sqrt(pi)*e^(1/4)``, whereas with 5.29.1, and even more so with 5.33.0, the expression is less pleasant, but still has the same value. Unfortunately, the computation takes a very long time with the default settings, so we temporarily use the Maxima setting ``domain: real``:: sage: sage.calculus.calculus.maxima('domain: real') real sage: f = exp(-x) * sinh(sqrt(x)) sage: t = integrate(f, x, 0, Infinity); t # long time 1/4*sqrt(pi)*(erf(1) - 1)*e^(1/4) - 1/4*(sqrt(pi)*(erf(1) - 1) - sqrt(pi) + 2*e^(-1) - 2)*e^(1/4) + 1/4*sqrt(pi)*e^(1/4) - 1/2*e^(1/4) + 1/2*e^(-3/4) sage: t.canonicalize_radical() # long time 1/2*sqrt(pi)*e^(1/4) sage: sage.calculus.calculus.maxima('domain: complex') complex An integral which used to return -1 before maxima 5.28. See :trac:`12842`:: sage: f = e^(-2*x)/sqrt(1-e^(-2*x)) sage: integrate(f, x, 0, infinity) 1 This integral would cause a stack overflow in earlier versions of Maxima, crashing sage. See :trac:`12377`. We don't care about the result here, just that the computation completes successfully:: sage: y = (x^2)*exp(x) / (1 + exp(x))^2 sage: _ = integrate(y, x, -1000, 1000) When SymPy cannot solve an integral it gives it back, so we must be able to convert SymPy's ``Integral`` (:trac:`14723`):: sage: x, y, z = var('x,y,z') sage: f = function('f') sage: integrate(f(x), x, algorithm='sympy') integrate(f(x), x) sage: integrate(f(x), x, 0, 1,algorithm='sympy') integrate(f(x), x, 0, 1) sage: integrate(integrate(integrate(f(x,y,z), x, algorithm='sympy'), y, algorithm='sympy'), z, algorithm='sympy') integrate(integrate(integrate(f(x, y, z), x), y), z) sage: integrate(sin(x)*tan(x)/(1-cos(x)), x, algorithm='sympy') -integrate(sin(x)*tan(x)/(cos(x) - 1), x) sage: _ = var('a,b,x') sage: integrate(sin(x)*tan(x)/(1-cos(x)), x, a, b, algorithm='sympy') -integrate(sin(x)*tan(x)/(cos(x) - 1), x, a, b) sage: import sympy sage: x, y, z = sympy.symbols('x y z') sage: f = sympy.Function('f') sage: SR(sympy.Integral(f(x,y,z), x, y, z)) integrate(integrate(integrate(f(x, y, z), x), y), z)
integrate?
File: /ext/sage/sage-9.2/local/lib/python3.8/site-packages/sage/misc/functional.py Signature : integrate(x, *args, **kwds) Docstring : Return an indefinite or definite integral of an object "x". First call "x.integral()" and if that fails make an object and integrate it using Maxima, maple, etc, as specified by algorithm. For symbolic expression calls "sage.calculus.calculus.integral()" - see this function for available options. EXAMPLES: sage: f = cyclotomic_polynomial(10) sage: integral(f) 1/5*x^5 - 1/4*x^4 + 1/3*x^3 - 1/2*x^2 + x sage: integral(sin(x),x) -cos(x) sage: y = var('y') sage: integral(sin(x),y) y*sin(x) sage: integral(sin(x), x, 0, pi/2) 1 sage: sin(x).integral(x, 0,pi/2) 1 sage: integral(exp(-x), (x, 1, oo)) e^(-1) Numerical approximation: sage: h = integral(tan(x)/x, (x, 1, pi/3)); h integrate(tan(x)/x, x, 1, 1/3*pi) sage: h.n() 0.07571599101... Specific algorithm can be used for integration: sage: integral(sin(x)^2, x, algorithm='maxima') 1/2*x - 1/4*sin(2*x) sage: integral(sin(x)^2, x, algorithm='sympy') -1/2*cos(x)*sin(x) + 1/2*x
integrate??
File: /ext/sage/sage-9.2/local/lib/python3.8/site-packages/sage/misc/functional.py Source: def integral(x, *args, **kwds): """ Return an indefinite or definite integral of an object ``x``. First call ``x.integral()`` and if that fails make an object and integrate it using Maxima, maple, etc, as specified by algorithm. For symbolic expression calls :func:`sage.calculus.calculus.integral` - see this function for available options. EXAMPLES:: sage: f = cyclotomic_polynomial(10) sage: integral(f) 1/5*x^5 - 1/4*x^4 + 1/3*x^3 - 1/2*x^2 + x :: sage: integral(sin(x),x) -cos(x) :: sage: y = var('y') sage: integral(sin(x),y) y*sin(x) :: sage: integral(sin(x), x, 0, pi/2) 1 sage: sin(x).integral(x, 0,pi/2) 1 sage: integral(exp(-x), (x, 1, oo)) e^(-1) Numerical approximation:: sage: h = integral(tan(x)/x, (x, 1, pi/3)); h integrate(tan(x)/x, x, 1, 1/3*pi) sage: h.n() 0.07571599101... Specific algorithm can be used for integration:: sage: integral(sin(x)^2, x, algorithm='maxima') 1/2*x - 1/4*sin(2*x) sage: integral(sin(x)^2, x, algorithm='sympy') -1/2*cos(x)*sin(x) + 1/2*x TESTS: A symbolic integral from :trac:`11445` that was incorrect in earlier versions of Maxima:: sage: f = abs(x - 1) + abs(x + 1) - 2*abs(x) sage: integrate(f, (x, -Infinity, Infinity)) 2 Another symbolic integral, from :trac:`11238`, that used to return zero incorrectly; with Maxima 5.26.0 one gets ``1/2*sqrt(pi)*e^(1/4)``, whereas with 5.29.1, and even more so with 5.33.0, the expression is less pleasant, but still has the same value. Unfortunately, the computation takes a very long time with the default settings, so we temporarily use the Maxima setting ``domain: real``:: sage: sage.calculus.calculus.maxima('domain: real') real sage: f = exp(-x) * sinh(sqrt(x)) sage: t = integrate(f, x, 0, Infinity); t # long time 1/4*sqrt(pi)*(erf(1) - 1)*e^(1/4) - 1/4*(sqrt(pi)*(erf(1) - 1) - sqrt(pi) + 2*e^(-1) - 2)*e^(1/4) + 1/4*sqrt(pi)*e^(1/4) - 1/2*e^(1/4) + 1/2*e^(-3/4) sage: t.canonicalize_radical() # long time 1/2*sqrt(pi)*e^(1/4) sage: sage.calculus.calculus.maxima('domain: complex') complex An integral which used to return -1 before maxima 5.28. See :trac:`12842`:: sage: f = e^(-2*x)/sqrt(1-e^(-2*x)) sage: integrate(f, x, 0, infinity) 1 This integral would cause a stack overflow in earlier versions of Maxima, crashing sage. See :trac:`12377`. We don't care about the result here, just that the computation completes successfully:: sage: y = (x^2)*exp(x) / (1 + exp(x))^2 sage: _ = integrate(y, x, -1000, 1000) When SymPy cannot solve an integral it gives it back, so we must be able to convert SymPy's ``Integral`` (:trac:`14723`):: sage: x, y, z = var('x,y,z') sage: f = function('f') sage: integrate(f(x), x, algorithm='sympy') integrate(f(x), x) sage: integrate(f(x), x, 0, 1,algorithm='sympy') integrate(f(x), x, 0, 1) sage: integrate(integrate(integrate(f(x,y,z), x, algorithm='sympy'), y, algorithm='sympy'), z, algorithm='sympy') integrate(integrate(integrate(f(x, y, z), x), y), z) sage: integrate(sin(x)*tan(x)/(1-cos(x)), x, algorithm='sympy') -integrate(sin(x)*tan(x)/(cos(x) - 1), x) sage: _ = var('a,b,x') sage: integrate(sin(x)*tan(x)/(1-cos(x)), x, a, b, algorithm='sympy') -integrate(sin(x)*tan(x)/(cos(x) - 1), x, a, b) sage: import sympy sage: x, y, z = sympy.symbols('x y z') sage: f = sympy.Function('f') sage: SR(sympy.Integral(f(x,y,z), x, y, z)) integrate(integrate(integrate(f(x, y, z), x), y), z) """ if hasattr(x, 'integral'): return x.integral(*args, **kwds) else: from sage.symbolic.ring import SR return SR(x).integral(*args, **kwds)
integrate

Doplňování jmen

Začněte psát příkaz a stiskněte Klávesu Tab
%var x, theta
%typeset_mode True
diff(1 + x + x^2, x)
2x+1\displaystyle 2 \, x + 1
(1+x+x^2).diff()
2x+1\displaystyle 2 \, x + 1
matrix(3, 3, [1,pi,3, e,5,6, 1,2,3]).
6π3(π2)e12\displaystyle 6 \, \pi - 3 \, {\left(\pi - 2\right)} e - 12
%var x, theta
plot(x * sin(x), (x, -2, 10))
%var x, theta