Tutorial
Voici un petit tuto qui contient:
des formules: sin(x2)
des graphiques
le lien vers le site http://www.sagemath.org/
%typeset_mode True
2+3
5
sin(x^2)
sin(x2)
diff(1 + x + x^3, x)
3x2+1
x
x
type(x)
<type 'sage.symbolic.expression.Expression'>
isinstance(2, Expression)
False
SR(2)
2
SR(2).derivative(x)
0
type(x)
<type 'sage.symbolic.expression.Expression'>
print(x.parent())
Symbolic Ring
e^(I*pi)+1
0
e^(i*pi)+1
0
pi
π
pi.numerical_approx(digits=1000)
3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342117067982148086513282306647093844609550582231725359408128481117450284102701938521105559644622948954930381964428810975665933446128475648233786783165271201909145648566923460348610454326648213393607260249141273724587006606315588174881520920962829254091715364367892590360011330530548820466521384146951941511609433057270365759591953092186117381932611793105118548074462379962749567351885752724891227938183011949129833673362440656643086021394946395224737190702179860943702770539217176293176752384674818467669405132000568127145263560827785771342757789609173637178721468440901224953430146549585371050792279689258923542019956112129021960864034418159813629774771309960518707211349999998372978049951059731732816096318595024459455346908302642522308253344685035261931188171010003137838752886587533208381420617177669147303598253490428755468731159562863882353787593751957781857780532171226806613001927876611195909216420199
n(pi)
3.14159265358979
N(pi)
3.14159265358979
a = [1, 3, -5]
a
[1, 3, −5]
a[1]
3
a = RR(pi)
type(a)
<type 'sage.rings.real_mpfr.RealNumber'>
a
3.14159265358979
n(pi, digits=1000)
3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342117067982148086513282306647093844609550582231725359408128481117450284102701938521105559644622948954930381964428810975665933446128475648233786783165271201909145648566923460348610454326648213393607260249141273724587006606315588174881520920962829254091715364367892590360011330530548820466521384146951941511609433057270365759591953092186117381932611793105118548074462379962749567351885752724891227938183011949129833673362440656643086021394946395224737190702179860943702770539217176293176752384674818467669405132000568127145263560827785771342757789609173637178721468440901224953430146549585371050792279689258923542019956112129021960864034418159813629774771309960518707211349999998372978049951059731732816096318595024459455346908302642522308253344685035261931188171010003137838752886587533208381420617177669147303598253490428755468731159562863882353787593751957781857780532171226806613001927876611195909216420199
f = diff(sin(x^2), x)
f
2xcos(x2)
x = 1
f
2xcos(x2)
x
1
f
2xcos(x2)
type(x)
<type 'sage.rings.integer.Integer'>
x = var("x")
x
x
type(x)
<type 'sage.symbolic.expression.Expression'>
f(x) = diff(sin(x^2), x)
f
x ↦ 2xcos(x2)
f(1)
2cos(1)
g(x) = e^(x^2) ; g
x ↦ e(x2)
def G(x, a=0): """ Cette fonction calcule G """ return e^(x^a)
G(x)
e
G(x,43)
e(x43)
diff(G(x,43), x)
43x42e(x43)
G?
File: /projects/d1f616f5-b5fa-499d-aa93-4337149d096f Signature : G(x, a=0) Docstring : Cette fonction calcule G
g
x ↦ e(x2)
integrate(g(x), x)
−21iπerf(ix)
var('y')
y
y
y
x+y^2
y2+x
s = x+y^2
s
y2+x
diff(s, x, y)
0
xi = var('xi', latex_name=r'\xi')
xi
ξ
s = sin(x*xi)*y^3
s
y3sin(xξ)
s = 2
s
2
s = sin(x*xi)*y^3
s.subs(xi=3, y=2)
8sin(3x)
s
y3sin(xξ)
a = s.subs({xi: 3, y: 2})
a
8sin(3x)
f(x,xi,y) = s
f
(x,ξ,y) ↦ y3sin(xξ)
f(x,3,2)
8sin(3x)
f(4,3,2)
8sin(12)
n(f(4,3,2), digits=50)
−4.2925833440034797733229938259392143385259082262243
s
y3sin(xξ)
var('z')
z
a = s.subs(y=1+z) ; a
(z+1)3sin(xξ)
a.expand()
z3sin(xξ)+3z2sin(xξ)+3zsin(xξ)+sin(xξ)
s = a.expand()
s.factor()
(z+1)3sin(xξ)
s
z3sin(xξ)+3z2sin(xξ)+3zsin(xξ)+sin(xξ)
s.simplify_full()
z3sin(xξ)+3z2sin(xξ)+3zsin(xξ)+sin(xξ)
s = (x+1)^2 - x^2 - 2*x - 1
s
(x+1)2−x2−2x−1
s.simplify_full()
0
File: /projects/sage/sage-6.10/local/lib/python2.7/site-packages/sage/functions/orthogonal_polys.py Signature : chebyshev_T(*args, **kwds) Docstring : Chebyshev polynomials of the first kind. REFERENCE: * [ASHandbook] 22.5.31 page 778 and 6.1.22 page 256. EXAMPLES: sage: chebyshev_T(5,x) 16*x^5 - 20*x^3 + 5*x sage: var('k') k sage: test = chebyshev_T(k,x) sage: test chebyshev_T(k, x)
g1 = plot(chebyshev_T(8,x), [x, -1, 1], axes_labels=[r'$\xi$', '$y$'], aspect_ratio=1, color='red', thickness=2, linestyle=':')
g1
g2 = plot(sin(x^3), (x,-1,1)) ; g2
g = g1 + g2
g
g.save("plot_g.png")
g = plot3d(sin(x*y^2), (x,-4,4), (y,-3,3), plot_points=100)
g.save("plot3d.png")
3D rendering not yet implemented
solve([x+y==6, x-y==4], x, y)
[[x=5, y=1]]
f(x) = x^2 + x - 1
solve(f(x)==0, x)[0]
x=−215−21
y = function('y')(x)
y
y(x)
eq = diff(y, x) + 3*x*y(x)^2
eq
3xy(x)2+D[0](y)(x)
desolve(eq == 0, y)
3y(x)1=21x2+C
desolve?
File: /projects/sage/sage-6.10/local/lib/python2.7/site-packages/sage/calculus/desolvers.py Signature : desolve(de, dvar, ics=None, ivar=None, show_method=False, contrib_ode=False) Docstring : Solves a 1st or 2nd order linear ODE via maxima. Including IVP and BVP. *Use* "desolve? <tab>" *if the output in truncated in notebook.* INPUT: * "de" - an expression or equation representing the ODE * "dvar" - the dependent variable (hereafter called "y") * "ics" - (optional) the initial or boundary conditions * for a first-order equation, specify the initial "x" and "y" * for a second-order equation, specify the initial "x", "y", and "dy/dx", i.e. write [x_0, y(x_0), y'(x_0)] * for a second-order boundary solution, specify initial and final "x" and "y" boundary conditions, i.e. write [x_0, y(x_0), x_1, y(x_1)]. * gives an error if the solution is not SymbolicEquation (as happens for example for a Clairaut equation) * "ivar" - (optional) the independent variable (hereafter called x), which must be specified if there is more than one independent variable in the equation. * "show_method" - (optional) if true, then Sage returns pair "[solution, method]", where method is the string describing the method which has been used to get a solution (Maxima uses the following order for first order equations: linear, separable, exact (including exact with integrating factor), homogeneous, bernoulli, generalized homogeneous) - use carefully in class, see below for the example of the equation which is separable but this property is not recognized by Maxima and the equation is solved as exact. * "contrib_ode" - (optional) if true, desolve allows to solve Clairaut, Lagrange, Riccati and some other equations. This may take a long time and is thus turned off by default. Initial conditions can be used only if the result is one SymbolicEquation (does not contain a singular solution, for example) OUTPUT: In most cases return a SymbolicEquation which defines the solution implicitly. If the result is in the form y(x)=... (happens for linear eqs.), return the right-hand side only. The possible constant solutions of separable ODE's are omitted. EXAMPLES: sage: x = var('x') sage: y = function('y')(x) sage: desolve(diff(y,x) + y - 1, y) (_C + e^x)*e^(-x) sage: f = desolve(diff(y,x) + y - 1, y, ics=[10,2]); f (e^10 + e^x)*e^(-x) sage: plot(f) Graphics object consisting of 1 graphics primitive We can also solve second-order differential equations.: sage: x = var('x') sage: y = function('y')(x) sage: de = diff(y,x,2) - y == x sage: desolve(de, y) _K2*e^(-x) + _K1*e^x - x sage: f = desolve(de, y, [10,2,1]); f -x + 7*e^(x - 10) + 5*e^(-x + 10) sage: f(x=10) 2 sage: diff(f,x)(x=10) 1 sage: de = diff(y,x,2) + y == 0 sage: desolve(de, y) _K2*cos(x) + _K1*sin(x) sage: desolve(de, y, [0,1,pi/2,4]) cos(x) + 4*sin(x) sage: desolve(y*diff(y,x)+sin(x)==0,y) -1/2*y(x)^2 == _C - cos(x) Clairaut equation: general and singular solutions: sage: desolve(diff(y,x)^2+x*diff(y,x)-y==0,y,contrib_ode=True,show_method=True) [[y(x) == _C^2 + _C*x, y(x) == -1/4*x^2], 'clairault'] For equations involving more variables we specify an independent variable: sage: a,b,c,n=var('a b c n') sage: desolve(x^2*diff(y,x)==a+b*x^n+c*x^2*y^2,y,ivar=x,contrib_ode=True) [[y(x) == 0, (b*x^(n - 2) + a/x^2)*c^2*u == 0]] sage: desolve(x^2*diff(y,x)==a+b*x^n+c*x^2*y^2,y,ivar=x,contrib_ode=True,show_method=True) [[[y(x) == 0, (b*x^(n - 2) + a/x^2)*c^2*u == 0]], 'riccati'] Higher order equations, not involving independent variable: sage: desolve(diff(y,x,2)+y*(diff(y,x,1))^3==0,y).expand() 1/6*y(x)^3 + _K1*y(x) == _K2 + x sage: desolve(diff(y,x,2)+y*(diff(y,x,1))^3==0,y,[0,1,1,3]).expand() 1/6*y(x)^3 - 5/3*y(x) == x - 3/2 sage: desolve(diff(y,x,2)+y*(diff(y,x,1))^3==0,y,[0,1,1,3],show_method=True) [1/6*y(x)^3 - 5/3*y(x) == x - 3/2, 'freeofx'] Separable equations - Sage returns solution in implicit form: sage: desolve(diff(y,x)*sin(y) == cos(x),y) -cos(y(x)) == _C + sin(x) sage: desolve(diff(y,x)*sin(y) == cos(x),y,show_method=True) [-cos(y(x)) == _C + sin(x), 'separable'] sage: desolve(diff(y,x)*sin(y) == cos(x),y,[pi/2,1]) -cos(y(x)) == -cos(1) + sin(x) - 1 Linear equation - Sage returns the expression on the right hand side only: sage: desolve(diff(y,x)+(y) == cos(x),y) 1/2*((cos(x) + sin(x))*e^x + 2*_C)*e^(-x) sage: desolve(diff(y,x)+(y) == cos(x),y,show_method=True) [1/2*((cos(x) + sin(x))*e^x + 2*_C)*e^(-x), 'linear'] sage: desolve(diff(y,x)+(y) == cos(x),y,[0,1]) 1/2*(cos(x)*e^x + e^x*sin(x) + 1)*e^(-x) This ODE with separated variables is solved as exact. Explanation - factor does not split e^{x-y} in Maxima into e^{x}e^{y}: sage: desolve(diff(y,x)==exp(x-y),y,show_method=True) [-e^x + e^y(x) == _C, 'exact'] You can solve Bessel equations, also using initial conditions, but you cannot put (sometimes desired) the initial condition at x=0, since this point is a singular point of the equation. Anyway, if the solution should be bounded at x=0, then _K2=0.: sage: desolve(x^2*diff(y,x,x)+x*diff(y,x)+(x^2-4)*y==0,y) _K1*bessel_J(2, x) + _K2*bessel_Y(2, x) Example of difficult ODE producing an error: sage: desolve(sqrt(y)*diff(y,x)+e^(y)+cos(x)-sin(x+y)==0,y) # not tested Traceback (click to the left for traceback) ... NotImplementedError, "Maxima was unable to solve this ODE. Consider to set option contrib_ode to True." Another difficult ODE with error - moreover, it takes a long time sage: desolve(sqrt(y)*diff(y,x)+e^(y)+cos(x)-sin(x+y)==0,y,contrib_ode=True) # not tested Some more types of ODE's: sage: desolve(x*diff(y,x)^2-(1+x*y)*diff(y,x)+y==0,y,contrib_ode=True,show_method=True) [[y(x) == _C*e^x, y(x) == _C + log(x)], 'factor'] sage: desolve(diff(y,x)==(x+y)^2,y,contrib_ode=True,show_method=True) [[[x == _C - arctan(sqrt(t)), y(x) == -x - sqrt(t)], [x == _C + arctan(sqrt(t)), y(x) == -x + sqrt(t)]], 'lagrange'] These two examples produce an error (as expected, Maxima 5.18 cannot solve equations from initial conditions). Maxima 5.18 returns false answer in this case!: sage: desolve(diff(y,x,2)+y*(diff(y,x,1))^3==0,y,[0,1,2]).expand() # not tested Traceback (click to the left for traceback) ... NotImplementedError, "Maxima was unable to solve this ODE. Consider to set option contrib_ode to True." sage: desolve(diff(y,x,2)+y*(diff(y,x,1))^3==0,y,[0,1,2],show_method=True) # not tested Traceback (click to the left for traceback) ... NotImplementedError, "Maxima was unable to solve this ODE. Consider to set option contrib_ode to True." Second order linear ODE: sage: desolve(diff(y,x,2)+2*diff(y,x)+y == cos(x),y) (_K2*x + _K1)*e^(-x) + 1/2*sin(x) sage: desolve(diff(y,x,2)+2*diff(y,x)+y == cos(x),y,show_method=True) [(_K2*x + _K1)*e^(-x) + 1/2*sin(x), 'variationofparameters'] sage: desolve(diff(y,x,2)+2*diff(y,x)+y == cos(x),y,[0,3,1]) 1/2*(7*x + 6)*e^(-x) + 1/2*sin(x) sage: desolve(diff(y,x,2)+2*diff(y,x)+y == cos(x),y,[0,3,1],show_method=True) [1/2*(7*x + 6)*e^(-x) + 1/2*sin(x), 'variationofparameters'] sage: desolve(diff(y,x,2)+2*diff(y,x)+y == cos(x),y,[0,3,pi/2,2]) 3*(x*(e^(1/2*pi) - 2)/pi + 1)*e^(-x) + 1/2*sin(x) sage: desolve(diff(y,x,2)+2*diff(y,x)+y == cos(x),y,[0,3,pi/2,2],show_method=True) [3*(x*(e^(1/2*pi) - 2)/pi + 1)*e^(-x) + 1/2*sin(x), 'variationofparameters'] sage: desolve(diff(y,x,2)+2*diff(y,x)+y == 0,y) (_K2*x + _K1)*e^(-x) sage: desolve(diff(y,x,2)+2*diff(y,x)+y == 0,y,show_method=True) [(_K2*x + _K1)*e^(-x), 'constcoeff'] sage: desolve(diff(y,x,2)+2*diff(y,x)+y == 0,y,[0,3,1]) (4*x + 3)*e^(-x) sage: desolve(diff(y,x,2)+2*diff(y,x)+y == 0,y,[0,3,1],show_method=True) [(4*x + 3)*e^(-x), 'constcoeff'] sage: desolve(diff(y,x,2)+2*diff(y,x)+y == 0,y,[0,3,pi/2,2]) (2*x*(2*e^(1/2*pi) - 3)/pi + 3)*e^(-x) sage: desolve(diff(y,x,2)+2*diff(y,x)+y == 0,y,[0,3,pi/2,2],show_method=True) [(2*x*(2*e^(1/2*pi) - 3)/pi + 3)*e^(-x), 'constcoeff'] AUTHORS: * David Joyner (1-2006) * Robert Bradshaw (10-2008) * Robert Marik (10-2009)