Factorisation de Cholesky avec python et scipy

Published: 04 novembre 2016

DMCA.com Protection Status

Exemple de factorisation de Cholesky avec python et scipy en reprenant l'example de wikipedia:

>>> import numpy as np
>>> A = np.array(([1,1,1,1],[1,5,5,5],[1,5,14,14],[1,5,14,15]))
>>> A
array([[ 1,  1,  1,  1],
       [ 1,  5,  5,  5],
       [ 1,  5, 14, 14],
       [ 1,  5, 14, 15]])
>>> L = linalg.cholesky(A, lower=True)
>>> L
array([[ 1.,  0.,  0.,  0.],
       [ 1.,  2.,  0.,  0.],
       [ 1.,  2.,  3.,  0.],
      [ 1.,  2.,  3.,  1.]])
>>> L.transpose()
array([[ 1.,  1.,  1.,  1.],
       [ 0.,  2.,  2.,  2.],
       [ 0.,  0.,  3.,  3.],
       [ 0.,  0.,  0.,  1.]])

Vérification si on retrouve bien la matrice de départ:

>>> dot(L,L.transpose())
array([[  1.,   1.,   1.,   1.],
       [  1.,   5.,   5.,   5.],
       [  1.,   5.,  14.,  14.],
       [  1.,   5.,  14.,  15.]])

Recherches associées