9.5 Formule de Cramer et conséquences

Dans cette section, on présente une application intéressante de la théorie du déterminant à la résolution des systèmes linéaires.

Si \(A\) est une matrice inversible \(n\times n\), on sait que pour tout \(\boldsymbol{b}\in \mathbb{R}^n\), le système \[ A\boldsymbol{x}=\boldsymbol{b} \] possède exactement une solution \(\boldsymbol{x}\), donnée par \[ \boldsymbol{x}=A^{-1}\boldsymbol{b}\,. \] Nous allons voir comment il est possible de calculer chacune des composantes \(x_j\) de cette solution, sans passer par la connaissance de \(A^{-1}\).

Si \(M\) est une matrice \(n\times n\), et \(\boldsymbol{z}\in \mathbb{R}^n\), \(M_j(\boldsymbol{z})\) est la matrice \(n\times n\) obtenue à partir de \(M\) en remplaçant la \(j\)-ème colonne par \(\boldsymbol{z}\) (sans toucher aux autres colonnes).

Exemple: Si \(M= \begin{pmatrix} 1&2&3\\ 4&5&6\\ 7&8&9 \end{pmatrix} \), \(\boldsymbol{z}= \begin{pmatrix} \sqrt{2}\\\pi\\e \end{pmatrix} \), alors \[ M_2(\boldsymbol{z})= \begin{pmatrix} 1&\sqrt{2}&3\\ 4&\pi&6\\ 7&e&9 \end{pmatrix} \,.\]

(Formule de Cramer) Soit \(A\) une matrice \(n\times n\) inversible, \(\boldsymbol{b}\in \mathbb{R}^n\), et soit \(\boldsymbol{x}\in\mathbb{R}^n\) l'unique solution du système \(A\boldsymbol{x}=\boldsymbol{b}\). Alors pour tout \(j\in\{1,2,\dots,n\}\), la \(j\)-ème composante de \(\boldsymbol{x}\) est égale à \[ x_j=\frac{\det(A_j(\boldsymbol{b}))}{\det(A)}\,. \]

Notons \(A=[\boldsymbol{a}_1\cdots\boldsymbol{a}_n]\). Calculons le produit de \(A\) par \((I_n)_j(\boldsymbol{x})\): \[\begin{aligned} A((I_n)_j(\boldsymbol{x})) &=A\bigl[\boldsymbol{e}_1 \cdots \boldsymbol{e}_{j-1}\,\boldsymbol{x}\,\boldsymbol{e}_{j+1} \cdots \boldsymbol{e}_n\bigr]\\ &=\bigl[A\boldsymbol{e}_1 \cdots A\boldsymbol{e}_{j-1}\,A\boldsymbol{x}\,A\boldsymbol{e}_{j+1} \cdots A\boldsymbol{e}_n\bigr]\\ &=\bigl[\boldsymbol{a}_1 \cdots \boldsymbol{a}_{j-1}\,\boldsymbol{b}\,\boldsymbol{a}_{j+1} \cdots \boldsymbol{a}_n\bigr]\\ &=A_j(\boldsymbol{b})\,. \end{aligned}\] On a donc \[ \det(A)\det\bigl((I_n)_j(\boldsymbol{x})\bigr) = \det\bigl(A((I_n)_j(\boldsymbol{x}))\bigr) =\det(A_j(\boldsymbol{b}))\,. \] Or en développant selon la \(j\)-ème colonne, \[\begin{aligned} \det\bigl((I_n)_j(\boldsymbol{x})\bigr) &=\sum_{k=1}^n(-1)^{k+j}x_k\det\bigl(((I_n)_j(\boldsymbol{x}))_{kj}\bigr)\\ &=\sum_{k=1}^n(-1)^{k+j}x_k\det\bigl((I_n)_{kj}\bigr)\,. \end{aligned}\] Dans la deuxième ligne, on a utilisé le fait que l'on trace la colonne contenant \(\boldsymbol{x}\), et donc cela revient au même de travailler avec \(I_n\) qu'avec \((I_n)_j(\boldsymbol{x})\). Ensuite, remarquons que si \(k\neq j\), alors \((I_n)_{kj}\) contient une colonne et une ligne de zéros, et donc en développant celon cette ligne, on voit que \(\det((I_n)_{kj})=0\).

Il ne subsiste donc, dans la somme ci-dessus, que le terme \(k=j\): \[\begin{aligned} \det\bigl((I_n)_j(\boldsymbol{x})\bigr) &=(-1)^{j+j}x_j\det\bigl((I_n)_{jj}\bigr)\\ &=x_j\det(I_{n-1})\\ &=x_j \end{aligned}\] Ceci démontre la formule.

Exemple: Considérons le système linéaire \(A\boldsymbol{x}=\boldsymbol{b}\) donné par \[ (*)\quad \begin{pmatrix} 1&2&3&4\\ 1&2&3&0\\ 1&2&0&0\\ 1&0&0&0 \end{pmatrix} \begin{pmatrix} x_1\\ x_2\\ x_3\\ x_4 \end{pmatrix} = \begin{pmatrix} 5\\ 6\\ 7\\ 8 \end{pmatrix} \] Comme \(\det(A)=4!=24\neq 0\), la matrice est inversible et la solution du système est unique. Si on s'intéresse par exemple à la quatrième composante \(x_4\), \[\begin{aligned} x_4=\frac{\det(A_4(\boldsymbol{b}))}{\det(A)} &=\frac{1}{24}\det \begin{pmatrix} 1&2&3&5\\ 1&2&3&6\\ 1&2&0&7\\ 1&0&0&8 \end{pmatrix}\\ &=\frac{1}{4}\det \begin{pmatrix} 1&1&1&5\\ 1&1&1&6\\ 1&1&0&7\\ 1&0&0&8 \end{pmatrix}\\ &=\frac{1}{4}\det \begin{pmatrix} 0&0&1&5\\ 0&0&1&6\\ 0&1&0&7\\ 1&0&0&8 \end{pmatrix}\,. \end{aligned}\] On a d'abord extrait un \(2\) de la deuxième colonne et un \(3\) de la troisième, puis on a soustrait la deuxième colonne de la première, et la troisième de la deuxième. Maintenant, en développant selon la première colonne, \[\begin{aligned} x_4&=\frac{1}{4}\det \begin{pmatrix} 0&0&1&5\\ 0&0&1&6\\ 0&1&0&7\\ 1&0&0&8 \end{pmatrix}\\ &=\frac{1}{4}(-1)\det \begin{pmatrix} 0&1&5\\ 0&1&6\\ 1&0&7\\ \end{pmatrix}\\ &=\frac{1}{4}(-1)(1)\det \begin{pmatrix} 1&5\\ 1&6\\ \end{pmatrix}\\ &=\frac{1}{4}(-1)(1)(6-5)\\ &=-\frac{1}{4}\,. \end{aligned}\] Bien-sûr, on trouve la même chose qu'en résolvant complètement le système \((*)\), qui serait par exemple de faire \(L_1\leftarrow L_1-L_2\), \(L_2\leftarrow L_2-L_3\), \(L_3\leftarrow L_3-L_4\), qui donne \[ \begin{pmatrix} 0&0&0&4\\ 0&0&3&0\\ 0&2&0&0\\ 1&0&0&0 \end{pmatrix} \begin{pmatrix} x_1\\ x_2\\ x_3\\ x_4 \end{pmatrix} = \begin{pmatrix} -1\\ -1\\ -1\\ 8 \end{pmatrix} \]

Une application intéressante: formule pour \(A^{-1}\)

Si le système considéré est grand, la formule de Cramer pour \(x_j\) représente un intérêt limité du point de vue calculatoire. En effet elle implique le calcul de deux déterminants, qui comme on sait représente un nombre d'opérations croissant factoriellement avec la taille du système.

Par contre, d'un point de vue théorique elle permet de dériver une formule explicite pour l'inverse d'une matrice:

Théorème: Soit \(A\) une matrice \(n\times n\) inversible, et soit \(C\) la matrice \(n\times n\) des cofacteurs, dont les coefficients sont définis par \[ c_{ij}:= (-1)^{i+j}\det(A_{ij})\,. \] Alors l'inverse de \(A\) est donné par \[ A^{-1}=\frac{1}{\det(A)}C^T\,. \]

Considérons \(A\) inversible, et notons son inverse plutôt \(G=(g_{ij})\), en nommant ses colonnes: \[G=[\boldsymbol{g}_1\cdots \boldsymbol{g}_n]\,,\] où \[ \boldsymbol{g}_k:= \begin{pmatrix} g_{1k}\\ g_{2k}\\ \vdots\\ g_{nk} \end{pmatrix}\,. \] Comme on sait, la condition \(AG=I_n\) devient \[ \bigl[ A\boldsymbol{g}_1\cdots A\boldsymbol{g}_n \bigr] = \bigl[ \boldsymbol{e}_1\cdots \boldsymbol{e}_n \bigr]\,, \] ce qui revient à résoudre les \(n\) systèmes \[ A\boldsymbol{g}_k=\boldsymbol{e}_k\,,\quad k=1,\dots,n\,. \] Par la formule de Cramer, la \(j\)-ème composante de \(\boldsymbol{g}_k\) est donnée par \[ g_{jk}=\frac{\det(A_j(\boldsymbol{e}_k))}{\det(A)}\,. \] Or, en développant selon la \(j\)-ème colonne, \[ \det(A_j(\boldsymbol{e}_k)) =(-1)^{j+k}\cdot 1\cdot \det(A_{kj})\,, \]

ce qui implique que \[ g_{jk}=\frac{(-1)^{j+k}\det(A_{kj})}{\det(A)} =\frac{c_{kj}}{\det(A)} =\Bigl(\frac{1}{\det(A)}C^T\Bigr)_{jk}\,, \]

et démontre la formule.

Exemple: La matrice \[A= \begin{pmatrix} 2&1&3\\ 1&-1&1\\ 1&4&-2 \end{pmatrix}\,, \] est inversible puisque \(\det(A)=-14\neq 0\). Utilisons la formule pour calculer son inverse. Indiquons en rouge le signe de chaque coefficient, venant du \((-1)^{i+j}={\color{red}\pm 1}\) dans la matrice des cofacteurs.

\[\begin{aligned} A^{-1} =& \frac{1}{\det(A)}C^T\\ =\frac{1}{-14}& \begin{pmatrix} {\color{red}+}\det \begin{pmatrix} -1&1\\ 4&-2 \end{pmatrix} &{\color{red}-}\det \begin{pmatrix} 1&1\\ 1&-2 \end{pmatrix} &{\color{red}+}\det \begin{pmatrix} 1&-1\\ 1&4 \end{pmatrix} \\ {\color{red}-}\det \begin{pmatrix} 1&3\\ 4&-2 \end{pmatrix} &{\color{red}+}\det \begin{pmatrix} 2&3\\ 1&-2 \end{pmatrix} &{\color{red}-}\det \begin{pmatrix} 2&1\\ 1&4 \end{pmatrix} \\ {\color{red}+}\det \begin{pmatrix} 1&3\\ -1&1 \end{pmatrix} &{\color{red}-}\det \begin{pmatrix} 2&3\\ 1&1 \end{pmatrix} &{\color{red}+}\det \begin{pmatrix} 2&1\\ 1&-1 \end{pmatrix} \end{pmatrix}^T\\ &=\frac{1}{-14} \begin{pmatrix} -2&3&5\\ 14&-7&-7\\ 4&1&-3 \end{pmatrix}^T\\ &=\frac{1}{-14} \begin{pmatrix} -2&14&4\\ 3&-7&1\\ 5&-7&-3 \end{pmatrix}\,. \end{aligned}\]