math:matrices:systeme_lineaire:directe
Différences
Ci-dessous, les différences entre deux révisions de la page.
Les deux révisions précédentesRévision précédenteProchaine révision | Révision précédente | ||
math:matrices:systeme_lineaire:directe [2019/03/17 22:36] – Inversion d'une matrice via le pivot de Gauss root | math:matrices:systeme_lineaire:directe [2020/04/28 23:00] (Version actuelle) – mhtml -> html root | ||
---|---|---|---|
Ligne 122: | Ligne 122: | ||
</ | </ | ||
- | ====Méthode de Gauss / Crout : LU (A non symétrique)==== | ||
- | Valable pour une matrice carrée définie positive. | ||
- | |||
- | Étape 1 : | ||
- | $$ | ||
- | \begin{align*} | ||
- | &j = 1 \\ | ||
- | &i = 1 \quad &l_{jj} &= a_{jj} \\ | ||
- | & | ||
- | \end{align*} | ||
- | $$ | ||
- | |||
- | Étape 2 : | ||
- | $$ | ||
- | \begin{align} | ||
- | \forall j &\in [2,N-1] : \\ | ||
- | i &= 1 \quad & l_{ji} &= a_{ji} \\ | ||
- | \forall &i \in [2, j] \quad & l_{ji} &= a_{ji} - \sum_{k=1}^{i-1}l_{jk}u_{ki} \\ | ||
- | \forall &i \in [j+1, N] \quad & u_{ji} &= \frac{a_{ji} - \sum_{k=1}^{j-1}l_{jk}u_{ki}}{l_{jj}} | ||
- | \end{align} | ||
- | $$ | ||
- | |||
- | Étape 3: | ||
- | $$ | ||
- | \begin{align} | ||
- | \forall i &\in [1,N] : \\ | ||
- | j &= N \\ | ||
- | l_{ji} &= a_{ji} - \sum_{k=1}^{i-1}l_{jk}u_{ki} \\ | ||
- | \end{align} | ||
- | $$ | ||
- | |||
- | Complexité : $\frac{N^3}{3}$ multiplications, | ||
- | |||
- | [[math: | ||
- | |||
- | [[https:// | ||
- | |||
- | Si l'un des $l_{jj}$ vaut 0, il faut appliquer un pivot. | ||
===Pivot=== | ===Pivot=== | ||
Ligne 210: | Ligne 172: | ||
[[https:// | [[https:// | ||
+ | |||
+ | ====Méthode de Gauss / Crout : LU (A non symétrique)==== | ||
+ | A doit être inversible (pas de pivot nul). | ||
+ | |||
+ | Étape 1 : | ||
+ | $$ | ||
+ | \begin{align*} | ||
+ | &j = 1 \\ | ||
+ | &i = 1 \quad &l_{jj} &= a_{jj} \\ | ||
+ | & | ||
+ | \end{align*} | ||
+ | $$ | ||
+ | |||
+ | Étape 2 : | ||
+ | $$ | ||
+ | \begin{align} | ||
+ | \forall j &\in [2,N-1] : \\ | ||
+ | i &= 1 \quad & l_{ji} &= a_{ji} \\ | ||
+ | \forall &i \in [2, j] \quad & l_{ji} &= a_{ji} - \sum_{k=1}^{i-1}l_{jk}u_{ki} \\ | ||
+ | \forall &i \in [j+1, N] \quad & u_{ji} &= \frac{a_{ji} - \sum_{k=1}^{j-1}l_{jk}u_{ki}}{l_{jj}} | ||
+ | \end{align} | ||
+ | $$ | ||
+ | |||
+ | Étape 3: | ||
+ | $$ | ||
+ | \begin{align} | ||
+ | \forall i &\in [1,N] : \\ | ||
+ | j &= N \\ | ||
+ | l_{ji} &= a_{ji} - \sum_{k=1}^{i-1}l_{jk}u_{ki} \\ | ||
+ | \end{align} | ||
+ | $$ | ||
+ | |||
+ | Complexité : $\frac{N^3}{3}$ multiplications, | ||
+ | |||
+ | [[math: | ||
+ | |||
+ | [[https:// | ||
+ | |||
+ | Si l'un des $l_{jj}$ vaut 0, il faut appliquer un pivot. | ||
+ | |||
+ | Implémentation du code en python : | ||
+ | |||
+ | <code python> | ||
+ | def factorlu(A): | ||
+ | L = np.identity(len(A)) | ||
+ | U = A.copy() | ||
+ | |||
+ | for j in range(len(A)): | ||
+ | | ||
+ | if (U[j][j] == 0): | ||
+ | L.fill(np.nan) | ||
+ | U.fill(np.nan) | ||
+ | return (L,U,0) | ||
+ | |||
+ | for i in range(j+1, | ||
+ | L[i, | ||
+ | U[i,j:] -=L[i, | ||
+ | | ||
+ | return (L,U,1) | ||
+ | </ | ||
+ | |||
====Méthode de Crout : CDtC (A symétrique)==== | ====Méthode de Crout : CDtC (A symétrique)==== | ||
Valable pour une matrice carrée symétrique définie positive. | Valable pour une matrice carrée symétrique définie positive. | ||
Ligne 235: | Ligne 258: | ||
Méthode : | Méthode : | ||
- | [[https:// | + | [[https:// |
Soit | Soit | ||
Ligne 403: | Ligne 426: | ||
$L = \begin{pmatrix} \sqrt 4 = 2 & 0 & 0 \\ \frac{12}{2} = 6 & \sqrt{37-6^2} = 1 & 0 \\ \frac{-16}{2} = -8 & \frac{-43-(-8)*6}{1} = 5 & \sqrt{98-8^2-5^2} = 3 \end{pmatrix}$ | $L = \begin{pmatrix} \sqrt 4 = 2 & 0 & 0 \\ \frac{12}{2} = 6 & \sqrt{37-6^2} = 1 & 0 \\ \frac{-16}{2} = -8 & \frac{-43-(-8)*6}{1} = 5 & \sqrt{98-8^2-5^2} = 3 \end{pmatrix}$ | ||
+ | |||
+ | Implémentation en python : | ||
+ | |||
+ | <code python> | ||
+ | def cholesky(A): | ||
+ | n = len(A) | ||
+ | L = np.zeros((n, | ||
+ | L[0,0] = cmath.sqrt(A[0, | ||
+ | L[1:,0] = A[1:, | ||
+ | |||
+ | for j in range(1,n): | ||
+ | if (not np.isreal(A[j, | ||
+ | # Matrice A non hermitienne | ||
+ | L.fill(np.nan) | ||
+ | return (L,-1) | ||
+ | |||
+ | carre = A[j,j] - np.dot(L[j,: | ||
+ | if (carre <= 0): | ||
+ | # Matrice non définie strictement positive | ||
+ | L.fill(np.nan) | ||
+ | return (L,0) | ||
+ | L[j,j] = cmath.sqrt(carre) | ||
+ | |||
+ | for i in range(j+1, | ||
+ | if (A[i,j] != np.conjugate(A[j, | ||
+ | # Matrice A non hermitienne | ||
+ | L.fill(np.nan) | ||
+ | return (L,0) | ||
+ | L[i, | ||
+ | |||
+ | return (L,1) | ||
+ | |||
+ | |||
+ | A4 = np.array( | ||
+ | [[ 4, 12, -16], | ||
+ | [ 12, 37, -43+2j], | ||
+ | [-16, -43-2j, | ||
+ | (L, sol) = cholesky(A4) | ||
+ | print (" | ||
+ | print (" | ||
+ | print (L.dot(L.transpose().conjugate())) | ||
+ | </ | ||
====QR (A non symétrique) méthode Householder==== | ====QR (A non symétrique) méthode Householder==== | ||
Ligne 428: | Ligne 493: | ||
$$Q = \prod_{k=1}^{N-1}Q_i$$ | $$Q = \prod_{k=1}^{N-1}Q_i$$ | ||
- | [[https:// | + | [[https:// |
[[http:// | [[http:// |
math/matrices/systeme_lineaire/directe.1552858617.txt.gz · Dernière modification : 2019/03/17 22:36 de root