🏠 Accueil Webclasse.fr
M

Cours : Les Matrices

L1 - Mathématiques

Diapositive 2 / 159

Nota bene : Ce cours est destiné à mes étudiants de L1 et ne couvre donc pas l'ensemble des notions sur les matrices.

Diapositive 3 / 159

Définition : Ensemble $\mathcal{M}_{n,p}$

Définition formelle
Soit $\mathbb{K}$ un corps (par exemple $\mathbb{R}$, $\mathbb{C}$, $\mathbb{Z}/2\mathbb{Z}$, etc.). On note $\mathcal{M}_{n,p}(\mathbb{K})$ l'ensemble des matrices à $n$ lignes et $p$ colonnes à coefficients dans $\mathbb{K}$. Une matrice $A \in \mathcal{M}_{n,p}(\mathbb{K})$ s'écrit :
$$ A = (a_{ij})_{\substack{1 \leq i \leq n \\ 1 \leq j \leq p}} = \begin{pmatrix} a_{11} & a_{12} & \cdots & a_{1p} \\ a_{21} & a_{22} & \cdots & a_{2p} \\ \vdots & \vdots & \ddots & \vdots \\ a_{n1} & a_{n2} & \cdots & a_{np} \end{pmatrix} $$
où $a_{ij} \in \mathbb{K}$ désigne le coefficient situé à la ligne $i$ et à la colonne $j$.

Diapositive 4 / 159

Exemple

$$ A = (a_{ij})_{\substack{1 \leq i \leq 4 \\ 1 \leq j \leq 4}} = \begin{pmatrix} 2 & 5 & 7 & 8 \\[4pt] -2,4 & -3 & 1 & 4 \\[4pt] \sqrt{2} & \frac{2}{3} & 9 & 111 \\[4pt] 0 & 1 & -7 & -10 \\[4pt] \end{pmatrix} $$
$A\in \mathcal{M}_{n,p}(\mathbb{R})$\\ On a, par exemple, $a_{23}=\dots$, $a_{44}=\dots$ et $a_{32}=\dots$.

Diapositive 5 / 159

Exemple

$$ A = (a_{ij})_{\substack{1 \leq i \leq 4 \\ 1 \leq j \leq 4}} = \begin{pmatrix} 2 & 5 & 7 & 8 \\[4pt] -2,4 & -3 & 1 & 4 \\[4pt] \sqrt{2} & \frac{2}{3} & 9 & 111 \\[4pt] 0 & 1 & -7 & -10 \\[4pt] \end{pmatrix} $$
$A\in \mathcal{M}_{n,p}(\mathbb{R})$\\ On a, par exemple, $a_{23}=1$, $a_{44}=-10$ et $a_{32}=\dfrac{2}{3}$.

Diapositive 6 / 159

Types de matrices

  • Matrices à coefficients numériques : $\mathbb{K} = \mathbb{R}$ ou $\mathbb{C}$
  • Matrices à coefficients binaires : $\mathbb{K} = \{0, 1\}$
  • Matrices à coefficients modulo 2 : $\mathbb{K} = \mathbb{Z}/2\mathbb{Z}$
Notation
Lorsque le contexte est clair, on note simplement $\mathcal{M}_{n,p}$ au lieu de $\mathcal{M}_{n,p}(\mathbb{K})$. Pour les matrices carrées ($n = p$), on note $\mathcal{M}_n(\mathbb{K})$ au lieu de $\mathcal{M}_{n,n}(\mathbb{K})$.

Diapositive 7 / 159

Propriété : Transposition de matrices

Définition
Soit $A = (a_{ij}) \in \mathcal{M}_{n,p}(\mathbb{K})$. La transposée de $A$, notée $A^T$ (ou ${}^tA$), est la matrice de $\mathcal{M}_{p,n}(\mathbb{K})$ définie par :
$$ A^T = (a_{ji})_{\substack{1 \leq j \leq p \\ 1 \leq i \leq n}} $$
Autrement dit, le coefficient de $A^T$ en position $(j,i)$ est $a_{ij}$.
Propriétés
Pour $A, B \in \mathcal{M}_{n,p}(\mathbb{K})$ et $\lambda \in \mathbb{K}$ :
  • $(A^T)^T = A$
  • $(A + B)^T = A^T + B^T$
  • $(\lambda A)^T = \lambda A^T$
Pour $A\in \mathcal{M}_{n,p}(\mathbb{K})$ et $B\in \mathcal{M}_{p,q}(\mathbb{K})$ : $(AB)^T = B^T A^T$

Diapositive 8 / 159

Exemple 1 : Transposition (matrice réelle $3 \times 2$)

$$ A = \begin{pmatrix} 1.5 & -2.3 \\ 4.0 & 0.5 \\ -1.2 & 3.7 \end{pmatrix} \in \mathcal{M}_{3,2}(\mathbb{R}) $$
$$ A^T = \dots $$

Diapositive 9 / 159

Exemple 1 : Transposition (matrice réelle $3 \times 2$)

$$ A = \begin{pmatrix} 1.5 & -2.3 \\ 4.0 & 0.5 \\ -1.2 & 3.7 \end{pmatrix} \in \mathcal{M}_{3,2}(\mathbb{R}) $$
$$ A^T = \begin{pmatrix} 1.5 & 4.0 & -1.2 \\ -2.3 & 0.5 & 3.7 \end{pmatrix} \in \mathcal{M}_{2,3}(\mathbb{R}) $$
Remarque : $a_{12} = -2.3$ devient $a_{21}^T = -2.3$, $a_{23} = 3.7$ devient $a_{32}^T = 3.7$, etc.

Diapositive 10 / 159

Exemple 2 : Transposition (matrice binaire $2 \times 4$)

$$ B = \begin{pmatrix} 1 & 0 & 1 & 1 \\ 0 & 1 & 0 & 1 \end{pmatrix} \in \mathcal{M}_{2,4}(\{0,1\}) $$
$$ B^T = \dots $$

Diapositive 11 / 159

Exemple 2 : Transposition (matrice binaire $2 \times 4$)

$$ B = \begin{pmatrix} 1 & 0 & 1 & 1 \\ 0 & 1 & 0 & 1 \end{pmatrix} \in \mathcal{M}_{2,4}(\{0,1\}) $$
$$ B^T = \begin{pmatrix} 1 & 0 \\ 0 & 1 \\ 1 & 0 \\ 1 & 1 \end{pmatrix} \in \mathcal{M}_{4,2}(\{0,1\}) $$

Diapositive 12 / 159

Exemple 3 : Transposition (matrice modulo 2, $4 \times 3$)

$$ C = \begin{pmatrix} 0 & 1 & 1 \\ 1 & 0 & 1 \\ 1 & 1 & 0 \\ 0 & 0 & 1 \end{pmatrix} \in \mathcal{M}_{4,3}(\mathbb{Z}/2\mathbb{Z}) $$
$$ C^T = \dots $$

Diapositive 13 / 159

Exemple 3 : Transposition (matrice modulo 2, $4 \times 3$)

$$ C = \begin{pmatrix} 0 & 1 & 1 \\ 1 & 0 & 1 \\ 1 & 1 & 0 \\ 0 & 0 & 1 \end{pmatrix} \in \mathcal{M}_{4,3}(\mathbb{Z}/2\mathbb{Z}) $$
$$ C^T = \begin{pmatrix} 0 & 1 & 1 & 0 \\ 1 & 0 & 1 & 0 \\ 1 & 1 & 0 & 1 \end{pmatrix} \in \mathcal{M}_{3,4}(\mathbb{Z}/2\mathbb{Z}) $$

Diapositive 14 / 159

Transposition : Implémentation Python (sans numpy)

def transpose(A):
    """
    Transpose une matrice A.
    A est une liste de listes.
    """
    if not A or not A[0]:return []
    
    n = len(A)      # nombre de lignes
    p = len(A[0])   # nombre de colonnes
    
    # Matrice transposee (p lignes, n colonnes)
    AT = []
    for j in range(p):
        ligne = []
        for i in range(n):
            ligne.append(A[i][j])
        AT.append(ligne)
    return AT

Diapositive 15 / 159

Transposition : Implémentation Python (sans numpy)

# Exemple
A = [[1.5, -2.3], [4.0, 0.5], [-1.2, 3.7]]
AT = transpose(A)
print("A^T =", AT)
# Resultat : [[1.5, 4.0, -1.2], [-2.3, 0.5, 3.7]]

Diapositive 16 / 159

Transposition : Implémentation Python (avec numpy)

import numpy as np

# Exemple 1 : matrice reelle
A = np.array([[1.5, -2.3], 
              [4.0, 0.5], 
              [-1.2, 3.7]])
AT = A.T
print("A^T =\n", AT)

# Exemple 2 : matrice binaire
B = np.array([[1, 0, 1, 1], 
              [0, 1, 0, 1]])
BT = B.T
print("\nB^T =\n", BT)

Diapositive 17 / 159

Transposition : Implémentation Python (avec numpy)

# Exemple 3 : matrice modulo 2
C = np.array([[0, 1, 1], 
              [1, 0, 1], 
              [1, 1, 0], 
              [0, 0, 1]])
CT = C.T
print("\nC^T =\n", CT)

Diapositive 18 / 159

Propriété : Addition de matrices

Définition
Soient $A = (a_{ij})$ et $B = (b_{ij})$ deux matrices de $\mathcal{M}_{n,p}(\mathbb{K})$. La somme $A + B$ est la matrice de $\mathcal{M}_{n,p}(\mathbb{K})$ définie par :
$$ A + B = (a_{ij} + b_{ij})_{\substack{1 \leq i \leq n \\ 1 \leq j \leq p}} $$
L'addition se fait coefficient par coefficient.
Propriétés
Pour $A, B, C \in \mathcal{M}_{n,p}(\mathbb{K})$ :
  • Commutativité : $A + B = B + A$
  • Associativité : $(A + B) + C = A + (B + C)$
  • Élément neutre : $A + 0_{n,p} = A$ où $0_{n,p} = (0)_{ij}$
  • Opposé : $A + (-A) = 0_{n,p}$ où $-A = (-a_{ij})$

Diapositive 19 / 159

Exemple 1 : Addition (matrices réelles $2 \times 3$)

$$ A = \begin{pmatrix} 2.5 & -1.0 & 3.2 \\ 0.5 & 4.1 & -2.3 \end{pmatrix}, \quad B = \begin{pmatrix} 1.5 & 2.0 & -1.2 \\ 3.0 & -0.1 & 1.8 \end{pmatrix} $$
$$ A + B = \begin{pmatrix} 2.5+1.5 & \dots & \dots \\ \dots & \dots & \dots \end{pmatrix} $$

Diapositive 20 / 159

Exemple 1 : Addition (matrices réelles $2 \times 3$)

$$ A = \begin{pmatrix} 2.5 & -1.0 & 3.2 \\ 0.5 & 4.1 & -2.3 \end{pmatrix}, \quad B = \begin{pmatrix} 1.5 & 2.0 & -1.2 \\ 3.0 & -0.1 & 1.8 \end{pmatrix} $$
$$ A + B = \begin{pmatrix} 2.5+1.5 & -1.0+2.0 & 3.2+(-1.2) \\ 0.5+3.0 & 4.1+(-0.1) & -2.3+1.8 \end{pmatrix} $$
$$ A + B = \begin{pmatrix} 4.0 & 1.0 & 2.0 \\ 3.5 & 4.0 & -0.5 \end{pmatrix} $$

Diapositive 21 / 159

Exemple 2 : Addition (matrices binaires $3 \times 2$)

$$ C = \begin{pmatrix} 1 & 0 \\ 1 & 1 \\ 0 & 1 \end{pmatrix}, \quad D = \begin{pmatrix} 0 & 1 \\ 1 & 0 \\ 1 & 1 \end{pmatrix} $$
Addition classique (dans $\mathbb{R}$) puis binaire :
$$ C + D = \dots $$

Diapositive 22 / 159

Exemple 2 : Addition (matrices binaires $3 \times 2$)

$$ C = \begin{pmatrix} 1 & 0 \\ 1 & 1 \\ 0 & 1 \end{pmatrix}, \quad D = \begin{pmatrix} 0 & 1 \\ 1 & 0 \\ 1 & 1 \end{pmatrix} $$
Addition classique (dans $\mathbb{R}$) puis binaire :
$$ C + D = \begin{pmatrix} 1 & 1 \\ 2 & 1 \\ 1 & 2 \end{pmatrix} = \begin{pmatrix} 1 & 1 \\ 0 & 1 \\ 1 & 0 \end{pmatrix} $$

Diapositive 23 / 159

Exemple 3 : Addition (matrices modulo 2, $3 \times 3$)

$$ E = \begin{pmatrix} 1 & 0 & 1 \\ 0 & 1 & 0 \\ 1 & 1 & 0 \end{pmatrix}, \quad F = \begin{pmatrix} 1 & 1 & 0 \\ 1 & 1 & 1 \\ 0 & 1 & 1 \end{pmatrix} $$
Addition modulo 2 (dans $\mathbb{Z}/2\mathbb{Z}$) :
$$ E + F = \dots $$
Car : $1+1 \equiv 0 \pmod{2}$, $1+0 \equiv 1 \pmod{2}$, $0+0 \equiv 0 \pmod{2}$

Diapositive 24 / 159

Exemple 3 : Addition (matrices modulo 2, $3 \times 3$)

$$ E = \begin{pmatrix} 1 & 0 & 1 \\ 0 & 1 & 0 \\ 1 & 1 & 0 \end{pmatrix}, \quad F = \begin{pmatrix} 1 & 1 & 0 \\ 1 & 1 & 1 \\ 0 & 1 & 1 \end{pmatrix} $$
Addition modulo 2 (dans $\mathbb{Z}/2\mathbb{Z}$) :
$$ E + F = \begin{pmatrix} 0 & 1 & 1 \\ 1 & 0 & 1 \\ 1 & 0 & 1 \end{pmatrix} $$
Car : $1+1 \equiv 0 \pmod{2}$, $1+0 \equiv 1 \pmod{2}$, $0+0 \equiv 0 \pmod{2}$

Diapositive 25 / 159

Addition : Implémentation Python (sans numpy)

def addition(A, B, modulo=None):
    """
    Additionne deux matrices A et B.
    Si modulo est specifie, effectue l'addition modulo
    """
    n = len(A)
    p = len(A[0])
    
    C = []
    for i in range(n):
        ligne = []
        for j in range(p):
            somme = A[i][j] + B[i][j]
            if modulo is not None:
                somme = somme % modulo
            ligne.append(somme)
        C.append(ligne)
    return C

Diapositive 26 / 159

Addition : Implémentation Python (sans numpy)

# Exemple modulo 2
E = [[1, 0, 1], [0, 1, 0], [1, 1, 0]]
F = [[1, 1, 0], [1, 1, 1], [0, 1, 1]]
EplusF = addition(E, F, modulo=2)
print("E + F (mod 2) =", EplusF)

Diapositive 27 / 159

Addition : Implémentation Python (avec numpy)

import numpy as np

# Exemple 1 : matrices reelles
A = np.array([[2.5, -1.0, 3.2], 
              [0.5, 4.1, -2.3]])
B = np.array([[1.5, 2.0, -1.2], 
              [3.0, -0.1, 1.8]])
C = A + B
print("A + B =\n", C)

# Exemple 2 : matrices binaires
C = np.array([[1, 0], [1, 1], [0, 1]])
D = np.array([[0, 1], [1, 0], [1, 1]])
CD = C + D
print("\nC + D =\n", CD)

Diapositive 28 / 159

Addition : Implémentation Python (avec numpy)

# Exemple 3 : matrices modulo 2
E = np.array([[1, 0, 1], [0, 1, 0], [1, 1, 0]])
F = np.array([[1, 1, 0], [1, 1, 1], [0, 1, 1]])
EF = (E + F) % 2
print("\nE + F (mod 2) =\n", EF)

Diapositive 29 / 159

Propriété : Produit de matrices

Définition
Soient $A = (a_{ik}) \in \mathcal{M}_{n,p}(\mathbb{K})$ et $B = (b_{kj}) \in \mathcal{M}_{p,q}(\mathbb{K})$. Le produit $AB$ est la matrice de $\mathcal{M}_{n,q}(\mathbb{K})$ définie par :
$$ AB = (c_{ij})_{\substack{1 \leq i \leq n \\ 1 \leq j \leq q}} $$
$$ c_{ij} = \sum_{k=1}^{p} a_{ik} \cdot b_{kj} $$
Condition
Le produit $AB$ n'est défini que si le nombre de colonnes de $A$ est égal au nombre de lignes de $B$.

Diapositive 30 / 159

Propriétés du produit matriciel

Propriétés
Lorsque les produits sont définis :
  • Associativité : $(AB)C = A(BC)$
  • Distributivité : $A(B+C) = AB + AC$ et $(A+B)C = AC + BC$
  • Élément neutre : $I_n A = A I_p = A$ où $I_n$ est la matrice identité
  • Non-commutativité : En général, $AB \neq BA$
  • Transposition : $(AB)^T = B^T A^T$
Matrice identité
La matrice identité $I_n \in \mathcal{M}_n(\mathbb{K})$ est définie par :
$$ I_n = (\delta_{ij}) \text{ où } \delta_{ij} = \begin{cases} 1 & \text{si } i = j \\ 0 & \text{sinon} \end{cases} $$

Diapositive 31 / 159

Exemple 1 : Produit (matrices réelles $2 \times 3$ et $3 \times 2$)

$$ A = \begin{pmatrix} 1 & 2 & 3 \\ 4 & 5 & 6 \end{pmatrix} \in \mathcal{M}_{2,3}(\mathbb{R}), \quad B = \begin{pmatrix} 1 & 2 \\ 0 & 1 \\ -1 & 0 \end{pmatrix} \in \mathcal{M}_{3,2}(\mathbb{R}) $$
Disposition pratique :
$$\begin{array}{c|cc} & \begin{pmatrix} 1 \quad\quad\quad\quad\quad\quad\quad\quad\quad\quad& 2 \\ 0 \quad\quad\quad\quad\quad\quad\quad\quad\quad\quad& 1 \\ -1 \quad\quad\quad\quad\quad\quad\quad\quad\quad\quad& 0 \end{pmatrix}\\ \hline \begin{pmatrix} 1 & 2 & 3 \\ 4 & 5 & 6 \end{pmatrix}& \begin{pmatrix} { 1\times 1 + 2\times 0 + 3\times (-1)}& \dots \\ \dots & \dots \end{pmatrix} \end{array}$$
$$ A\times B=AB =\dots \in \mathcal{M}_{2,2}(\mathbb{R}) $$

Diapositive 32 / 159

Exemple 1 : Produit (matrices réelles $2 \times 3$ et $3 \times 2$)

$$ A = \begin{pmatrix} 1 & 2 & 3 \\ 4 & 5 & 6 \end{pmatrix} \in \mathcal{M}_{2,3}(\mathbb{R}), \quad B = \begin{pmatrix} 1 & 2 \\ 0 & 1 \\ -1 & 0 \end{pmatrix} \in \mathcal{M}_{3,2}(\mathbb{R}) $$
Disposition pratique :
$$\begin{array}{c|cc} & \begin{pmatrix} 1 & 2 \\ 0 & 1 \\ -1 & 0 \end{pmatrix}\\ \hline \begin{pmatrix} 1 & 2 & 3 \\ 4 & 5 & 6 \end{pmatrix}& \begin{pmatrix} -2 & 4 \\ -2 & 13 \end{pmatrix} \end{array}$$
$$ AB = \begin{pmatrix} -2 & 4 \\ -2 & 13 \end{pmatrix} \in \mathcal{M}_{2,2}(\mathbb{R}) $$

Diapositive 33 / 159

Exemple 2 : Produit (matrices binaires $3 \times 2$ et $2 \times 3$)

$$ C = \begin{pmatrix} 1 & 0 \\ 1 & 1 \\ 0 & 1 \end{pmatrix} \in \mathcal{M}_{3,2}(\{0,1\}), \quad D = \begin{pmatrix} 1 & 1 & 0 \\ 0 & 1 & 1 \end{pmatrix} \in \mathcal{M}_{2,3}(\{0,1\}) $$
Disposition pratique :
$$\begin{array}{c|ccc} & \begin{pmatrix} 1 & 1 & 0 \\ 0 & 1 & 1 \end{pmatrix}\\ \hline \begin{pmatrix} 1 & 0 \\ 1 & 1 \\ 0 & 1 \end{pmatrix}& \\ \end{array}$$
$$ CD = \dots $$

Diapositive 34 / 159

Exemple 2 : Produit (matrices binaires $3 \times 2$ et $2 \times 3$)

$$ C = \begin{pmatrix} 1 & 0 \\ 1 & 1 \\ 0 & 1 \end{pmatrix} \in \mathcal{M}_{3,2}(\{0,1\}), \quad D = \begin{pmatrix} 1 & 1 & 0 \\ 0 & 1 & 1 \end{pmatrix} \in \mathcal{M}_{2,3}(\{0,1\}) $$
Disposition pratique :
$$\begin{array}{c|ccc} & \begin{pmatrix} 1 & 1 & 0 \\ 0 & 1 & 1 \end{pmatrix}\\ \hline \begin{pmatrix} 1 & 0 \\ 1 & 1 \\ 0 & 1 \end{pmatrix}&\begin{pmatrix} 1 & 1 & 0 \\ 1 & 2 & 1 \\ 0 & 1 & 1 \end{pmatrix} \\ \end{array}$$
$$ CD = \begin{pmatrix} 1 & 1 & 0 \\ 1 & 2 & 1 \\ 0 & 1 & 1 \end{pmatrix}=\begin{pmatrix} 1 & 1 & 0 \\ 1 & 0 & 1 \\ 0 & 1 & 1 \end{pmatrix} $$

Diapositive 35 / 159

Exemple 3 : Produit (matrices mod 2, $2 \times 3$ et $3 \times 2$)

$$ E = \begin{pmatrix} 1 & 0 & 1 \\ 1 & 1 & 0 \end{pmatrix} \in \mathcal{M}_{2,3}(\mathbb{Z}/2\mathbb{Z}), \quad F = \begin{pmatrix} 0 & 1 \\ 1 & 1 \\ 1 & 0 \end{pmatrix} \in \mathcal{M}_{3,2}(\mathbb{Z}/2\mathbb{Z}) $$
Disposition pratique ( mod 2) :
$$\begin{array}{cc} & \begin{pmatrix} 0 & 1 \\ 1 & 1 \\ 1 & 0 \end{pmatrix}\\ \begin{pmatrix} 1 & 0 & 1 \\ 1 & 1 & 0 \end{pmatrix}&\begin{pmatrix} \dots & \dots \\ \dots & \dots \end{pmatrix} \\ \end{array}$$
$$ EF = \dots \pmod{2} $$

Diapositive 36 / 159

Exemple 3 : Produit (matrices mod 2, $2 \times 3$ et $3 \times 2$)

$$ E = \begin{pmatrix} 1 & 0 & 1 \\ 1 & 1 & 0 \end{pmatrix} \in \mathcal{M}_{2,3}(\mathbb{Z}/2\mathbb{Z}), \quad F = \begin{pmatrix} 0 & 1 \\ 1 & 1 \\ 1 & 0 \end{pmatrix} \in \mathcal{M}_{3,2}(\mathbb{Z}/2\mathbb{Z}) $$
Disposition pratique ( mod 2) :
$$\begin{array}{cc} & \begin{pmatrix} 0 & 1 \\ 1 & 1 \\ 1 & 0 \end{pmatrix}\\ \begin{pmatrix} 1 & 0 & 1 \\ 1 & 1 & 0 \end{pmatrix}&\begin{pmatrix} 1 & 1 \\ 1 & 0 \end{pmatrix} \\ \end{array}$$
$$ EF = \begin{pmatrix} 1 & 1 \\ 1 & 0 \end{pmatrix} \pmod{2} $$

Diapositive 37 / 159

Produit : Implémentation Python (sans numpy)

def produit(A, B, modulo=None):
    """
    Calcule le produit de deux matrices A et B.
    """
    n = len(A)      # lignes de A
    p = len(A[0])   # colonnes de A = lignes de B
    q = len(B[0])   # colonnes de B
    C = []
    for i in range(n):
        ligne = []
        for j in range(q):
            somme = 0
            for k in range(p):
                somme += A[i][k] * B[k][j]
            if modulo is not None:
                somme = somme % modulo
            ligne.append(somme)
        C.append(ligne)
    return C

Diapositive 38 / 159

Produit : Implémentation Python (sans numpy)

# Exemple
E = [[1, 0, 1], [1, 1, 0]]
F = [[0, 1], [1, 1], [1, 0]]
EF = produit(E, F, modulo=2)
print("EF (mod 2) =", EF)

Diapositive 39 / 159

Produit : Implémentation Python (avec numpy)

import numpy as np
# Exemple 1 : matrices reelles
A = np.array([[1, 2, 3], [4, 5, 6]])
B = np.array([[1, 2], [0, 1], [-1, 0]])
AB = np.dot(A, B)  # ou A @ B
print("AB =\n", AB)

# Exemple 2 : matrices binaires
C = np.array([[1, 0], [1, 1], [0, 1]])
D = np.array([[1, 1, 0], [0, 1, 1]])
CD = np.dot(C, D)
print("\nCD =\n", CD)

# Exemple 3 : matrices modulo 2
E = np.array([[1, 0, 1], [1, 1, 0]])
F = np.array([[0, 1], [1, 1], [1, 0]])
EF = np.dot(E, F) % 2
print("\nEF (mod 2) =\n", EF)

Diapositive 40 / 159

Propriété : Multiplication par un scalaire

Définition
Soit $A = (a_{ij}) \in \mathcal{M}_{n,p}(\mathbb{K})$ et $\lambda \in \mathbb{K}$. Le produit scalaire $\lambda A$ est la matrice de $\mathcal{M}_{n,p}(\mathbb{K})$ définie par :
$$ \lambda A = (\lambda \cdot a_{ij})_{\substack{1 \leq i \leq n \\ 1 \leq j \leq p}} $$
Propriétés
Pour $A, B \in \mathcal{M}_{n,p}(\mathbb{K})$ et $\lambda, \mu \in \mathbb{K}$ :
  • $\lambda(A + B) = \lambda A + \lambda B$
  • $(\lambda + \mu)A = \lambda A + \mu A$
  • $(\lambda \mu)A = \lambda(\mu A)$
  • $1 \cdot A = A$
  • $\lambda(AB) = (\lambda A)B = A(\lambda B)$

Diapositive 41 / 159

Exemple 1 : Multiplication scalaire (matrice réelle $2 \times 3$)

$$ \lambda = 2.5, \quad A = \begin{pmatrix} 4 & -2 & 6 \\ 0 & 8 & -4 \end{pmatrix} $$
$$ \lambda A = 2.5 \times \begin{pmatrix} 4 & -2 & 6 \\ 0 & 8 & -4 \end{pmatrix} $$
$$ \lambda A = \begin{pmatrix} 10 & -5 & 15 \\ 0 & 20 & -10 \end{pmatrix} $$

Diapositive 42 / 159

Exemple 2 : Multiplication scalaire (mat. binaire $3 \times 2$)

$$ \lambda = 0, \quad B = \begin{pmatrix} 1 & 1 \\ 0 & 1 \\ 1 & 0 \end{pmatrix} $$
$$ \lambda B = 0 \times \begin{pmatrix} 1 & 1 \\ 0 & 1 \\ 1 & 0 \end{pmatrix} = \begin{pmatrix} 0 & 0 \\ 0 & 0 \\ 0 & 0 \end{pmatrix} $$
La multiplication par 0 donne la matrice nulle.

Diapositive 43 / 159

Exemple 3 : Multiplication scalaire (mat. mod 2, $2 \times 4$)

$$ \lambda = 1, \quad C = \begin{pmatrix} 1 & 0 & 1 & 1 \\ 0 & 1 & 0 & 1 \end{pmatrix} \in \mathcal{M}_{2,4}(\mathbb{Z}/2\mathbb{Z}) $$
$$ \lambda C = 1 \times \begin{pmatrix} 1 & 0 & 1 & 1 \\ 0 & 1 & 0 & 1 \end{pmatrix} = \begin{pmatrix} 1 & 0 & 1 & 1 \\ 0 & 1 & 0 & 1 \end{pmatrix} $$
Note : Dans $\mathbb{Z}/2\mathbb{Z}$, les seuls scalaires sont 0 et 1.

Diapositive 44 / 159

Multiplication scalaire : Implémentation Python (sans numpy)

def mult_scalaire(lambda_val, A, modulo=None):
    """
    Multiplie une matrice A par un scalaire lambda_val.
    """
    n = len(A)
    p = len(A[0])
    
    C = []
    for i in range(n):
        ligne = []
        for j in range(p):
            produit = lambda_val * A[i][j]
            if modulo is not None:
                produit = produit % modulo
            ligne.append(produit)
        C.append(ligne)
    return C

Diapositive 45 / 159

Multiplication scalaire : Implémentation Python (sans numpy)

# Exemple 1
A = [[4, -2, 6], [0, 8, -4]]
lambda_A = mult_scalaire(2.5, A)
print("2.5 * A =", lambda_A)

# Exemple 2 (modulo 2)
C = [[1, 0, 1, 1], [0, 1, 0, 1]]
lambda_C = mult_scalaire(1, C, modulo=2)
print("1 * C (mod 2) =", lambda_C)

Diapositive 46 / 159

Multiplication scalaire : Implémentation Python (avec numpy)

import numpy as np
# Exemple 1 : matrice reelle
A = np.array([[4, -2, 6], 
              [0, 8, -4]])
lambda_A = 2.5 * A
print("2.5 * A =\n", lambda_A)
# Exemple 2 : matrice binaire (mult par 0)
B = np.array([[1, 1], 
              [0, 1], 
              [1, 0]])
lambda_B = 0 * B
print("\n0 * B =\n", lambda_B)
# Exemple 3 : matrice modulo 2
C = np.array([[1, 0, 1, 1], 
              [0, 1, 0, 1]])
lambda_C = (1 * C) % 2
print("\n1 * C (mod 2) =\n", lambda_C)

Diapositive 47 / 159

Propriété : Définition d'un espace vectoriel

Définition
Un ensemble $E$ est un espace vectoriel sur un corps $\mathbb{K}$ s'il est muni de deux opérations satisfaisant 8 axiomes :
Pour l'addition :
  1. Associativité\\ $\vec{u}+(\vec{v}+\vec{w})=(\vec{u}+\vec{v})+\vec{w}$
  2. Commutativité $\vec{u}+\vec{v}=\vec{v}+\vec{u}$
  3. Élément neutre $\vec{0}$ $\vec{u}+\vec{0}=\vec{0}+\vec{u}=\vec{u}$
  4. Opposé $\vec{u}-\vec{u}=\vec{0}$
Pour la multiplication scalaire :
  1. $1 \cdot \vec{u} = \vec{u}$
  2. $\lambda(\mu \vec{u}) = (\lambda\mu)\vec{u}$
  3. $(\lambda+\mu)\vec{u} = \lambda\vec{u} + \mu\vec{u}$
  4. $\lambda(\vec{u}+\vec{v}) = \lambda\vec{u} + \lambda\vec{v}$

Diapositive 48 / 159

Exemple 1 : $\mathbb{R}^2$ comme espace vectoriel

Ensemble : $\mathbb{R}^2 = \{(x, y) \mid x, y \in \mathbb{R}\}$ Addition :
$$ (x_1, y_1) + (x_2, y_2) = (x_1 + x_2, y_1 + y_2) $$
Exemple numérique : $(3, 2) + (1, -4) = (4, -2)$ Multiplication scalaire :
$$ \lambda \cdot (x, y) = (\lambda x, \lambda y) $$
Exemple numérique : $2 \cdot (3, -1) = (6, -2)$

Diapositive 49 / 159

Exemple 2 : Espace des polynômes $\mathbb{R}_2[X]$

Ensemble : $\mathbb{R}_2[X] = \{a_0 + a_1X + a_2X^2 \mid a_0, a_1, a_2 \in \mathbb{R}\}$ Addition :
$$ P(X) + Q(X) = (a_0 + b_0) + (a_1 + b_1)X + (a_2 + b_2)X^2 $$
Exemple : $(2 + 3X - X^2) + (1 - X + 2X^2) = 3 + 2X + X^2$ Multiplication scalaire :
$$ \lambda \cdot (a_0 + a_1X + a_2X^2) = \lambda a_0 + \lambda a_1X + \lambda a_2X^2 $$
Exemple : $3 \cdot (1 + 2X - X^2) = 3 + 6X - 3X^2$

Diapositive 50 / 159

Exemple 3 : Espace $\mathcal{M}_{2,2}(\mathbb{R})$

Ensemble : Matrices $2 \times 2$ à coefficients réels Addition :
$$ \begin{pmatrix} a & b \\ c & d \end{pmatrix} + \begin{pmatrix} a' & b' \\ c' & d' \end{pmatrix} = \begin{pmatrix} a+a' & b+b' \\ c+c' & d+d' \end{pmatrix} $$
Exemple :
$$ \begin{pmatrix} 1 & 2 \\ 3 & 4 \end{pmatrix} + \begin{pmatrix} 5 & 6 \\ 7 & 8 \end{pmatrix} = \begin{pmatrix} 6 & 8 \\ 10 & 12 \end{pmatrix} $$
Multiplication scalaire :
$$ 2 \begin{pmatrix} 1 & -1 \\ 0 & 3 \end{pmatrix} = \begin{pmatrix} 2 & -2 \\ 0 & 6 \end{pmatrix} $$

Diapositive 51 / 159

Propriété : Structure d'espace vectoriel

Théorème
L'ensemble $\mathcal{M}_{n,p}(\mathbb{K})$ muni de l'addition matricielle et de la multiplication par un scalaire forme un espace vectoriel sur $\mathbb{K}$. Sa dimension est $\dim(\mathcal{M}_{n,p}(\mathbb{K})) = n \times p$.

Diapositive 52 / 159

Propriété : Structure d'espace vectoriel

Base canonique
Une base canonique de $\mathcal{M}_{n,p}(\mathbb{K})$ est constituée des matrices $E_{ij}$ définies par :
$$ E_{ij} = (e_{kl}) \text{ où } e_{kl} = \begin{cases} 1 & \text{si } k=i \text{ et } l=j \\ 0 & \text{sinon} \end{cases} $$
Toute matrice $A = (a_{ij})$ s'écrit :
$$ A = \sum_{i=1}^{n} \sum_{j=1}^{p} a_{ij} E_{ij} $$

Diapositive 53 / 159

Exemple 1 : Base canonique ($\mathcal{M}_{2,2}(\mathbb{R})$)

Les 4 matrices de base de $\mathcal{M}_{2,2}(\mathbb{R})$ sont :
$$ E_{11} = \begin{pmatrix} 1 & 0 \\ 0 & 0 \end{pmatrix}, \quad E_{12} = \begin{pmatrix} 0 & 1 \\ 0 & 0 \end{pmatrix} $$
$$ E_{21} = \begin{pmatrix} 0 & 0 \\ 1 & 0 \end{pmatrix}, \quad E_{22} = \begin{pmatrix} 0 & 0 \\ 0 & 1 \end{pmatrix} $$
Exemple de décomposition :
$$ \begin{pmatrix} 3 & -2 \\ 5 & 1 \end{pmatrix} = 3E_{11} - 2E_{12} + 5E_{21} + 1E_{22} $$

Diapositive 54 / 159

Exemple 2 : Base canonique ($\mathcal{M}_{2,3}(\{0,1\})$)

Les 6 matrices de base de $\mathcal{M}_{2,3}$ sont :
$$ E_{11} = \begin{pmatrix} 1 & 0 & 0 \\ 0 & 0 & 0 \end{pmatrix}, \; E_{12} = \begin{pmatrix} 0 & 1 & 0 \\ 0 & 0 & 0 \end{pmatrix}, \; E_{13} = \begin{pmatrix} 0 & 0 & 1 \\ 0 & 0 & 0 \end{pmatrix} $$
$$ E_{21} = \begin{pmatrix} 0 & 0 & 0 \\ 1 & 0 & 0 \end{pmatrix}, \; E_{22} = \begin{pmatrix} 0 & 0 & 0 \\ 0 & 1 & 0 \end{pmatrix}, \; E_{23} = \begin{pmatrix} 0 & 0 & 0 \\ 0 & 0 & 1 \end{pmatrix} $$
Exemple :
$$ \begin{pmatrix} 1 & 0 & 1 \\ 0 & 1 & 1 \end{pmatrix} = E_{11} + E_{13} + E_{22} + E_{23} $$

Diapositive 55 / 159

Exemple 3 : Base canonique ($\mathcal{M}_{3,1}(\mathbb{Z}/2\mathbb{Z})$)

Les 3 matrices de base de $\mathcal{M}_{3,1}$ (vecteurs colonnes) sont :
$$ E_{11} = \begin{pmatrix} 1 \\ 0 \\ 0 \end{pmatrix}, \quad E_{21} = \begin{pmatrix} 0 \\ 1 \\ 0 \end{pmatrix}, \quad E_{31} = \begin{pmatrix} 0 \\ 0 \\ 1 \end{pmatrix} $$
Exemple de décomposition (modulo 2) :
$$ \begin{pmatrix} 1 \\ 1 \\ 0 \end{pmatrix} = 1 \cdot E_{11} + 1 \cdot E_{21} + 0 \cdot E_{31} $$

Diapositive 56 / 159

Base canonique : Implémentation Python (sans numpy)

def matrice_base(n, p, i, j):
    """
    Cree la matrice de base E_ij de M_n,p.
    """
    E = []
    for k in range(n):
        ligne = []
        for l in range(p):
            if k == i and l == j:
                ligne.append(1)
            else:
                ligne.append(0)
        E.append(ligne)
    return E

def decomposition(A):
    """
    Decompose A sur la base canonique.
    """
    n = len(A)
    p = len(A[0])
    decomp = []
    for i in range(n):
        for j in range(p):
            if A[i][j] != 0:
                decomp.append((A[i][j], i, j))
    return decomp

# Exemple
A = [[3, -2], [5, 1]]
dec = decomposition(A)
print("Decomposition :", dec)

Diapositive 57 / 159

Base canonique : Implémentation Python (avec numpy)

import numpy as np

def matrice_base_np(n, p, i, j):
    """
    Cree la matrice de base E_ij de M_n,p.
    """
    E = np.zeros((n, p))
    E[i, j] = 1
    return E

# Exemple 1 : Base de M_2,2
E11 = matrice_base_np(2, 2, 0, 0)
E12 = matrice_base_np(2, 2, 0, 1)
E21 = matrice_base_np(2, 2, 1, 0)
E22 = matrice_base_np(2, 2, 1, 1)

Diapositive 58 / 159

Base canonique : Implémentation Python (avec numpy)

# Decomposition d'une matrice
A = np.array([[3, -2], [5, 1]])
print("A =\n", A)
print("\nA = 3*E11 - 2*E12 + 5*E21 + 1*E22")
verif = 3*E11 - 2*E12 + 5*E21 + 1*E22
print("\nVerification :\n", verif)

Diapositive 59 / 159

Propriété : Matrices carrées particulières

Définitions
Pour $A \in \mathcal{M}_n(\mathbb{K})$ : Matrice diagonale : $a_{ij} = 0$ si $i \neq j$
$$ D = \begin{pmatrix} d_1 & 0 & \cdots & 0 \\ 0 & d_2 & \cdots & 0 \\ \vdots & \vdots & \ddots & \vdots \\ 0 & 0 & \cdots & d_n \end{pmatrix} $$
Matrice triangulaire supérieure : $a_{ij} = 0$ si $i > j$ Matrice triangulaire inférieure : $a_{ij} = 0$ si $i < j$ Matrice symétrique : $A^T = A$ (donc $a_{ij} = a_{ji}$) Matrice antisymétrique : $A^T = -A$ (donc $a_{ij} = -a_{ji}$ et $a_{ii} = 0$)

Diapositive 60 / 159

Exemple 1 : Matrices particulières (réelles $3 \times 3$)

Matrice diagonale :
$$ D = \begin{pmatrix} 2 & 0 & 0 \\ 0 & -3 & 0 \\ 0 & 0 & 5 \end{pmatrix} $$
Matrice triangulaire supérieure :
$$ U = \begin{pmatrix} 1 & 4 & 7 \\ 0 & 2 & 5 \\ 0 & 0 & 3 \end{pmatrix} $$
Matrice symétrique :
$$ S = \begin{pmatrix} 1 & 2 & 3 \\ 2 & 4 & 5 \\ 3 & 5 & 6 \end{pmatrix} $$

Diapositive 61 / 159

Exemple 2 : Matrices particulières (binaires $3 \times 3$)

Matrice diagonale :
$$ D = \begin{pmatrix} 1 & 0 & 0 \\ 0 & 0 & 0 \\ 0 & 0 & 1 \end{pmatrix} $$
Matrice triangulaire inférieure :
$$ L = \begin{pmatrix} 1 & 0 & 0 \\ 1 & 1 & 0 \\ 0 & 1 & 1 \end{pmatrix} $$
Matrice symétrique :
$$ S = \begin{pmatrix} 0 & 1 & 1 \\ 1 & 0 & 1 \\ 1 & 1 & 0 \end{pmatrix} $$

Diapositive 62 / 159

Exemple 3 : Matrices particulières (mod 2, $4 \times 4$)

Matrice diagonale :
$$ D = \begin{pmatrix} 1 & 0 & 0 & 0 \\ 0 & 1 & 0 & 0 \\ 0 & 0 & 0 & 0 \\ 0 & 0 & 0 & 1 \end{pmatrix} $$
Matrice triangulaire supérieure :
$$ U = \begin{pmatrix} 1 & 1 & 0 & 1 \\ 0 & 1 & 1 & 0 \\ 0 & 0 & 1 & 1 \\ 0 & 0 & 0 & 0 \end{pmatrix} $$

Diapositive 63 / 159

Matrices particulières : Implémentation Python (sans numpy)

def est_diagonale(A):
    """Verifie si A est diagonale."""
    n = len(A)
    for i in range(n):
        for j in range(len(A[0])):
            if i != j and A[i][j] != 0:
                return False
    return True

def est_symetrique(A):
    """Verifie si A est symetrique."""
    n = len(A)
    if n != len(A[0]):
        return False
    for i in range(n):
        for j in range(n):
            if A[i][j] != A[j][i]:
                return False
    return True

Diapositive 64 / 159

Matrices particulières : Implémentation Python (sans numpy)

# Exemple
S = [[1, 2, 3], [2, 4, 5], [3, 5, 6]]
print("S est symetrique :", est_symetrique(S))

D = [[2, 0, 0], [0, -3, 0], [0, 0, 5]]
print("D est diagonale :", est_diagonale(D))

Diapositive 65 / 159

Matrices particulières : Implémentation Python (avec numpy)

import numpy as np
# Creation de matrices particulieres
D = np.diag([2, -3, 5])  # Matrice diagonale
print("Matrice diagonale D :\n", D)
# Matrice triangulaire superieure
U = np.triu([[1, 4, 7], [8, 2, 5], [9, 6, 3]])
print("\nMatrice triangulaire sup. U :\n", U)
# Test de symetrie
S = np.array([[1, 2, 3], [2, 4, 5], [3, 5, 6]])
est_sym = np.allclose(S, S.T)
print("\nS est symetrique :", est_sym)
# Matrice antisymetrique
A = np.array([[0, 1, -2], [-1, 0, 3], [2, -3, 0]])
est_antisym = np.allclose(A, -A.T)
print("A est antisymetrique :", est_antisym)

Diapositive 66 / 159

Propriété : Trace d'une matrice

Définition
Soit $A = (a_{ij}) \in \mathcal{M}_n(\mathbb{K})$ une matrice carrée. La trace de $A$, notée $\text{tr}(A)$, est la somme des éléments diagonaux :
$$ \text{tr}(A) = \sum_{i=1}^{n} a_{ii} = a_{11} + a_{22} + \cdots + a_{nn} $$

Diapositive 67 / 159

Propriété : Trace d'une matrice

Propriétés
Pour $A, B \in \mathcal{M}_n(\mathbb{K})$ et $\lambda \in \mathbb{K}$ :
  • $\text{tr}(A + B) = \text{tr}(A) + \text{tr}(B)$
  • $\text{tr}(\lambda A) = \lambda \cdot \text{tr}(A)$
  • $\text{tr}(AB) = \text{tr}(BA)$
  • $\text{tr}(A^T) = \text{tr}(A)$
  • $\text{tr}(I_n) = n$

Diapositive 68 / 159

Exemple 1 : Trace (matrice réelle $3 \times 3$)

$$ A = \begin{pmatrix} 5 & 2 & -1 \\ 3 & -4 & 7 \\ 0 & 6 & 2 \end{pmatrix} $$
$$ \text{tr}(A) = a_{11} + a_{22} + a_{33} = 5 + (-4) + 2 = 3 $$
Les éléments non-diagonaux (2, -1, 3, 7, 0, 6) ne contribuent pas à la trace.

Diapositive 69 / 159

Exemple 2 : Trace (matrice binaire $4 \times 4$)

$$ B = \begin{pmatrix} 1 & 0 & 1 & 1 \\ 0 & 1 & 0 & 1 \\ 1 & 1 & 0 & 0 \\ 0 & 1 & 1 & 1 \end{pmatrix} $$
$$ \text{tr}(B) = \dots $$

Diapositive 70 / 159

Exemple 2 : Trace (matrice binaire $4 \times 4$)

$$ B = \begin{pmatrix} 1 & 0 & 1 & 1 \\ 0 & 1 & 0 & 1 \\ 1 & 1 & 0 & 0 \\ 0 & 1 & 1 & 1 \end{pmatrix} $$
$$ \text{tr}(B) = b_{11} + b_{22} + b_{33} + b_{44} = 1 + 1 + 0 + 1 = 3 = 1 $$

Diapositive 71 / 159

Exemple 3 : Trace (matrice mod 2, $3 \times 3$)

$$ C = \begin{pmatrix} 1 & 0 & 1 \\ 1 & 1 & 0 \\ 0 & 1 & 1 \end{pmatrix} \in \mathcal{M}_3(\mathbb{Z}/2\mathbb{Z}) $$
Calcul classique :
$$ \text{tr}(C) = 1 + 1 + 1 = 3 $$
Modulo 2 :
$$ \text{tr}(C) \equiv 3 \equiv 1 \pmod{2} $$

Diapositive 72 / 159

Trace : Implémentation Python (sans numpy)

def trace(A, modulo=None):
    """
    Calcule la trace d'une matrice carree A.
    """
    n = len(A)
    tr = 0
    for i in range(n):
        tr += A[i][i]
    
    if modulo is not None:
        tr = tr % modulo
    
    return tr

Diapositive 73 / 159

Trace : Implémentation Python (sans numpy)

# Exemple 1
A = [[5, 2, -1], [3, -4, 7], [0, 6, 2]]
print("tr(A) =", trace(A))

# Exemple 2
B = [[1, 0, 1, 1], [0, 1, 0, 1], 
     [1, 1, 0, 0], [0, 1, 1, 1]]
print("tr(B) =", trace(B))

# Exemple 3 (modulo 2)
C = [[1, 0, 1], [1, 1, 0], [0, 1, 1]]
print("tr(C) mod 2 =", trace(C, modulo=2))

Diapositive 74 / 159

Trace : Implémentation Python (avec numpy)

import numpy as np

# Exemple 1 : matrice reelle
A = np.array([[5, 2, -1], 
              [3, -4, 7], 
              [0, 6, 2]])
tr_A = np.trace(A)
print("tr(A) =", tr_A)

# Exemple 2 : matrice binaire
B = np.array([[1, 0, 1, 1], 
              [0, 1, 0, 1], 
              [1, 1, 0, 0], 
              [0, 1, 1, 1]])
tr_B = np.trace(B)
print("tr(B) =", tr_B)

Diapositive 75 / 159

Trace : Implémentation Python (avec numpy)

# Exemple 3 : matrice modulo 2
C = np.array([[1, 0, 1], 
              [1, 1, 0], 
              [0, 1, 1]])
tr_C = np.trace(C) % 2
print("tr(C) mod 2 =", tr_C)

Diapositive 76 / 158

Récapitulatif des opérations

Opération Notation Dimensions
Transposition $A^T$ $\mathcal{M}_{n,p} \to \mathcal{M}_{p,n}$
Addition $A + B$ $\mathcal{M}_{n,p} \times \mathcal{M}_{n,p} \to \mathcal{M}_{n,p}$
Mult. scalaire $\lambda A$ $\mathbb{K} \times \mathcal{M}_{n,p} \to \mathcal{M}_{n,p}$
Produit $AB$ $\mathcal{M}_{n,p} \times \mathcal{M}_{p,q} \to \mathcal{M}_{n,q}$
Trace $\text{tr}(A)$ $\mathcal{M}_n \to \mathbb{K}$

Diapositive 77 / 159

Récapitulatif des opérations

Points clés
  • Les dimensions doivent être compatibles
  • Le produit matriciel n'est pas commutatif
  • $\mathcal{M}_{n,p}(\mathbb{K})$ est un espace vectoriel de dimension $n \times p$
  • Les opérations se généralisent à tout corps $\mathbb{K}$

Diapositive 78 / 159

Applications et prolongements

  • Systèmes linéaires, vu à la suite : $AX = B$
  • Transformations géométriques : rotations, homothéties, projections
  • Graphes vus, en seconde partie : matrices d'adjacence, matrices d'incidence
  • Cryptographie : chiffrement matriciel (Hill)
  • Codes correcteurs : matrices génératrices modulo 2
  • Théorie des jeux : matrices de gains
  • Analyse numérique : résolution de systèmes, valeurs propres
  • Apprentissage automatique : représentation des données

Diapositive 79 / 159

Propriété : Inverse d'une matrice

Définition
Une matrice $A \in \mathcal{M}_n(\mathbb{K})$ est inversible s'il existe $B \in \mathcal{M}_n(\mathbb{K})$ telle que :
$$ AB = BA = I_n $$
On note alors $B = A^{-1}$ l'inverse de $A$.
Remarque
On a donc lorsque la matrice $A$ existe :
$$ A\times A^{-1} = A^{-1}\times A = I_n $$
Et la matrice $A$ est nécessairement carrée.

Diapositive 80 / 159

Exemple 1 : matrice $2 \times 2$

Soit la matrice $ A = \begin{pmatrix} 1 & 2 \\ 3 & 4 \end{pmatrix} $ Vérifier que $A^{-1}=\begin{pmatrix} -2 & 1 \\ \frac{3}{2} & -\frac{1}{2} \end{pmatrix}$ Autrement dit calculer $M\times M^{-1}$ et $M^{-1}\times M$.

Diapositive 81 / 159

Exemple 1 : matrice $3 \times 3$

Soit la matrice $ M = \begin{pmatrix} 1 & 2 & 3 \\ 0 & 1 & 4 \\ 5 & 6 & 0 \end{pmatrix} $ Vérifier que $M^{-1} = \begin{pmatrix} -24 & 18 & 5 \\ 20 & -15 & -4 \\ -5 & 4 & 1 \end{pmatrix}$ Autrement dit calculer $A\times A^{-1}$ et $A^{-1}\times A$.

Diapositive 82 / 159

Exemple 3: matrice $2 \times 2$ non inversible

Soit la matrice $ A = \begin{pmatrix} 0 & 2 \\ 0 & 0 \end{pmatrix} $ Vérifier que pour toute matrice $ B = \begin{pmatrix} a & b \\ c & d \end{pmatrix} $ On ne peut pas avoir $AB = BA = I_n$ Ainsi la matrice $A$ n'est pas inversible et $A^{-1}$ n'existe pas.

Diapositive 83 / 159

Propriété : Inverse d'une matrice

Unicité
Si $A$ est inversible, alors son inverse $A^{-1}$ est unique.
Propriétés
Soient $A, B \in \mathcal{M}_n(\mathbb{K})$ deux matrices inversibles et $\lambda \in \mathbb{K}^*$. Alors :
  • $\left(A^{-1}\right)^{-1} = A$
  • $\left(AB\right)^{-1} = B^{-1}A^{-1}$
  • $\left(A^\top\right)^{-1} = \left(A^{-1}\right)^\top$
  • $\left(\lambda A\right)^{-1} = \dfrac{1}{\lambda}\,A^{-1}$

Diapositive 84 / 159

Propriété : Inverse d'une matrice

Attention
En général $\left(A + B\right)^{-1} \neq A^{-1} + B^{-1}$. L'inversion renverse l'ordre dans un produit :
$$ \left(A_1 A_2 \cdots A_k\right)^{-1} = A_k^{-1} \cdots A_2^{-1} A_1^{-1} $$

Diapositive 85 / 159

Propriété : Déterminant d'une matrice $2 \times 2$

Définition
Soit $A = \begin{pmatrix} a & b \\ c & d \end{pmatrix} \in \mathcal{M}_2(\mathbb{K})$. Le déterminant de $A$, noté $\det(A)$ ou $|A|$, est :
$$ \det(A) = \begin{vmatrix} a & b \\ c & d \end{vmatrix} = ad - bc $$
Propriétés importantes
  • $\det(I_2) = 1$
  • $\det(AB) = \det(A) \cdot \det(B)$
  • $\det(A^T) = \det(A)$
  • $\det(\lambda A) = \lambda^2 \det(A)$

Diapositive 86 / 159

Propriétés

Propriétés importantes
  • $A$ est inversible $\Leftrightarrow \det(A) \neq 0$
  • $\det\!\left(A^{-1}\right) = \dfrac{1}{\det(A)}$
Formule explicite (cofacteurs - hors programme)
Lorsque $A$ est inversible, on a :
$$ A^{-1} = \frac{1}{\det(A)}\,\mathrm{com}(A)^\top $$
où $\mathrm{com}(A)$ désigne la matrice des cofacteurs de $A$.

Diapositive 87 / 159

Exemple 1 : Déterminant $2 \times 2$ (matrice réelle)

$$ A = \begin{pmatrix} 3 & 5 \\ 2 & 4 \end{pmatrix} $$
Calcul :
$$ \det(A) = \begin{vmatrix} 3 & 5 \\ 2 & 4 \end{vmatrix} = 3 \times 4 - 5 \times 2 = 12 - 10 = 2 $$
Conclusion : $\det(A) = 2 \neq 0$ donc $A$ est inversible.

Diapositive 88 / 159

Exemple 2 : Déterminant $2 \times 2$ (matrice singulière)

$$ B = \begin{pmatrix} 2 & 4 \\ 1 & 2 \end{pmatrix} $$
Calcul :
$$ \det(B) = \dots $$

Diapositive 89 / 159

Exemple 2 : Déterminant $2 \times 2$ (matrice singulière)

$$ B = \begin{pmatrix} 2 & 4 \\ 1 & 2 \end{pmatrix} $$
Calcul :
$$ \det(B) = \begin{vmatrix} 2 & 4 \\ 1 & 2 \end{vmatrix} = 2 \times 2 - 4 \times 1 = 4 - 4 = 0 $$
Conclusion : $\det(B) = 0$ donc $B$ n'est pas inversible. Remarque : La deuxième ligne est proportionnelle à la première ($L_2 = \frac{1}{2}L_1$).

Diapositive 90 / 159

Exemple 3 : Déterminant $2 \times 2$ (matrice avec fractions)

$$ C = \begin{pmatrix} \frac{1}{2} & \frac{3}{4} \\[0.3cm] -\frac{2}{3} & \frac{1}{6} \end{pmatrix} $$
Calcul :
$$ \det(C) = \dots $$

Diapositive 91 / 159

Exemple 3 : Déterminant $2 \times 2$ (matrice avec fractions)

$$ C = \begin{pmatrix} \frac{1}{2} & \frac{3}{4} \\[0.3cm] -\frac{2}{3} & \frac{1}{6} \end{pmatrix} $$
Calcul :
$$ \det(C) = \frac{1}{2} \times \frac{1}{6} - \frac{3}{4} \times \left(-\frac{2}{3}\right) = \frac{1}{12} + \frac{6}{12} = \frac{7}{12} $$
Conclusion : $\det(C) = \frac{7}{12} \neq 0$ donc $C$ est inversible.

Diapositive 92 / 159

Déterminant $2 \times 2$ : Implémentation Python (sans numpy)

def det_2x2(A):
    """
    Calcule le determinant d'une matrice 2x2.
    """
    a, b = A[0][0], A[0][1]
    c, d = A[1][0], A[1][1]
    return a * d - b * c

# Exemple 1
A = [[3, 5], [2, 4]]
print("det(A) =", det_2x2(A))
# Exemple 2
B = [[2, 4], [1, 2]]
print("det(B) =", det_2x2(B))
# Exemple 3
C = [[0.5, 0.75], [-2/3, 1/6]]
print("det(C) =", det_2x2(C))

Diapositive 93 / 159

Déterminant $2 \times 2$ : Implémentation Python (sans numpy)

# Test d'inversibilite
def est_inversible(A):
    return det_2x2(A) != 0

print("A inversible ?", est_inversible(A))
print("B inversible ?", est_inversible(B))

Diapositive 94 / 159

Déterminant $2 \times 2$ : Implémentation Python (avec numpy)

import numpy as np

# Exemple 1
A = np.array([[3, 5], 
              [2, 4]])
det_A = np.linalg.det(A)
print("det(A) =", det_A)
# Exemple 2
B = np.array([[2, 4], 
              [1, 2]])
det_B = np.linalg.det(B)
print("det(B) =", det_B)
# Exemple 3
C = np.array([[0.5, 0.75], 
              [-2/3, 1/6]])
det_C = np.linalg.det(C)
print("det(C) =", det_C)

Diapositive 95 / 159

Déterminant $2 \times 2$ : Implémentation Python (avec numpy)

# Test d'inversibilite
print("A inversible ?", det_A != 0)
print("B inversible ?", np.abs(det_B) > 1e-10)

Diapositive 96 / 159

Propriété : Déterminant d'une matrice $3 \times 3$

Méthode de Sarrus
Soit $A = \begin{pmatrix} a_{11} & a_{12} & a_{13} \\ a_{21} & a_{22} & a_{23} \\ a_{31} & a_{32} & a_{33} \end{pmatrix}$. Règle de Sarrus : On recopie les deux premières colonnes à droite, puis : \begin{align*} \det(A) = &\; a_{11}a_{22}a_{33} + a_{12}a_{23}a_{31} + a_{13}a_{21}a_{32} \\ &\; - a_{13}a_{22}a_{31} - a_{11}a_{23}a_{32} - a_{12}a_{21}a_{33} \end{align*}
Diagonales descendantes (avec $+$) puis, diagonales montantes (avec $-$)

Diapositive 97 / 158

Exemple 1 : Déterminant $3 \times 3$ avec Sarrus

$$ A = \begin{pmatrix} 1 & 2 & 3 \\ 0 & 1 & 4 \\ 5 & 6 & 0 \end{pmatrix} $$
Application de la règle de Sarrus :
1 2 3 1 2
0 1 4 0 1
5 6 0 5 6
Diagonales $\searrow$ (positives) : $1 \times 1 \times 0 = 0$, $\quad 2 \times 4 \times 5 = 40$, $\quad 3 \times 0 \times 6 = 0$ Diagonales $\nearrow$ (négatives) : $3 \times 1 \times 5 = 15$, $\quad 1 \times 4 \times 6 = 24$, $\quad 2 \times 0 \times 0 = 0$
$$ \det(A) = (0 + 40 + 0) - (15 + 24 + 0) = 40 - 39 = 1 $$

Diapositive 98 / 159

Exemple 2 : Déterminant $3 \times 3$ (matrice diagonale)

$$ D = \begin{pmatrix} 2 & 0 & 0 \\ 0 & -3 & 0 \\ 0 & 0 & 5 \end{pmatrix} $$
Application de Sarrus :
$$\begin{array}{ccc|cc} 2 & 0 & 0 & 2 & 0 \\ 0 & -3 & 0 & 0 & -3 \\ 0 & 0 & 5 & 0 & 0 \end{array}$$
Diagonales $\searrow$ : $2 \times (-3) \times 5 = -30$, $\quad 0$, $\quad 0$ Diagonales $\nearrow$ : $0$, $\quad 0$, $\quad 0$
$$ \det(D) = -30 - 0 = -30 = 2 \times (-3) \times 5 $$
Propriété : Pour une matrice diagonale, $\det(D)$ = produit des éléments diagonaux.

Diapositive 99 / 159

Exemple 2 : Déterminant $3 \times 3$ (matrice diagonale)

$$ D = \begin{pmatrix} 2 & 0 & 0 \\ 0 & -3 & 0 \\ 0 & 0 & 5 \end{pmatrix} $$
Application de Sarrus :
$$\begin{array}{ccc|cc} 2 & 0 & 0 & 2 & 0 \\ 0 & -3 & 0 & 0 & -3 \\ 0 & 0 & 5 & 0 & 0 \end{array}$$
Diagonales $\searrow$ : $\dots$ Diagonales $\nearrow$ : $\dots$
$$ \det(D) = \dots $$
Propriété : Pour une matrice diagonale, $\det(D)$ = produit des éléments diagonaux.

Diapositive 100 / 159

Exemple 3 : Déterminant $3 \times 3$ (matrice singulière)

$$ B = \begin{pmatrix} 1 & 2 & 3 \\ 2 & 4 & 6 \\ 1 & 1 & 1 \end{pmatrix} $$
Application de Sarrus : \begin{center}
$$\begin{array}{ccc|cc} 1 & 2 & 3 & \dots & \dots \\ 2 & 4 & 6 & \dots & \dots \\ 1 & 1 & 1 & \dots & \dots \end{array}$$
\end{center} Diagonales $\searrow$ : $\dots$ Diagonales $\nearrow$ : $\dots$
$$ \det(B) = \dots $$

Diapositive 101 / 159

Exemple 3 : Déterminant $3 \times 3$ (matrice singulière)

$$ B = \begin{pmatrix} 1 & 2 & 3 \\ 2 & 4 & 6 \\ 1 & 1 & 1 \end{pmatrix} $$
Application de Sarrus : \begin{center}
$$\begin{array}{ccc|cc} 1 & 2 & 3 & 1 & 2 \\ 2 & 4 & 6 & 2 & 4 \\ 1 & 1 & 1 & 1 & 1 \end{array}$$
\end{center} Diagonales $\searrow$ : $1 \times 4 \times 1 = 4$, $\quad 2 \times 6 \times 1 = 12$, $\quad 3 \times 2 \times 1 = 6$ Diagonales $\nearrow$ : $3 \times 4 \times 1 = 12$, $\quad 1 \times 6 \times 1 = 6$, $\quad 2 \times 2 \times 1 = 4$
$$ \det(B) = (4 + 12 + 6) - (12 + 6 + 4) = 22 - 22 = 0 $$
$L_2 = 2 L_1$ donc la matrice n'est pas inversible.

Diapositive 102 / 159

Déterminant $3 \times 3$ : Implémentation Python (sans numpy)

def det_3x3(A):
    """
    Calcule le determinant d'une matrice 3x3
    par la regle de Sarrus.
    """
    # Diagonales descendantes (positives)
    diag_desc = (A[0][0]*A[1][1]*A[2][2] + 
                 A[0][1]*A[1][2]*A[2][0] + 
                 A[0][2]*A[1][0]*A[2][1])
    
    # Diagonales montantes (negatives)
    diag_mont = (A[0][2]*A[1][1]*A[2][0] + 
                 A[0][0]*A[1][2]*A[2][1] + 
                 A[0][1]*A[1][0]*A[2][2])
    
    return diag_desc - diag_mont

Diapositive 103 / 159

Déterminant $3 \times 3$ : Implémentation Python (sans numpy)

# Exemples
A = [[1, 2, 3], [0, 1, 4], [5, 6, 0]]
print("det(A) =", det_3x3(A))

D = [[2, 0, 0], [0, -3, 0], [0, 0, 5]]
print("det(D) =", det_3x3(D))

B = [[1, 2, 3], [2, 4, 6], [1, 1, 1]]
print("det(B) =", det_3x3(B))

Diapositive 104 / 159

Déterminant $3 \times 3$ : Implémentation Python (avec numpy)

import numpy as np

# Exemple 1
A = np.array([[1, 2, 3], 
              [0, 1, 4], 
              [5, 6, 0]])
det_A = np.linalg.det(A)
print("det(A) =", det_A)

# Exemple 2 : matrice diagonale
D = np.array([[2, 0, 0], 
              [0, -3, 0], 
              [0, 0, 5]])
det_D = np.linalg.det(D)
print("det(D) =", det_D)

Diapositive 105 / 159

Déterminant $3 \times 3$ : Implémentation Python (avec numpy)

# Exemple 3 : matrice singuliere
B = np.array([[1, 2, 3], 
              [2, 4, 6], 
              [1, 1, 1]])
det_B = np.linalg.det(B)
print("det(B) =", det_B)
print("B inversible ?", np.abs(det_B) > 1e-10)

Diapositive 106 / 159

Propriété : Inverse d'une matrice $2 \times 2$

Définition
Une matrice $A \in \mathcal{M}_n(\mathbb{K})$ est inversible s'il existe $B \in \mathcal{M}_n(\mathbb{K})$ telle que :
$$ AB = BA = I_n $$
On note alors $B = A^{-1}$ l'inverse de $A$.
Formule pour une matrice $2 \times 2$
Soit $A = \begin{pmatrix} a & b \\ c & d \end{pmatrix}$ avec $\det(A) = ad - bc \neq 0$.
$$ A^{-1} = \frac{1}{\det(A)} \begin{pmatrix} d & -b \\ -c & a \end{pmatrix} = \frac{1}{ad-bc} \begin{pmatrix} d & -b \\ -c & a \end{pmatrix} $$
Condition : $A$ est inversible $\Leftrightarrow \det(A) \neq 0$

Diapositive 107 / 159

Exemple 1 : Inverse d'une matrice $2 \times 2$

$$ A = \begin{pmatrix} 3 & 5 \\ 2 & 4 \end{pmatrix} $$
Étape 1 : Calculer le déterminant
$$ \det(A) = 3 \times 4 - 5 \times 2 = 12 - 10 = 2 \neq 0 $$
Étape 2 : Appliquer la formule
$$ A^{-1} = \frac{1}{2} \begin{pmatrix} 4 & -5 \\ -2 & 3 \end{pmatrix} = \begin{pmatrix} 2 & -\frac{5}{2} \\[0.2cm] -1 & \frac{3}{2} \end{pmatrix} $$
Vérification : $AA^{-1} = \begin{pmatrix} 3 & 5 \\ 2 & 4 \end{pmatrix} \begin{pmatrix} 2 & -\frac{5}{2} \\ -1 & \frac{3}{2} \end{pmatrix} = \begin{pmatrix} 1 & 0 \\ 0 & 1 \end{pmatrix}$ (ok)

Diapositive 108 / 159

Exemple 2 : Inverse d'une matrice $2 \times 2$ (identité)

$$ I_2 = \begin{pmatrix} 1 & 0 \\ 0 & 1 \end{pmatrix} $$
Calcul :
$$ \det(I_2) = 1 \times 1 - 0 \times 0 = 1 $$
$$ I_2^{-1} = \frac{1}{1} \begin{pmatrix} 1 & 0 \\ 0 & 1 \end{pmatrix} = \begin{pmatrix} 1 & 0 \\ 0 & 1 \end{pmatrix} = I_2 $$
Propriété : L'inverse de la matrice identité est elle-même.

Diapositive 109 / 159

Exemple 3 : Inverse d'une matrice $2 \times 2$ (cas général)

$$ B = \begin{pmatrix} 1 & 2 \\ 3 & 7 \end{pmatrix} $$
Calcul du déterminant :
$$ \det(B) = 1 \times 7 - 2 \times 3 = 7 - 6 = 1 $$
Calcul de l'inverse :
$$ B^{-1} = \frac{1}{1} \begin{pmatrix} 7 & -2 \\ -3 & 1 \end{pmatrix} = \begin{pmatrix} 7 & -2 \\ -3 & 1 \end{pmatrix} $$
Vérification :
$$ BB^{-1} = \begin{pmatrix} 1 & 2 \\ 3 & 7 \end{pmatrix} \begin{pmatrix} 7 & -2 \\ -3 & 1 \end{pmatrix} = \begin{pmatrix} 1 & 0 \\ 0 & 1 \end{pmatrix} $$

Diapositive 110 / 159

Inverse $2 \times 2$ : Implémentation Python (sans numpy)

def inverse_2x2(A):
    """
    Calcule l'inverse d'une matrice 2x2.
    Retourne None si non inversible.
    """
    a, b = A[0][0], A[0][1]
    c, d = A[1][0], A[1][1]
    
    det = a * d - b * c
    
    if det == 0:
        return None
    
    inv = [[d/det, -b/det],
           [-c/det, a/det]]
    
    return inv

Diapositive 111 / 159

Inverse $2 \times 2$ : Implémentation Python (sans numpy)

# Exemples
A = [[3, 5], [2, 4]]
A_inv = inverse_2x2(A)
print("A^-1 =", A_inv)

B = [[1, 2], [3, 7]]
B_inv = inverse_2x2(B)
print("B^-1 =", B_inv)

Diapositive 112 / 159

Inverse $2 \times 2$ : Implémentation Python (avec numpy)

import numpy as np
# Exemple 1
A = np.array([[3, 5], 
              [2, 4]])
A_inv = np.linalg.inv(A)
print("A^-1 =\n", A_inv)
# Verification
verif = np.dot(A, A_inv)
print("\nAA^-1 =\n", verif)
# Exemple 2 : Identite
I = np.eye(2)
I_inv = np.linalg.inv(I)
print("\nI^-1 =\n", I_inv)
# Exemple 3
B = np.array([[1, 2], 
              [3, 7]])
B_inv = np.linalg.inv(B)
print("\nB^-1 =\n", B_inv)

Diapositive 113 / 158

Récapitulatif n°2 des opérations

Opération Notation Dimensions
Transposition $A^T$ $\mathcal{M}_{n,p} \to \mathcal{M}_{p,n}$
Addition $A + B$ $\mathcal{M}_{n,p} \times \mathcal{M}_{n,p} \to \mathcal{M}_{n,p}$
Mult. scalaire $\lambda A$ $\mathbb{K} \times \mathcal{M}_{n,p} \to \mathcal{M}_{n,p}$
Produit $AB$ $\mathcal{M}_{n,p} \times \mathcal{M}_{p,q} \to \mathcal{M}_{n,q}$
Trace $\text{tr}(A)$ $\mathcal{M}_n \to \mathbb{K}$
det $\text{det}(A)$ $\mathcal{M}_n \to \mathbb{K}$
Inverse $A^{-1}$ $\mathcal{M}_n \to \mathcal{M}_n$

Diapositive 114 / 159

Propriété : Résolution par inversion matricielle

Système linéaire
Un système de $n$ équations à $n$ inconnues s'écrit sous forme matricielle :
$$ AX = B $$
où $A \in \mathcal{M}_n(\mathbb{K})$, $X = \begin{pmatrix} x_1 \\ \vdots \\ x_n \end{pmatrix}$, $B = \begin{pmatrix} b_1 \\ \vdots \\ b_n \end{pmatrix}$

Diapositive 115 / 159

Exemple : système de 3 équations à 3 inconnues

Soit $A = \begin{pmatrix} 1 & 2 & 3 \\ 4 & 5 & 6 \\ 7 & 8 & 9 \end{pmatrix}$ $X= \begin{pmatrix} x \\ y \\ z \end{pmatrix}$ $B = \begin{pmatrix} 10 \\ 11 \\ 12 \end{pmatrix}$
Calculer $A\times X$ puis écrire $A\times X = B$ sous la forme d'un système de 3 équations à 3 inconnues.

Diapositive 116 / 159

Propriété : Résolution par inversion matricielle

Résolution
Si $\det(A) \neq 0$ (système de Cramer), alors :
$$ X = A^{-1}B $$
Méthode :
  1. Calculer $\det(A)$ et vérifier qu'il est non nul
  2. Calculer $A^{-1}$
  3. Calculer $X = A^{-1}B$

Diapositive 117 / 159

Exemple 1 : Système $2 \times 2$ par inversion

Système :
$$ \begin{cases} 3x + 5y = 16 \\ 2x + 4y = 12 \end{cases} $$
Forme matricielle : $AX = B$ avec
$$ A = \begin{pmatrix} 3 & 5 \\ 2 & 4 \end{pmatrix}, \quad X = \begin{pmatrix} x \\ y \end{pmatrix}, \quad B = \begin{pmatrix} 16 \\ 12 \end{pmatrix} $$
Calcul : $\det(A) = 2 \neq 0$, donc $A^{-1} = \begin{pmatrix} 2 & -\frac{5}{2} \\ -1 & \frac{3}{2} \end{pmatrix}$
$$ X = A^{-1}B = \begin{pmatrix} 2 & -\frac{5}{2} \\ -1 & \frac{3}{2} \end{pmatrix} \begin{pmatrix} 16 \\ 12 \end{pmatrix} = \begin{pmatrix} 2 \\ 2 \end{pmatrix} $$
Solution : $x = 2$, $y = 2$

Diapositive 118 / 159

Exemple 2 : Système $2 \times 2$ simple

Système :
$$ \begin{cases} x + 2y = 5 \\ 3x + 7y = 16 \end{cases} $$
Forme matricielle :
$$ \begin{pmatrix} 1 & 2 \\ 3 & 7 \end{pmatrix} \begin{pmatrix} x \\ y \end{pmatrix} = \begin{pmatrix} 5 \\ 16 \end{pmatrix} $$
$\det(A) = \dots$, donc $A^{-1} = \dots$
$$ X = \begin{pmatrix} \dots & \dots \\ \dots & \dots \end{pmatrix} \begin{pmatrix} 5 \\ 16 \end{pmatrix} = \begin{pmatrix} 3 \\ 1 \end{pmatrix} $$

Diapositive 119 / 159

Exemple 2 : Système $2 \times 2$ simple

Système :
$$ \begin{cases} x + 2y = 5 \\ 3x + 7y = 16 \end{cases} $$
Forme matricielle :
$$ \begin{pmatrix} 1 & 2 \\ 3 & 7 \end{pmatrix} \begin{pmatrix} x \\ y \end{pmatrix} = \begin{pmatrix} 5 \\ 16 \end{pmatrix} $$
$\det(A) = 1$, donc $A^{-1} = \begin{pmatrix} 7 & -2 \\ -3 & 1 \end{pmatrix}$
$$ X = \begin{pmatrix} 7 & -2 \\ -3 & 1 \end{pmatrix} \begin{pmatrix} 5 \\ 16 \end{pmatrix} = \begin{pmatrix} 3 \\ 1 \end{pmatrix} $$
Solution : $x = 3$, $y = 1$ Vérification : $3 + 2(1) = 5$ (ok) et $3(3) + 7(1) = 16$ (ok)

Diapositive 120 / 159

Exemple 3 : Système $3 \times 3$ par inversion

Système :
$$ \begin{cases} x + 2y + 3z = 14 \\ \phantom{x} + y + 4z = 13 \\ 5x + 6y \phantom{+ 3z} = 19 \end{cases} $$
Forme matricielle :
$$ \begin{pmatrix} 1 & 2 & 3 \\ 0 & 1 & 4 \\ 5 & 6 & 0 \end{pmatrix} \begin{pmatrix} x \\ y \\ z \end{pmatrix} = \begin{pmatrix} 14 \\ 13 \\ 19 \end{pmatrix} $$
On a calculé $A^{-1} = \begin{pmatrix} -24 & 18 & 5 \\ 20 & -15 & -4 \\ -5 & 4 & 1 \end{pmatrix}$
$$ X = A^{-1}B = \begin{pmatrix} -24 & 18 & 5 \\ 20 & -15 & -4 \\ -5 & 4 & 1 \end{pmatrix} \begin{pmatrix} 14 \\ 13 \\ 19 \end{pmatrix} = \begin{pmatrix} \dots \\ \dots \\ \dots \end{pmatrix} $$

Diapositive 121 / 159

Exemple 3 : Système $3 \times 3$ par inversion

Système :
$$ \begin{cases} x + 2y + 3z = 14 \\ \phantom{x} + y + 4z = 13 \\ 5x + 6y \phantom{+ 3z} = 19 \end{cases} $$
Forme matricielle :
$$ \begin{pmatrix} 1 & 2 & 3 \\ 0 & 1 & 4 \\ 5 & 6 & 0 \end{pmatrix} \begin{pmatrix} x \\ y \\ z \end{pmatrix} = \begin{pmatrix} 14 \\ 13 \\ 19 \end{pmatrix} $$
$$ X = A^{-1}B = \begin{pmatrix} -24 & 18 & 5 \\ 20 & -15 & -4 \\ -5 & 4 & 1 \end{pmatrix} \begin{pmatrix} 14 \\ 13 \\ 19 \end{pmatrix} = \begin{pmatrix} 1 \\ 1 \\ 3 \end{pmatrix} $$
Solution : $x = 1$, $y = 1$, $z = 3$

Diapositive 122 / 159

Systèmes linéaires : Implémentation Python (sans numpy)

def resoudre_systeme_2x2(A, B):
    """
    Resout AX = B pour un systeme 2x2.
    """
    A_inv = inverse_2x2(A)
    if A_inv is None:
        return None
    
    # Produit matrice-vecteur
    x = A_inv[0][0]*B[0] + A_inv[0][1]*B[1]
    y = A_inv[1][0]*B[0] + A_inv[1][1]*B[1]
    
    return [x, y]

Diapositive 123 / 159

Systèmes linéaires : Implémentation Python (sans numpy)

# Exemple 1
A = [[3, 5], [2, 4]]
B = [16, 12]
solution = resoudre_systeme_2x2(A, B)
print("Solution :", solution)

# Exemple 2
A2 = [[1, 2], [3, 7]]
B2 = [5, 16]
solution2 = resoudre_systeme_2x2(A2, B2)
print("Solution 2 :", solution2)

Diapositive 124 / 159

Systèmes linéaires : Implémentation Python (avec numpy)

import numpy as np

# Exemple 1 : Systeme 2x2
A = np.array([[3, 5], 
              [2, 4]])
B = np.array([16, 12])
X = np.linalg.solve(A, B)
print("Solution :", X)

# Verification
verif = np.dot(A, X)
print("AX =", verif, "  B =", B)

Diapositive 125 / 159

Systèmes linéaires : Implémentation Python (avec numpy)

# Exemple 2
A2 = np.array([[1, 2], 
               [3, 7]])
B2 = np.array([5, 16])
X2 = np.linalg.solve(A2, B2)
print("\nSolution 2 :", X2)

# Exemple 3 : Systeme 3x3
A3 = np.array([[1, 2, 3], [0, 1, 4], [5, 6, 0]])
B3 = np.array([14, 13, 19])
X3 = np.linalg.solve(A3, B3)
print("\nSolution 3 :", X3)

Diapositive 126 / 159

Propriété : Formules de Cramer

Théorème de Cramer
Soit $AX = B$ un système de $n$ équations à $n$ inconnues avec $\det(A) \neq 0$.
La solution $X = (x_1, x_2, \ldots, x_n)^T$ est donnée par :
$$ x_i = \frac{\det(A_i)}{\det(A)} $$
où $A_i$ est la matrice obtenue en remplaçant la $i$-ème colonne de $A$ par $B$.
Pour un système $2 \times 2$ :
$$ x = \frac{\begin{vmatrix} b_1 & a_{12} \\ b_2 & a_{22} \end{vmatrix}}{\det(A)}, \quad y = \frac{\begin{vmatrix} a_{11} & b_1 \\ a_{21} & b_2 \end{vmatrix}}{\det(A)} $$

Diapositive 127 / 158

Exemple 1 : Cramer pour système $2 \times 2$

Système :
$$ \begin{cases} 3x + 5y = 16 \\ 2x + 4y = 12 \end{cases} $$
$$A = \begin{pmatrix} 3 & 5 \\ 2 & 4 \end{pmatrix}, \quad \det(A) = 2$$
Calcul de $x$ :
$$ A_1 = \begin{pmatrix} 16 & 5 \\ 12 & 4 \end{pmatrix}, \quad \det(A_1) = 16 \times 4 - 5 \times 12 = 4 $$
$$ x = \frac{4}{2} = 2 $$
Calcul de $y$ :
$$ A_2 = \begin{pmatrix} 3 & 16 \\ 2 & 12 \end{pmatrix}, \quad \det(A_2) = 3 \times 12 - 16 \times 2 = 4 $$
$$ y = \frac{4}{2} = 2 $$

Diapositive 128 / 159

Exemple 2 : Cramer pour système $2 \times 2$

Système :
$$ \begin{cases} x + 2y = 5 \\ 3x + 7y = 16 \end{cases} $$
$A = \dots$, $\det(A) = \dots$ Calcul de $x$ :
$$ \det(A_1) = \dots \implies x = \dots $$
Calcul de $y$ :
$$ \det(A_2) = \dots \implies y = \dots $$

Diapositive 129 / 159

Exemple 2 : Cramer pour système $2 \times 2$

Système :
$$ \begin{cases} x + 2y = 5 \\ 3x + 7y = 16 \end{cases} $$
$A = \begin{pmatrix} 1 & 2 \\ 3 & 7 \end{pmatrix}$, $\det(A) = 1$ Calcul de $x$ :
$$ \det(A_1) = \begin{vmatrix} 5 & 2 \\ 16 & 7 \end{vmatrix} = 35 - 32 = 3 \implies x = 3 $$
Calcul de $y$ :
$$ \det(A_2) = \begin{vmatrix} 1 & 5 \\ 3 & 16 \end{vmatrix} = 16 - 15 = 1 \implies y = 1 $$

Diapositive 130 / 159

Exemple 3 : Cramer pour système $3 \times 3$

Système :
$$ \begin{cases} x + 2y + 3z = 14 \\ y + 4z = 13 \\ 5x + 6y = 19 \end{cases} $$
$\det(A) = 1$ Pour $x$ :
$$ A_1 = \begin{pmatrix} 14 & 2 & 3 \\ 13 & 1 & 4 \\ 19 & 6 & 0 \end{pmatrix}, \quad \det(A_1) = 1 \implies x = 1 $$
Pour $y$ :
$$ A_2 = \begin{pmatrix} 1 & 14 & 3 \\ 0 & 13 & 4 \\ 5 & 19 & 0 \end{pmatrix}, \quad \det(A_2) = 1 \implies y = 1 $$
Pour $z$ :
$$ A_3 = \begin{pmatrix} 1 & 2 & 14 \\ 0 & 1 & 13 \\ 5 & 6 & 19 \end{pmatrix}, \quad \det(A_3) = 3 \implies z = 3 $$

Diapositive 131 / 159

Formules de Cramer : Implémentation Python (sans numpy)

def cramer_2x2(A, B):
    """
    Resout un systeme 2x2 avec Cramer.
    """
    det_A = det_2x2(A)
    if det_A == 0:
        return None
        # Determinant pour x (remplacer col 1 par B)
    A1 = [[B[0], A[0][1]], 
          [B[1], A[1][1]]]
    det_A1 = det_2x2(A1)
    x = det_A1 / det_A
        # Determinant pour y (remplacer col 2 par B)
    A2 = [[A[0][0], B[0]], 
          [A[1][0], B[1]]]
    det_A2 = det_2x2(A2)
    y = det_A2 / det_A
    
    return [x, y]

Diapositive 132 / 159

Formules de Cramer : Implémentation Python (sans numpy)

# Exemple
A = [[3, 5], [2, 4]]
B = [16, 12]
sol = cramer_2x2(A, B)
print("Solution (Cramer) :", sol)

Diapositive 133 / 159

Formules de Cramer : Implémentation Python (avec numpy)

import numpy as np

def cramer_np(A, B):
    """Resout avec Cramer."""
    n = A.shape[0]
    det_A = np.linalg.det(A)
    
    if abs(det_A) < 1e-10:
        return None
    
    solution = []
    for i in range(n):
        A_i = A.copy()
        A_i[:, i] = B
        det_A_i = np.linalg.det(A_i)
        solution.append(det_A_i / det_A)
    
    return np.array(solution)

Diapositive 134 / 159

Formules de Cramer : Implémentation Python (avec numpy)

# Exemple 1 : 2x2
A = np.array([[3, 5], [2, 4]], dtype=float)
B = np.array([16, 12], dtype=float)
sol = cramer_np(A, B)
print("Solution (Cramer) :", sol)

# Exemple 2 : 3x3
A3 = np.array([[1, 2, 3], [0, 1, 4], [5, 6, 0]], 
              dtype=float)
B3 = np.array([14, 13, 19], dtype=float)
sol3 = cramer_np(A3, B3)
print("\nSolution 3x3 :", sol3)

Diapositive 135 / 159

Propriété : Valeurs propres et vecteurs propres

Définitions
Soit $A \in \mathcal{M}_n(\mathbb{K})$. Un scalaire $\lambda \in \mathbb{K}$ est une valeur propre de $A$ s'il existe un vecteur non nul $\vec{v} \in \mathbb{K}^n$ tel que :
$$ A\vec{v} = \lambda \vec{v} $$
Le vecteur $\vec{v}$ est appelé vecteur propre associé à $\lambda$.
Polynôme caractéristique
Les valeurs propres sont les racines du polynôme caractéristique :
$$ P_A(\lambda) = \det(A - \lambda I_n) = 0 $$
Pour $n = 2$ : $P_A(\lambda) = \lambda^2 - \text{tr}(A) \lambda + \det(A)$

Diapositive 136 / 159

Exemple 1 : Valeurs propres d'une matrice $2 \times 2$

$$ A = \begin{pmatrix} 4 & 1 \\ 2 & 3 \end{pmatrix} $$
Polynôme caractéristique :
$$ \det(A - \lambda I) = \begin{vmatrix} 4-\lambda & 1 \\ 2 & 3-\lambda \end{vmatrix} = (4-\lambda)(3-\lambda) - 2 $$
$$ = \lambda^2 - 7\lambda + 10 = (\lambda - 5)(\lambda - 2) = 0 $$
Valeurs propres : $\lambda_1 = 5$ et $\lambda_2 = 2$

Diapositive 137 / 159

Exemple 1 : Vecteurs propres (suite)

Pour $\lambda_1 = 5$ :
$$ (A - 5I)\vec{v} = \vec{0} \implies \begin{pmatrix} -1 & 1 \\ 2 & -2 \end{pmatrix} \begin{pmatrix} v_1 \\ v_2 \end{pmatrix} = \begin{pmatrix} 0 \\ 0 \end{pmatrix} $$
$-v_1 + v_2 = 0 \implies v_2 = v_1$ Vecteur propre : $\vec{v}_1 = \begin{pmatrix} 1 \\ 1 \end{pmatrix}$ Pour $\lambda_2 = 2$ :
$$ (A - 2I)\vec{v} = \vec{0} \implies \begin{pmatrix} 2 & 1 \\ 2 & 1 \end{pmatrix} \begin{pmatrix} v_1 \\ v_2 \end{pmatrix} = \begin{pmatrix} 0 \\ 0 \end{pmatrix} $$
$2v_1 + v_2 = 0 \implies v_2 = -2v_1$ Vecteur propre : $\vec{v}_2 = \begin{pmatrix} 1 \\ -2 \end{pmatrix}$

Diapositive 138 / 159

Exemple 2 : Matrice diagonale $2 \times 2$

$$ D = \begin{pmatrix} 3 & 0 \\ 0 & -5 \end{pmatrix} $$
Polynôme caractéristique :
$$ \det(D - \lambda I) = (3-\lambda)(-5-\lambda) = 0 $$
Valeurs propres : $\lambda_1 = 3$ et $\lambda_2 = -5$ Vecteurs propres :
  • Pour $\lambda_1 = 3$ : $\vec{v}_1 = \begin{pmatrix} 1 \\ 0 \end{pmatrix}$
  • Pour $\lambda_2 = -5$ : $\vec{v}_2 = \begin{pmatrix} 0 \\ 1 \end{pmatrix}$
Propriété : Les valeurs propres d'une matrice diagonale sont ses éléments diagonaux.

Diapositive 139 / 159

Exemple 3 : Matrice symétrique $2 \times 2$

$$ S = \begin{pmatrix} 2 & 1 \\ 1 & 2 \end{pmatrix} $$
Polynôme caractéristique :
$$ \det(S - \lambda I) = (2-\lambda)^2 - 1 = \lambda^2 - 4\lambda + 3 = 0 $$
Valeurs propres : $\lambda_1 = 3$ et $\lambda_2 = 1$ Vecteurs propres : $\vec{v}_1 = \begin{pmatrix} 1 \\ 1 \end{pmatrix}$ pour $\lambda_1 = 3$, \quad $\vec{v}_2 = \begin{pmatrix} 1 \\ -1 \end{pmatrix}$ pour $\lambda_2 = 1$ Les vecteurs propres sont orthogonaux (propriété des matrices symétriques réelles).

Diapositive 140 / 159

Valeurs propres $2 \times 2$ : Implémentation Python (sans numpy)

import math

def valeurs_propres_2x2(A):
    """
    Calcule les valeurs propres d'une matrice 2x2.
    """
    tr = A[0][0] + A[1][1]
    det = det_2x2(A)
    
    delta = tr**2 - 4*det
    
    if delta < 0: return None
    
    lambda1 = (tr + math.sqrt(delta)) / 2
    lambda2 = (tr - math.sqrt(delta)) / 2
    
    return [lambda1, lambda2]

Diapositive 141 / 159

Valeurs propres $2 \times 2$ : Implémentation Python (sans numpy)

def vecteur_propre_2x2(A, lambda_val):
    """Trouve un vecteur propre."""
    a = A[0][0] - lambda_val
    b = A[0][1]
    
    if abs(b) > 1e-10:
        return [1, -a/b]
    else:
        return [0, 1]

Diapositive 142 / 159

Valeurs propres $2 \times 2$ : Implémentation (suite)

# Exemple 1
A = [[4, 1], [2, 3]]
vp = valeurs_propres_2x2(A)
print("Valeurs propres de A :", vp)

for i, lambda_val in enumerate(vp):
    v = vecteur_propre_2x2(A, lambda_val)
    print(f"Vecteur propre {i+1} :", v)

# Exemple 2 : Matrice diagonale
D = [[3, 0], [0, -5]]
vp_D = valeurs_propres_2x2(D)
print("\nValeurs propres de D :", vp_D)

# Exemple 3 : Matrice symetrique
S = [[2, 1], [1, 2]]
vp_S = valeurs_propres_2x2(S)
print("\nValeurs propres de S :", vp_S)

Diapositive 143 / 159

Valeurs propres $2 \times 2$ : Implémentation (suite)

for i, lambda_val in enumerate(vp_S):
    v = vecteur_propre_2x2(S, lambda_val)
    print(f"Vecteur propre {i+1} :", v)

Diapositive 144 / 159

Valeurs propres $2 \times 2$ : Implémentation Python (avec numpy)

import numpy as np

# Exemple 1
A = np.array([[4, 1], 
              [2, 3]])
valeurs_propres, vecteurs_propres = np.linalg.eig(A)
print("Valeurs propres de A :", valeurs_propres)
print("Vecteurs propres de A :\n", vecteurs_propres)

# Verification : A*v = lambda*v
v1 = vecteurs_propres[:, 0]
lambda1 = valeurs_propres[0]
print("\nAv1 =", np.dot(A, v1))
print("lambda1*v1 =", lambda1 * v1)

Diapositive 145 / 159

Valeurs propres $2 \times 2$ : Implémentation Python (avec numpy)

# Exemple 2 : Matrice diagonale
D = np.array([[3, 0], 
              [0, -5]])
vp_D, vec_D = np.linalg.eig(D)
print("\n\nValeurs propres de D :", vp_D)
print("Vecteurs propres de D :\n", vec_D)

Diapositive 146 / 159

Propriété : Valeurs propres de matrices $3 \times 3$

Méthode
Pour une matrice $A \in \mathcal{M}_3(\mathbb{K})$ : Étape 1 : Calculer le polynôme caractéristique
$$ P_A(\lambda) = \det(A - \lambda I_3) = -\lambda^3 + c_2\lambda^2 + c_1\lambda + c_0 $$
Étape 2 : Résoudre $P_A(\lambda) = 0$ (équation cubique) Étape 3 : Pour chaque valeur propre $\lambda_i$, résoudre
$$ (A - \lambda_i I_3)\vec{v} = \vec{0} $$
Propriétés simplificatrices :
  • Matrice diagonale : valeurs propres = éléments diagonaux
  • Matrice triangulaire : valeurs propres = éléments diagonaux

Diapositive 147 / 159

Exemple 1 : Matrice diagonale $3 \times 3$

$$ D = \begin{pmatrix} 2 & 0 & 0 \\ 0 & -1 & 0 \\ 0 & 0 & 4 \end{pmatrix} $$
Valeurs propres : $\lambda_1 = 2$, $\lambda_2 = -1$, $\lambda_3 = 4$ Vecteurs propres :
  • $\lambda_1 = 2$ : $\vec{v}_1 = \begin{pmatrix} 1 \\ 0 \\ 0 \end{pmatrix}$
  • $\lambda_2 = -1$ : $\vec{v}_2 = \begin{pmatrix} 0 \\ 1 \\ 0 \end{pmatrix}$
  • $\lambda_3 = 4$ : $\vec{v}_3 = \begin{pmatrix} 0 \\ 0 \\ 1 \end{pmatrix}$

Diapositive 148 / 159

Exemple 2 : Matrice triangulaire $3 \times 3$

$$ T = \begin{pmatrix} 3 & 1 & 2 \\ 0 & 3 & 5 \\ 0 & 0 & -2 \end{pmatrix} $$
Propriété : Pour une matrice triangulaire, les valeurs propres sont les éléments diagonaux. Valeurs propres : $\lambda_1 = 3$ (multiplicité 2), $\lambda_2 = -2$ Polynôme caractéristique :
$$ P_T(\lambda) = (3-\lambda)^2(-2-\lambda) = 0 $$

Diapositive 149 / 159

Exemple 3 : Matrice symétrique $3 \times 3$

$$ S = \begin{pmatrix} 1 & 0 & 0 \\ 0 & 1 & 1 \\ 0 & 1 & 1 \end{pmatrix} $$
Calcul du polynôme caractéristique :
$$ \det(S - \lambda I) = (1-\lambda)[(1-\lambda)^2 - 1] = (1-\lambda)(\lambda^2 - 2\lambda) = 0 $$
Valeurs propres : $\lambda_1 = 1$, $\lambda_2 = 0$, $\lambda_3 = 2$

Diapositive 150 / 159

Valeurs propres $3 \times 3$ : Implémentation Python (avec numpy)

import numpy as np

# Exemple 1 : Matrice diagonale
D = np.array([[2, 0, 0], 
              [0, -1, 0], 
              [0, 0, 4]])
vp_D, vec_D = np.linalg.eig(D)
print("Valeurs propres de D :", vp_D)
print("Vecteurs propres de D :\n", vec_D)

# Exemple 2 : Matrice triangulaire
T = np.array([[3, 1, 2], 
              [0, 3, 5], 
              [0, 0, -2]])
vp_T, vec_T = np.linalg.eig(T)
print("\nValeurs propres de T :", vp_T)

Diapositive 151 / 159

Valeurs propres $3 \times 3$ : Implémentation Python (avec numpy)

# Exemple 3 : Matrice symetrique
S = np.array([[1, 0, 0], 
              [0, 1, 1], 
              [0, 1, 1]])
vp_S, vec_S = np.linalg.eig(S)
print("\nValeurs propres de S :", vp_S)
print("Vecteurs propres de S :\n", vec_S)

Diapositive 152 / 159

Propriété : Diagonalisation et matrice de passage

Théorème
Si $A \in \mathcal{M}_n(\mathbb{K})$ possède $n$ vecteurs propres linéairement indépendants $\vec{v}_1, \ldots, \vec{v}_n$ associés aux valeurs propres $\lambda_1, \ldots, \lambda_n$, alors :
$$ A = PDP^{-1} $$
où $P = [\vec{v}_1 \mid \vec{v}_2 \mid \cdots \mid \vec{v}_n]$ et $D = \text{diag}(\lambda_1, \ldots, \lambda_n)$
Propriétés importantes
  • $\det(A) = \prod_{i=1}^n \lambda_i$ (produit des valeurs propres)
  • $\text{tr}(A) = \sum_{i=1}^n \lambda_i$ (somme des valeurs propres)
  • $A^k = PD^kP^{-1}$ où $D^k = \text{diag}(\lambda_1^k, \ldots, \lambda_n^k)$
  • Les matrices symétriques réelles sont toujours diagonalisables

Diapositive 153 / 159

Exemple : Diagonalisation d'une matrice $2 \times 2$

$$ A = \begin{pmatrix} 4 & 1 \\ 2 & 3 \end{pmatrix} $$
On a trouvé : $\lambda_1 = 5$, $\vec{v}_1 = \begin{pmatrix} 1 \\ 1 \end{pmatrix}$ et $\lambda_2 = 2$, $\vec{v}_2 = \begin{pmatrix} 1 \\ -2 \end{pmatrix}$ Matrice de passage :
$$ P = \begin{pmatrix} 1 & 1 \\ 1 & -2 \end{pmatrix}, \quad D = \begin{pmatrix} 5 & 0 \\ 0 & 2 \end{pmatrix} $$
Calcul de $P^{-1}$ : $\det(P) = -3$
$$ P^{-1} = \frac{1}{-3} \begin{pmatrix} -2 & -1 \\ -1 & 1 \end{pmatrix} = \begin{pmatrix} \frac{2}{3} & \frac{1}{3} \\[0.2cm] \frac{1}{3} & -\frac{1}{3} \end{pmatrix} $$
Vérification : $A = PDP^{-1}$

Diapositive 154 / 159

Exemple : Calcul de puissance matricielle

Objectif : Calculer $A^{10}$ pour $A = \begin{pmatrix} 4 & 1 \\ 2 & 3 \end{pmatrix}$ Utilisation de la diagonalisation :
$$ A^{10} = PD^{10}P^{-1} $$
$$ D^{10} = \begin{pmatrix} 5^{10} & 0 \\ 0 & 2^{10} \end{pmatrix} = \begin{pmatrix} 9\,765\,625 & 0 \\ 0 & 1\,024 \end{pmatrix} $$
$$ A^{10} = \begin{pmatrix} 1 & 1 \\ 1 & -2 \end{pmatrix} \begin{pmatrix} 9\,765\,625 & 0 \\ 0 & 1\,024 \end{pmatrix} \begin{pmatrix} \frac{2}{3} & \frac{1}{3} \\[0.2cm] \frac{1}{3} & -\frac{1}{3} \end{pmatrix} $$
Cette méthode est beaucoup plus efficace que calculer $A \times A \times \cdots \times A$ (10 fois).

Diapositive 155 / 159

Exemple : Vérification des propriétés

Pour $A = \begin{pmatrix} 4 & 1 \\ 2 & 3 \end{pmatrix}$ avec $\lambda_1 = 5$, $\lambda_2 = 2$ : 1) Produit des valeurs propres = déterminant :
$$ \lambda_1 \times \lambda_2 = 5 \times 2 = 10 = \det(A) \quad \checkmark $$
2) Somme des valeurs propres = trace :
$$ \lambda_1 + \lambda_2 = 5 + 2 = 7 = 4 + 3 = \text{tr}(A) \quad \checkmark $$
Ces propriétés permettent de vérifier rapidement si le calcul des valeurs propres est correct !

Diapositive 156 / 159

Diagonalisation : Implémentation Python (sans numpy)

def diagonaliser_2x2(A):
    """
    Diagonalise une matrice 2x2 : A = P*D*P^-1
    Retourne P, D, P_inv
    """
    # Calcul des valeurs propres
    vp = valeurs_propres_2x2(A)
    if vp is None:
        return None
    
    # Calcul des vecteurs propres
    v1 = vecteur_propre_2x2(A, vp[0])
    v2 = vecteur_propre_2x2(A, vp[1])

Diapositive 157 / 159

Diagonalisation : Implémentation Python (sans numpy)

# Matrice P
    P = [[v1[0], v2[0]], 
         [v1[1], v2[1]]]
    
    # Matrice D
    D = [[vp[0], 0], 
         [0, vp[1]]]
    
    # P^-1
    P_inv = inverse_2x2(P)
    
    return P, D, P_inv

Diapositive 158 / 159

Diagonalisation : Implémentation Python (avec numpy)

import numpy as np

# Diagonalisation automatique
A = np.array([[4, 1], 
              [2, 3]], dtype=float)

valeurs_propres, P = np.linalg.eig(A)
D = np.diag(valeurs_propres)
P_inv = np.linalg.inv(P)

print("Matrice A :\n", A)
print("\nValeurs propres :", valeurs_propres)
print("\nMatrice P (vecteurs propres) :\n", P)
print("\nMatrice D (diagonale) :\n", D)

# Verification : A = P*D*P^-1
A_reconstruit = P @ D @ P_inv
print("\nA reconstruit :\n", A_reconstruit)

Diapositive 159 / 159

Diagonalisation : Implémentation Python (avec numpy)

# Calcul de A^10
A_10 = P @ np.linalg.matrix_power(D, 10) @ P_inv
print("\nA^10 :\n", A_10)