Calcul matriciel

Une matrice est un tableau de nombres. Derrière cette définition modeste se cache un outil très puissant : les matrices codent des systèmes d'équations, des transformations du plan, des graphes, des évolutions de populations… et se multiplient selon une règle bien particulière.

  • Calculer avec des matrices : somme, produit, puissances
  • Savoir que le produit n'est pas commutatif
  • Calculer l'inverse d'une matrice carrée d'ordre 2
  • Écrire et résoudre un système linéaire sous forme matricielle

Cours

1. Matrices

Une matrice de taille $n \times p$ est un tableau de nombres réels à $n$ lignes et $p$ colonnes. Le coefficient de la ligne $i$ et de la colonne $j$ est noté $a_{ij}$ ; on écrit $A = (a_{ij})$.

  • Si $n = p$, la matrice est carrée d'ordre $n$ ;
  • une matrice $n \times 1$ est une matrice colonne, une matrice $1 \times p$ une matrice ligne ;
  • la matrice identité $I_n$ est la matrice carrée qui a des 1 sur la diagonale et des 0 ailleurs ; la matrice nulle n'a que des 0.

$A = \begin{pmatrix} 2 & -1 & 0 \\ 3 & 5 & 4\end{pmatrix}$ est de taille $2 \times 3$, avec $a_{12} = -1$ et $a_{23} = 4$. $\quad I_2 = \begin{pmatrix} 1 & 0 \\ 0 & 1\end{pmatrix}$.

2. Opérations

Pour deux matrices de même taille, on additionne coefficient par coefficient : $(A + B)_{ij} = a_{ij} + b_{ij}$. Pour un réel $k$, $(kA)_{ij} = ka_{ij}$.

Soit $A$ de taille $n \times p$ et $B$ de taille $p \times q$ (le nombre de colonnes de $A$ est égal au nombre de lignes de $B$). Le produit $AB$ est la matrice $n \times q$ de coefficients $$c_{ij} = a_{i1}b_{1j} + a_{i2}b_{2j} + \dots + a_{ip}b_{pj} = \sum_{k=1}^{p}a_{ik}b_{kj}$$ (ligne $i$ de $A$ « fois » colonne $j$ de $B$).

$\begin{pmatrix} 1 & 2 \\ 3 & 4\end{pmatrix}\begin{pmatrix} 5 \\ 6\end{pmatrix} = \begin{pmatrix} 1 \times 5 + 2 \times 6 \\ 3 \times 5 + 4 \times 6\end{pmatrix} = \begin{pmatrix} 17 \\ 39\end{pmatrix}$ ; $\quad\begin{pmatrix} 1 & 2 \\ 3 & 4\end{pmatrix}\begin{pmatrix} 0 & 1 \\ 1 & 0\end{pmatrix} = \begin{pmatrix} 2 & 1 \\ 4 & 3\end{pmatrix}$.

Lorsque les produits existent : $(AB)C = A(BC)$ (associativité), $A(B + C) = AB + AC$ et $(A + B)C = AC + BC$ (distributivité), $AI_p = I_nA = A$.

  • En général, $AB \neq BA$ : le produit n'est pas commutatif (l'un des deux peut même ne pas exister).
  • $AB = 0$ n'implique pas $A = 0$ ou $B = 0$ : $\begin{pmatrix} 1 & 1 \\ 1 & 1\end{pmatrix}\begin{pmatrix} 1 & -1 \\ -1 & 1\end{pmatrix} = \begin{pmatrix} 0 & 0 \\ 0 & 0\end{pmatrix}$.
  • Par conséquent, $(A + B)^2 = A^2 + AB + BA + B^2$, qui n'est égal à $A^2 + 2AB + B^2$ que si $AB = BA$.

3. Puissances

Pour $A$ carrée d'ordre $n$ : $A^0 = I_n$ et $A^{k+1} = A^k \times A$. Par exemple $A^3 = AAA$.

Si $D = \begin{pmatrix} a & 0 \\ 0 & b\end{pmatrix}$, alors $D^k = \begin{pmatrix} a^k & 0 \\ 0 & b^k\end{pmatrix}$ pour tout entier naturel $k$.

Pour $A = \begin{pmatrix} 1 & 1 \\ 0 & 1\end{pmatrix}$ et tout $n \in \mathbb{N}$ : $A^n = \begin{pmatrix} 1 & n \\ 0 & 1\end{pmatrix}$.

Par récurrence. $A^0 = I_2 = \begin{pmatrix} 1 & 0 \\ 0 & 1\end{pmatrix}$ : vrai pour $n = 0$. Si $A^n = \begin{pmatrix} 1 & n \\ 0 & 1\end{pmatrix}$, alors $A^{n+1} = A^nA = \begin{pmatrix} 1 & n \\ 0 & 1\end{pmatrix}\begin{pmatrix} 1 & 1 \\ 0 & 1\end{pmatrix} = \begin{pmatrix} 1 & n + 1 \\ 0 & 1\end{pmatrix}$. $\blacksquare$

Les calculatrices (menu Matrice) et Python (avec numpy) calculent sommes, produits, puissances et inverses. C'est utile pour conjecturer une formule de $A^n$, qu'on démontre ensuite par récurrence.

4. Inverse d'une matrice carrée

Une matrice carrée $A$ d'ordre $n$ est inversible s'il existe une matrice $B$ telle que $AB = BA = I_n$. Cette matrice est unique ; on la note $A^{-1}$.

Soit $A = \begin{pmatrix} a & b \\ c & d\end{pmatrix}$. Son déterminant est $\det A = ad - bc$. La matrice $A$ est inversible si et seulement si $\det A \neq 0$, et alors $$A^{-1} = \frac{1}{ad - bc}\begin{pmatrix} d & -b \\ -c & a\end{pmatrix}.$$

Justification de la formule.

Posons $B = \begin{pmatrix} d & -b \\ -c & a\end{pmatrix}$. Un calcul direct donne $AB = \begin{pmatrix} ad - bc & -ab + ba \\ cd - dc & -cb + da\end{pmatrix} = (ad - bc)I_2$, et de même $BA = (ad - bc)I_2$.

Si $ad - bc \neq 0$, la matrice $\frac{1}{ad - bc}B$ est donc l'inverse de $A$. Si $ad - bc = 0$, alors $AB = 0$ ; si $A$ était inversible, on aurait $B = A^{-1}AB = 0$, donc $a = b = c = d = 0$ et $A = 0$, qui n'est pas inversible : contradiction. $\blacksquare$

$A = \begin{pmatrix} 2 & 1 \\ 5 & 3\end{pmatrix}$ : $\det A = 6 - 5 = 1$, donc $A^{-1} = \begin{pmatrix} 3 & -1 \\ -5 & 2\end{pmatrix}$. On vérifie que $AA^{-1} = I_2$.

5. Systèmes linéaires

Le système $\begin{cases} 2x + y = 5 \\ x - y = 1\end{cases}$ s'écrit $AX = B$ avec $A = \begin{pmatrix} 2 & 1 \\ 1 & -1\end{pmatrix}$, $X = \begin{pmatrix} x \\ y\end{pmatrix}$ et $B = \begin{pmatrix} 5 \\ 1\end{pmatrix}$.

Si $A$ est inversible, le système a une unique solution : $X = A^{-1}B$ (on multiplie à gauche par $A^{-1}$).

Pour $\begin{cases} 2x + y - z = 1 \\ x - y + z = 2 \\ x + 2y + z = 5\end{cases}$, on calcule $A^{-1}$ à la calculatrice puis $X = A^{-1}B$, ou on résout à la main : la somme des deux premières lignes donne $3x = 3$, d'où $x = 1$, puis $y = 1$ et $z = 2$.

6. Transformations du plan

Une matrice $M = \begin{pmatrix} a & b \\ c & d\end{pmatrix}$ transforme le point $(x\,;\,y)$ en $(ax + by\,;\,cx + dy)$. Ses colonnes sont les images des vecteurs $\vec\imath$ et $\vec\jmath$. Exemples :

  • rotation d'angle $\theta$ : $\begin{pmatrix} \cos\theta & -\sin\theta \\ \sin\theta & \cos\theta\end{pmatrix}$ ;
  • symétrie d'axe $(Ox)$ : $\begin{pmatrix} 1 & 0 \\ 0 & -1\end{pmatrix}$ ; homothétie de rapport $k$ : $kI_2$.

Enchaîner deux transformations revient à multiplier leurs matrices ; $|\det M|$ est le coefficient par lequel les aires sont multipliées.

Des tableaux de nombres servaient déjà à résoudre des systèmes dans le traité chinois des Neuf chapitres (vers le Ier siècle). Le mot « matrice » est dû à Sylvester (1850) et le calcul matriciel à Cayley (1858). Les matrices sont aujourd'hui partout : images numériques, moteurs de recherche, intelligence artificielle.

Mini-jeux

Exercices

Avec $A = \begin{pmatrix} 1 & 2 \\ 3 & 4\end{pmatrix}$ et $B = \begin{pmatrix} 0 & 1 \\ 1 & 0\end{pmatrix}$, calculer $AB$ et $BA$. Que remarque-t-on ?

$AB = \begin{pmatrix} 2 & 1 \\ 4 & 3\end{pmatrix}$ (colonnes échangées), $BA = \begin{pmatrix} 3 & 4 \\ 1 & 2\end{pmatrix}$ (lignes échangées). $AB \neq BA$.

$A$ est de taille $2 \times 3$, $B$ de taille $3 \times 3$ et $C$ de taille $3 \times 1$. Parmi $AB$, $BA$, $BC$, $CA$, $AC$, $ABC$, lesquels existent ? Quelle est leur taille ?

$AB$ : $2 \times 3$. $BC$ : $3 \times 1$. $AC$ : $2 \times 1$. $ABC$ : $2 \times 1$. $BA$ et $CA$ n'existent pas.

Calculer l'inverse de $\begin{pmatrix} 4 & 7 \\ 1 & 2\end{pmatrix}$.

$\det = 8 - 7 = 1$ : inverse $\begin{pmatrix} 2 & -7 \\ -1 & 4\end{pmatrix}$.

Écrire le système $\begin{cases} x + y + z = 6 \\ 2x - y + z = 3 \\ x + 2y - z = 2\end{cases}$ sous la forme $AX = B$ puis le résoudre (calculatrice autorisée pour $A^{-1}$).

$x =$

$A = \begin{pmatrix} 1 & 1 & 1 \\ 2 & -1 & 1 \\ 1 & 2 & -1\end{pmatrix}$, $B = \begin{pmatrix} 6 \\ 3 \\ 2\end{pmatrix}$. À la main : $L_1 + L_3$ donne $2x + 3y = 8$, $L_2 + L_3$ donne $3x + y = 5$, d'où $x = 1$, $y = 2$, puis $z = 3$. Vérification : $1 + 2 + 3 = 6$, $2 - 2 + 3 = 3$, $1 + 4 - 3 = 2$.

Soit $A = \begin{pmatrix} 2 & 1 \\ 0 & 3\end{pmatrix}$. Vérifier que $A^2 - 5A + 6I_2 = 0$. En déduire que $A$ est inversible et donner $A^{-1}$.

$A^2 = \begin{pmatrix} 4 & 5 \\ 0 & 9\end{pmatrix}$ et $A^2 - 5A + 6I_2 = \begin{pmatrix} 4 - 10 + 6 & 5 - 5 \\ 0 & 9 - 15 + 6\end{pmatrix} = 0$. Donc $A(5I_2 - A) = 6I_2$, soit $A \times \frac16(5I_2 - A) = I_2$ (et de même dans l'autre sens) : $A^{-1} = \frac16\begin{pmatrix} 3 & -1 \\ 0 & 2\end{pmatrix}$.

Soit $R_\theta$ la matrice de la rotation d'angle $\theta$. Calculer $R_\alpha R_\beta$ et reconnaître $R_{\alpha + \beta}$. En déduire $R_\theta^n$.

$R_\alpha R_\beta = \begin{pmatrix} \cos\alpha\cos\beta - \sin\alpha\sin\beta & -(\cos\alpha\sin\beta + \sin\alpha\cos\beta) \\ \sin\alpha\cos\beta + \cos\alpha\sin\beta & \cos\alpha\cos\beta - \sin\alpha\sin\beta\end{pmatrix} = R_{\alpha + \beta}$ par les formules d'addition. Par récurrence, $R_\theta^n = R_{n\theta}$ : c'est la formule de Moivre en version matricielle !

Déterminer la fonction $f(x) = ax^2 + bx + c$ dont la courbe passe par les points $(1\,;\,2)$, $(2\,;\,3)$ et $(3\,;\,6)$, en écrivant un système matriciel.

$\begin{pmatrix} 1 & 1 & 1 \\ 4 & 2 & 1 \\ 9 & 3 & 1\end{pmatrix}\begin{pmatrix} a \\ b \\ c\end{pmatrix} = \begin{pmatrix} 2 \\ 3 \\ 6\end{pmatrix}$. En soustrayant les lignes : $3a + b = 1$ et $5a + b = 3$, d'où $a = 1$, $b = -2$, $c = 3$. Donc $f(x) = x^2 - 2x + 3$.

Soit $N = \begin{pmatrix} 0 & 1 \\ 0 & 0\end{pmatrix}$ et $A = 2I_2 + N$. Calculer $N^2$. Justifier qu'on peut utiliser la formule du binôme pour calculer $A^n$, et en déduire $A^n$.

$N^2 = 0$. $I_2$ commute avec toute matrice, donc la formule du binôme s'applique : $A^n = \sum_k\binom nk(2I_2)^{n-k}N^k = 2^nI_2 + n2^{n-1}N$ (les termes $k \geqslant 2$ sont nuls). Ainsi $A^n = \begin{pmatrix} 2^n & n2^{n-1} \\ 0 & 2^n\end{pmatrix}$.