# -*- coding: utf-8 -*- """ Created on Tue Dec 23 16:17:33 2014 @author: grivet Listing 5.2SP : Factorisation LU, avec permutation de lignes et utilisation d'un programme de la bibliothèque Scipy """ import numpy as np from scipy.linalg import lu def affiche_mat(titre,M): print (titre) for row in M: for val in row: print (' %10.5f' %val, end='') print() N = 4; A = np.array([ [2, 1, 0, 4],[-4, -2, 3, -7],[4, 1, -2, 8],[0,-3,-12, -1]],float) affiche_mat('A = ',A) print() A0 = np.copy(A) p = np.zeros(N) P,L,U = lu(A) affiche_mat('matrice de permutation P = ',P); affiche_mat('matrice L = ',L) affiche_mat('matrice U = ',U) affiche_mat('produit LU: ',np.dot(L,U)) PL = np.dot(P,L) PLU = np.dot(PL,U) affiche_mat('produit permuté PLU =', PLU)