Matrices triangulaires Résolution de systèmes linéaires particuliers S Canu - G Gasso - B Gaüzère - L Noiret benoitgauzere@insa-rouenfr 18 septembre 2016
Plan 1 Introduction 2 Résolution de systèmes linéaires Matrices diagonales Matrices triangulaires 3 Algorithme tri inf tri inf par ligne tri inf par colonne Version matricielle Exemple Version matricielle par lignes Le cas des matrices triangulaires supérieures L algèbre de matrices triangulaires Canu, Gasso, Gaüzère, Noiret (INSA Rouen - ASI) Triangulaire 18 septembre 2016 2 / 31
Plan 1 Introduction 2 Résolution de systèmes linéaires Matrices diagonales Matrices triangulaires 3 Algorithme tri inf tri inf par ligne tri inf par colonne Version matricielle Exemple Version matricielle par lignes Le cas des matrices triangulaires supérieures L algèbre de matrices triangulaires Canu, Gasso, Gaüzère, Noiret (INSA Rouen - ASI) Triangulaire 18 septembre 2016 2 / 31
Résolution de systèmes linéaires particuliers I Résolution de systèmes linéaires Résolution de systèmes linéaires Résolution de Ax = b Matrices particulières La structure des matrices peut faciliter la résolution Structures particulières : matrices diagonales matrices triangulaires triangulaires supérieures triangulaires inférieures unitaires (sup ou inf) Figure Matrice de similarité de matrices par blocs séquences vidéos anu, Gasso, Gaüzère, Noiret (INSA Rouen - ASI) Triangulaire 18 septembre 2016 3 / 31
Plan 1 Introduction 2 Résolution de systèmes linéaires Matrices diagonales Matrices triangulaires 3 Algorithme tri inf tri inf par ligne tri inf par colonne Version matricielle Exemple Version matricielle par lignes Le cas des matrices triangulaires supérieures L algèbre de matrices triangulaires Canu, Gasso, Gaüzère, Noiret (INSA Rouen - ASI) Triangulaire 18 septembre 2016 3 / 31
Le cas des matrices diagonales Matrice Diagonale Algo Matrice carrée A ij = 0 si i j Fonction x diag(a, b) Pour i = 1, n faire x i = b i /A ii Fin Pour Si A ii = 0 le problème n admet pas de solution si b i 0 Complexité? Canu, Gasso, Gaüzère, Noiret (INSA Rouen - ASI) Triangulaire 18 septembre 2016 4 / 31
Le cas des matrices diagonales Matrice Diagonale Algo Matrice carrée A ij = 0 si i j Fonction x diag(a, b) Pour i = 1, n faire x i = b i /A ii Fin Pour Si A ii = 0 le problème n admet pas de solution si b i 0 Complexité : O(n) Canu, Gasso, Gaüzère, Noiret (INSA Rouen - ASI) Triangulaire 18 septembre 2016 4 / 31
Le cas des matrices triangulaires I Matrice triangulaire inférieure Une matrice A est dite triangulaire inférieure si elle est carrée, j > i, A ij = 0 Matrice triangulaire supérieure Une matrice A est dite triangulaire supérieure si elle est carrée j < i, A ij = 0 NB : Par convention, on notera les matrices triangulaires inférieures L pour lower et les matrices triangulaires supérieures U pour upper Canu, Gasso, Gaüzère, Noiret (INSA Rouen - ASI) Triangulaire 18 septembre 2016 5 / 31
Le cas des matrices triangulaires II Exemples L 1,1 0 0 0 0 L 2,1 L 2,2 0 0 0 L = L 3,1 L 3,2 0 0 0 L n,1 L n,2 L n,n 1 L n,n U 1,1 U 1,2 U 1,n 1 U 1,n 0 U 2,2 U 2,n 1 U 2,n U = 0 0 0 0 0 Un 1,n 0 0 0 0 U n,n Canu, Gasso, Gaüzère, Noiret (INSA Rouen - ASI) Triangulaire 18 septembre 2016 6 / 31
Système et matrices triangulaires inférieures I Lx = b soit L une matrice triangulaire inférieure La résolution d un système linéaire se pose de la manière suivante : Lx = b L 11 x 1 = b 1 L 21 x 1 + L 22 x 2 = b 2 = L i1 x 1 + L i2 x 2 + + L ii x i = b i = L n1 x 1 + L n2 x 2 + + L ni x i + + L nn x n = b n Canu, Gasso, Gaüzère, Noiret (INSA Rouen - ASI) Triangulaire 18 septembre 2016 7 / 31
Exemple Lx = b 2 0 0 2 Calculez x tel que Lx = b avec L = 4 1 0 b = 3 6 1 2 7 2x 1 = 2 Ce problème revient à résoudre : 4x 1 x 2 = 3 6x 1 + x 2 2x 3 = 7 anu, Gasso, Gaüzère, Noiret (INSA Rouen - ASI) Triangulaire 18 septembre 2016 8 / 31
Exemple Lx = b 2 0 0 2 Calculez x tel que Lx = b avec L = 4 1 0 b = 3 6 1 2 7 2x 1 = 2 Ce problème revient à résoudre : 4x 1 x 2 = 3 6x 1 + x 2 2x 3 = 7 x 1 = b 1 = 2 L 1,1 2 = 1 Solution : x 2 = b 2 L 2,1 x 1 = 3 4 1 = 1 L 2,2 1 x 3 = b 3 L 3,1 x 1 L 3,2 x 2 = L 3,3 7 ( 6) 1 1 1 2 = 1 Canu, Gasso, Gaüzère, Noiret (INSA Rouen - ASI) Triangulaire 18 septembre 2016 8 / 31
Généralisation Problème Lx = b L 11 x 1 = b 1 L 21 x 1 + L 22 x 2 = b 2 L i1 x 1 + L i2 x 2 + + L ii x i = b i L n1 x 1 + L n2 x 2 + + L ni x i + + L nn x n = b n Solution x 1 = b 1 /L 11 x 2 = b 2 L 21 x 1 L 22 ) x i = b i (L i1 x 1 +L i2 x 2 + +L ii 1 x i 1 L ii ( ) x n = bn L n1 x 1 +L n2 x 2 + +L ni x i + +L nn 1 x n 1 L nn Canu, Gasso, Gaüzère, Noiret (INSA Rouen - ASI) Triangulaire 18 septembre 2016 9 / 31
Plan 1 Introduction 2 Résolution de systèmes linéaires Matrices diagonales Matrices triangulaires 3 Algorithme tri inf tri inf par ligne tri inf par colonne Version matricielle Exemple Version matricielle par lignes Le cas des matrices triangulaires supérieures L algèbre de matrices triangulaires Canu, Gasso, Gaüzère, Noiret (INSA Rouen - ASI) Triangulaire 18 septembre 2016 9 / 31
L algorithme tri inf x tri inf(l, b) Pour i = 1, n faire s = 0 Pour j = 1, i 1 faire s = s + L ij x j Fin Pour x i = (b i s)/l ii Fin Pour x i = b i (L i1 x 1 + +L ij x j + +L ii 1 x i 1 ) L ii Propriétés de l algorithme tri inf Complexité : O(n 2 ) anu, Gasso, Gaüzère, Noiret (INSA Rouen - ASI) Triangulaire 18 septembre 2016 10 / 31
L algorithme tri inf x tri inf(l, b) Pour i = 1, n faire s = 0 Pour j = 1, i 1 faire s = s + L ij x j Fin Pour x i = (b i s)/l ii Fin Pour x i = b i (L i1 x 1 + +L ij x j + +L ii 1 x i 1 ) L ii Propriétés de l algorithme tri inf Complexité : O(n 2 ) anu, Gasso, Gaüzère, Noiret (INSA Rouen - ASI) Triangulaire 18 septembre 2016 10 / 31
Amélioration I Fonction b tri inf(l, b) On stocke la solution x dans b Économie d espace mémoire Pour i = 1, n faire s = 0 Pour j = 1, i 1 faire s = s + L ij b j Fin Pour b i = (b i s)/l ii Fin Pour Canu, Gasso, Gaüzère, Noiret (INSA Rouen - ASI) Triangulaire 18 septembre 2016 11 / 31
Amélioration II Fonction b tri inf(l, b) sans la variable intermédiaire s Pour i = 1, n faire Pour j = 1, i 1 faire b i = b i L ij b j Fin Pour b i = b i /L ii Fin Pour // b i = b i L i1 b 1 L i2 b 2 L ij b j Canu, Gasso, Gaüzère, Noiret (INSA Rouen - ASI) Triangulaire 18 septembre 2016 12 / 31
Amélioration III Une boucle Pour i = 1, n faire ( ) b i = b i L(i, 1 : i 1)b(1 : i 1) Fin Pour /L ii ( Li1 L i2 L i3 L i4 L i,i 1 ) b 1 b 2 b 3 b 4 b i 1 Canu, Gasso, Gaüzère, Noiret (INSA Rouen - ASI) Triangulaire 18 septembre 2016 13 / 31
tri inf par colonne Approche par colonnes À chaque itération : On met à jour l ensemble de la solution ; On traite une colonne de L ; À l itération j Seul L(j + 1 : n, j) contient de l information L 1,1 0 0 0 0 L 2,1 L 2,2 0 0 0 L = L 3,1 L 3,2 0 0 0 L n,1 L n,2 L n,n 1 L n,n Canu, Gasso, Gaüzère, Noiret (INSA Rouen - ASI) Triangulaire 18 septembre 2016 14 / 31
tri inf par colonne Schéma global Canu, Gasso, Gaüzère, Noiret (INSA Rouen - ASI) Triangulaire 18 septembre 2016 15 / 31
j = 1 x 1 = b 1 /L 1,1 : peut être calculé i > 1, x i = b i L i,j : peut être mis à jour Canu, Gasso, Gaüzère, Noiret (INSA Rouen - ASI) Triangulaire 18 septembre 2016 16 / 31
j = 2 x 2 = (b 2 L 2,1 x 1 )/L 2,2 x 1 est connu x 2 = b 2 L 2,1 x 1 est connu i > 2, x i = b i L i,j : peut être mis à jour } x 2 final peut être calculé Canu, Gasso, Gaüzère, Noiret (INSA Rouen - ASI) Triangulaire 18 septembre 2016 17 / 31
Terme général j x j = (b j j 1 k=1 L j,kx k )/L j,j x(1 : j 1) est connu j 1 x j = b j L j,k x k x j final peut être calculé est connu k=1 i > j, x i = b i L i,j : peut être mis à jour Canu, Gasso, Gaüzère, Noiret (INSA Rouen - ASI) Triangulaire 18 septembre 2016 18 / 31
Algorithme tri inf par colonnes Généralisation Stockons x dans b Algorithme : Fonction tri inf C (L, b) : b Pour j = 1, n 1 faire b j = b j /L j,j b(j + 1 : n) = b(j + 1 : n) b j L(j + 1 : n, j) Fin Pour b n = b n /L nn Fin À l itération j : b(1 : j) = x j i > j, bi = b i j 1 k=1 L ikx k Canu, Gasso, Gaüzère, Noiret (INSA Rouen - ASI) Triangulaire 18 septembre 2016 19 / 31
Version matricielle I tri inf c Fonction tri inf C (L, b) : b Pour j = 1, n 1 faire b j = b j /L j,j b(j + 1 : n) = b(j + 1 : n) b j L(j + 1 : n, j) Fin Pour b n = b n /L nn Fin j = 1 on a : b 1 /L 1,1 b 2 b 1L 2,1 L 1,1 b 3 b 1L 3,1 L 1,1 b = b i b 1L i,1 L 1,1 b n b 1L n,1 L 1,1 Canu, Gasso, Gaüzère, Noiret (INSA Rouen - ASI) Triangulaire 18 septembre 2016 20 / 31
Version matricielle II Version Matricielle, b = M 1 b 1/L 1,1 0 0 L 2,1 /L 1,1 1 0 0 L 3,1 /L 1,1 0 1 0 0 L i,1 /L 1,1 0 0 1 0 0 L n,1 /L 1,1 0 0 1 b 1 b 2 b 3 b i b n b 1 b 2 b 3 b i b n b 1 /L 1,1 b 2 b 1L 2,1 L 1,1 b 3 b 1L 3,1 L 1,1 = b i b 1L i,1 L 1,1 b n b 1L n,1 L 1,1 Canu, Gasso, Gaüzère, Noiret (INSA Rouen - ASI) Triangulaire 18 septembre 2016 21 / 31
M 1 = 1/L 1,1 0 0 L 2,1 /L 1,1 1 0 0 L 3,1 /L 1,1 0 1 0 0 L i,1 /L 1,1 0 0 1 0 0 L n,1 /L 1,1 0 0 1 = I τ 1 e 1 Avec τ 1 = 1 1/L 11 L 21 /L 11 L i1 /L 11 L n1 /L 11 et e 1 = 1 0 0 Canu, Gasso, Gaüzère, Noiret (INSA Rouen - ASI) Triangulaire 18 septembre 2016 22 / 31
Terme général j D une manière générale : M j = I τ j e j τj = (0 } {{ 0} j 1 fois avec e j = (0 } {{ 0} j 1 fois 1 1/L jj L(j + 1 : n, j)/l jj ) 1 } 0 {{ 0} ) de j+1 jusqu à n Canu, Gasso, Gaüzère, Noiret (INSA Rouen - ASI) Triangulaire 18 septembre 2016 23 / 31
Exemple I 2 0 0 L = 4 1 0 6 1 2 j = 1 1/2 0 0 M 1 = 2 1 0 Lx = b 1 0 0 3 0 1 M 1 Lx = M 1 b M 1L = 0 1 0 0 1 2 j = 2 1 0 0 1 0 0 M 2 = 0 1 0 M 2 M 1 L = 0 1 0 0 1 1 0 0 2 Canu, Gasso, Gaüzère, Noiret (INSA Rouen - ASI) Triangulaire 18 septembre 2016 24 / 31
Exemple II j = 3 1 0 0 1 0 0 M 3 = 0 1 0 M 3 M 2 M 1 L = 0 1 0 = I 0 1/2 0 0 1 Fin j = n, on remarque que M 3 M 2 M 1 L = I : M 3 M 2 M 1 Lx = M 3 M 2 M 1 b x = M 3 M 2 M 1 b : Solution Canu, Gasso, Gaüzère, Noiret (INSA Rouen - ASI) Triangulaire 18 septembre 2016 25 / 31
Algorithme Fonction tri inf M (L, b) : b Pour j = 1, n faire Fin // τ j = (0 } {{ 0 } j 1 fois τ j = tau(l(:, j)) M j = τ j ej T b = M j b Fin Pour 1 1/L jj L(j + 1 : n, j)/l jj ) T Canu, Gasso, Gaüzère, Noiret (INSA Rouen - ASI) Triangulaire 18 septembre 2016 26 / 31
Analyse mathématique de tri inf par colonnes Theorem (inverse d une matrice triangulaire) Soit L une matrice triangulaire L 1 = M n M j M 1 L algorithme tri inf par colonnes L algorithme tri inf par colonnes est une méthode calculer implicitement l inverse de la matrice L : efficace pour x = L 1 b = M n M j M 1 b Canu, Gasso, Gaüzère, Noiret (INSA Rouen - ASI) Triangulaire 18 septembre 2016 27 / 31
La version ligne Fonction tri inf(l, b) : b Pour i = 1, n faire Fin b i = ( b i L(i, 1 : i 1)b(1 : i 1) ) /L ii Fin Pour N i = 1 0 0 0 0 1 0 0 1 0 L i1 /L ii 1/L ii 0 1 0 0 0 0 1 // b = N i b N i = I e i νi avec : νi = (L(1 : i 1, j)/l ii ) 1 1/L ii 0 } {{ 0} ) de i+1 jusqu à n e i = (0 } {{ 0} 1 0 } {{ 0} ) i 1 fois de i+1 jusqu à n Canu, Gasso, Gaüzère, Noiret (INSA Rouen - ASI) Triangulaire 18 septembre 2016 28 / 31
Le cas des matrices triangulaires supérieures Ux = b Fonction tri sup(u, b) : b b n = b n /U nn Pour i = n 1 : 1 : 1 faire Pour j = i + 1 : n faire U 11 x 1 + U 12 x 2 + + U 1i x i + + U 1n x n = b 1 U i,i x i + U i,i+1 x i+1 + + U i,n x n = b i U n 1,n 1 x n 1 + U n 1,n x n = b n 1 U nn x n = b n Fin b i = b i U ij b j Fin Pour b i = b i /U ii Fin Pour Canu, Gasso, Gaüzère, Noiret (INSA Rouen - ASI) Triangulaire 18 septembre 2016 29 / 31
L algèbre de matrices triangulaires le produit de deux matrices tri inf est une matrice tri inf L L L l inverse d une matrice tri inf est une matrice tri inf L 1 L le produit de deux matrices unitaires tri inf est une matrice unitaire tri inf l inverse d une matrice unitaire tri inf est une matrice unitaire tri inf NB : matrice unitaire : matrice avec des 1 sur la diagonale Canu, Gasso, Gaüzère, Noiret (INSA Rouen - ASI) Triangulaire 18 septembre 2016 30 / 31
Conclusion le cas des matrices diagonales Dx = b : O(n) le cas des matrices triangulaires Lx = b : O(n 2 ) l écriture matricielle : diagonalisation O(n 2 ) O(n) Canu, Gasso, Gaüzère, Noiret (INSA Rouen - ASI) Triangulaire 18 septembre 2016 31 / 31