lu takes as argument a square matrix A of size n (numeric or
symbolic).
lu(A) returns a permutation p of 0..n−1,
a lower triangular matrix L, with 1 on the diagonal,
and an upper triangular matrix U, such that :
L*U*x=P*B=p(B) where p(B)=[bp(0),bp(1)..bp(n−1)], B=[b0,b1..bn−1] |
The permutation matrix P is defined from p by :
P[i, p(i)]=1, P[i, j]=0 if j ≠ p(i) |
In other words, it is the identity matrix where the rows are permuted
according to the permutation p.
The function permu2mat may be used to compute P
(permu2mat(p) returns P).
Input :
Output :
Here n=2, hence :
P[0,p(0)]=P2[0,1]=1, P[1,p(1)]=P2[1,0]=1, P=[[0,1],[1,0]] |
Verification :
Input :
Output:
Note that the permutation is different for exact input (the choice of
pivot is the simplest instead of the largest in absolute value).
Input :
Output :
Input :
Output :