Contact
CoCalc Logo Icon
StoreFeaturesDocsShareSupport News AboutSign UpSign In
| Download
Views: 108
typeset_mode(True)# Juste pour que les choses soient joliment affichées

Exemple.

Trouver la forme de smith de la matrice à coefficients entiers J=(204062262262)J = \left(\begin{array}{rrr} 2 & 0 & -4 \\ 0 & 6 & 2 \\ 2 & 6 & 2 \\ 2 & 6 & 2 \end{array}\right)

J=matrix(ZZ,[[2,0,-4],[0,6,2],[2,6,2],[2,6,2]]) ## ZZ est ici pour dire l'anneau ambient. J
(204062262262)\displaystyle \left(\begin{array}{rrr} 2 & 0 & -4 \\ 0 & 6 & 2 \\ 2 & 6 & 2 \\ 2 & 6 & 2 \end{array}\right)
J.smith_form()
((2000200012000)\displaystyle \left(\begin{array}{rrr} 2 & 0 & 0 \\ 0 & 2 & 0 \\ 0 & 0 & 12 \\ 0 & 0 & 0 \end{array}\right), (0010010013100011)\displaystyle \left(\begin{array}{rrrr} 0 & 0 & 1 & 0 \\ 0 & 1 & 0 & 0 \\ 1 & -3 & -1 & 0 \\ 0 & 0 & -1 & 1 \end{array}\right), (110011023)\displaystyle \left(\begin{array}{rrr} 1 & -1 & 0 \\ 0 & 1 & 1 \\ 0 & -2 & -3 \end{array}\right))

Ceci retourne une liste, les éléments de la liste sont la forme normale, puis les deux "matrices de passage". Il faut juste faire attention car sage commence à compter à 0. Donc pour accéder au deuxième élément de la liste on doit utiliser l'indice 1

X= J.smith_form()[1] X.inverse()
(1310010010001001)\displaystyle \left(\begin{array}{rrrr} 1 & 3 & 1 & 0 \\ 0 & 1 & 0 & 0 \\ 1 & 0 & 0 & 0 \\ 1 & 0 & 0 & 1 \end{array}\right)

On peut aussi faire les opérations élémentaires sur les rangéees et les colonnes. Regardez le code ci-aprés, vous comprendrez la syntaxe. Il faut toujours faire attention aux comptes qui commencent à 0.

M = J.with_added_multiple_of_row(2,0,-1) M = M.with_added_multiple_of_row(3,0,-1) M
(204062066066)\displaystyle \left(\begin{array}{rrr} 2 & 0 & -4 \\ 0 & 6 & 2 \\ 0 & 6 & 6 \\ 0 & 6 & 6 \end{array}\right)
M= M.with_added_multiple_of_row(2,1,-1) M= M.with_added_multiple_of_row(3,1,-1) M
(204062004004)\displaystyle \left(\begin{array}{rrr} 2 & 0 & -4 \\ 0 & 6 & 2 \\ 0 & 0 & 4 \\ 0 & 0 & 4 \end{array}\right)
M = M.with_added_multiple_of_row(3,2,-1) M
(204062004000)\displaystyle \left(\begin{array}{rrr} 2 & 0 & -4 \\ 0 & 6 & 2 \\ 0 & 0 & 4 \\ 0 & 0 & 0 \end{array}\right)
M = M.with_swapped_columns(1,2) M
(240026040000)\displaystyle \left(\begin{array}{rrr} 2 & -4 & 0 \\ 0 & 2 & 6 \\ 0 & 4 & 0 \\ 0 & 0 & 0 \end{array}\right)
M= M.with_added_multiple_of_column(2,1,-3) M = M.with_added_multiple_of_row(0,1,2) M = M.with_added_multiple_of_row(2,1,-2) M = M.with_added_multiple_of_column(2,0,-6)
(2000200012000)\displaystyle \left(\begin{array}{rrr} 2 & 0 & 0 \\ 0 & 2 & 0 \\ 0 & 0 & -12 \\ 0 & 0 & 0 \end{array}\right)

On peut aussi calculer les mineurs. Ci après des petites lignes de code qui créent les sous-matrices de taille choisie, on les met dans une liste, puis on calcule les déterminants. Ce code n'est vraiment pas robuste... on devrait, en toute rigueur vérifier que MM est une matrice, puis que kk fait du sens...

def Submat(M, k): return [M[rows,cols] for cols in Combinations(M.ncols(),k) for rows in Combinations(M.nrows(),k)];

Voici les sous-matrices 2×22\times 2 de la matrice originale JJ

Submat(J, 2)
[(2006)\displaystyle \left(\begin{array}{rr} 2 & 0 \\ 0 & 6 \end{array}\right), (2026)\displaystyle \left(\begin{array}{rr} 2 & 0 \\ 2 & 6 \end{array}\right), (2026)\displaystyle \left(\begin{array}{rr} 2 & 0 \\ 2 & 6 \end{array}\right), (0626)\displaystyle \left(\begin{array}{rr} 0 & 6 \\ 2 & 6 \end{array}\right), (0626)\displaystyle \left(\begin{array}{rr} 0 & 6 \\ 2 & 6 \end{array}\right), (2626)\displaystyle \left(\begin{array}{rr} 2 & 6 \\ 2 & 6 \end{array}\right), (2402)\displaystyle \left(\begin{array}{rr} 2 & -4 \\ 0 & 2 \end{array}\right), (2422)\displaystyle \left(\begin{array}{rr} 2 & -4 \\ 2 & 2 \end{array}\right), (2422)\displaystyle \left(\begin{array}{rr} 2 & -4 \\ 2 & 2 \end{array}\right), (0222)\displaystyle \left(\begin{array}{rr} 0 & 2 \\ 2 & 2 \end{array}\right), (0222)\displaystyle \left(\begin{array}{rr} 0 & 2 \\ 2 & 2 \end{array}\right), (2222)\displaystyle \left(\begin{array}{rr} 2 & 2 \\ 2 & 2 \end{array}\right), (0462)\displaystyle \left(\begin{array}{rr} 0 & -4 \\ 6 & 2 \end{array}\right), (0462)\displaystyle \left(\begin{array}{rr} 0 & -4 \\ 6 & 2 \end{array}\right), (0462)\displaystyle \left(\begin{array}{rr} 0 & -4 \\ 6 & 2 \end{array}\right), (6262)\displaystyle \left(\begin{array}{rr} 6 & 2 \\ 6 & 2 \end{array}\right), (6262)\displaystyle \left(\begin{array}{rr} 6 & 2 \\ 6 & 2 \end{array}\right), (6262)\displaystyle \left(\begin{array}{rr} 6 & 2 \\ 6 & 2 \end{array}\right)]
[det(m) for m in Submat(J,2)]
[12\displaystyle 12, 12\displaystyle 12, 12\displaystyle 12, 12\displaystyle -12, 12\displaystyle -12, 0\displaystyle 0, 4\displaystyle 4, 12\displaystyle 12, 12\displaystyle 12, 4\displaystyle -4, 4\displaystyle -4, 0\displaystyle 0, 24\displaystyle 24, 24\displaystyle 24, 24\displaystyle 24, 0\displaystyle 0, 0\displaystyle 0, 0\displaystyle 0]
[det(m) for m in Submat(J,3)]
[48\displaystyle 48, 48\displaystyle 48, 0\displaystyle 0, 0\displaystyle 0]