HP Forums
About LU factorization - Printable Version

+- HP Forums (https://www.hpmuseum.org/forum)
+-- Forum: HP Calculators (and very old HP Computers) (/forum-3.html)
+--- Forum: HP Prime (/forum-5.html)
+--- Thread: About LU factorization (/thread-4071.html)

Pages: 1 2


RE: About LU factorization - salvomic - 06-04-2015 05:10 PM

(06-04-2015 04:57 PM)Werner Wrote:  ...
Crout factorisation alternatingly computes a row and a column...
Cheers, Werner

hi Werner,
both methods have goods and issues...
Maybe Parisse and Tim could tell us more about the Prime and LU...

However for matrices operations perhaps it could be better to have also some little commands or helps, like a command to extract pivots, to get cofactors, adjoint, minors, and also factorizations LDU (LDV) and LDLt. As they are missing, I'm trying to make some programs, but for pivots I'm getting these troubles...
Some other calculators have those commands, if I well remember (i.e., TI 89/Voyage had adj / cofactor function)...
For example I use a lot a little program to get minor of a matrix:
Code:


#cas 
matrixminor(m,r,c):=
BEGIN
  m:= delrows(m,r);
  m:= delcols(m,c);
END;
#end
Simple but useful, it helps to don't use delrows() and delcols() more and more. It's alternative to the subMat() command (syntax: subMat(m, r1, c1, r2,c2), and perhaps more short Smile

I made a program to calculate Cofactor matrix and adjoint matrix (see here)...

Salvo


RE: About LU factorization - salvomic - 06-05-2015 08:15 PM

Given the permutation matrix (by LU), like [1,3,2] is there a way to obtain the actual permutation matrix (like P21 = [[0,1,0], [1,0,0], [0,0,1]] ?
I need to make a routine with that matrix for the program to calculate LDU factorization as, sometime, L*D*U returns the matrix A with some swap of rows (indicated by the permutation matrix by LU).

Salvo


RE: About LU factorization - Claudio L. - 06-05-2015 08:38 PM

(06-05-2015 08:15 PM)salvomic Wrote:  Given the permutation matrix (by LU), like [1,3,2] is there a way to obtain the actual permutation matrix (like P21 = [[0,1,0], [1,0,0], [0,0,1]] ?
I need to make a routine with that matrix for the program to calculate LDU factorization as, sometime, L*D*U returns the matrix A with some swap of rows (indicated by the permutation matrix by LU).

Salvo

To get the permutation matrix, simply create an NxN matrix with all zeros, and for each row, take a number off the list, and put a 1 in the corresponding column.
For example:
[ 1 , 3 , 2 ] --> Put a 1 in the 1st column on row 1, on row 2 put it in the 3rd column, and on the 3rd row put it in the 2nd column.
You'll get [[ 1 0 0 ] [0 0 1] [0 1 0]], which is what you are looking for.


RE: About LU factorization - salvomic - 06-05-2015 09:00 PM

(06-05-2015 08:38 PM)Claudio L. Wrote:  To get the permutation matrix, simply create an NxN matrix with all zeros, and for each row, take a number off the list, and put a 1 in the corresponding column.
For example:
[ 1 , 3 , 2 ] --> Put a 1 in the 1st column on row 1, on row 2 put it in the 3rd column, and on the 3rd row put it in the 2nd column.
You'll get [[ 1 0 0 ] [0 0 1] [0 1 0]], which is what you are looking for.

thank you Claudio!

something like this?
Code:

EXPORT permMatrix(lst)
// given a permutation list (like {1,3,2}) and the matrix dimension, returns a permutation matrix
BEGIN
local j, k, mat, dimen;
dimen:= length(lst);
mat:= MAKEMAT(0, dimen, dimen);
FOR j FROM 1 TO dimen DO
mat(j,lst(j)):= 1;
END; // for
RETURN mat;
END;



RE: About LU factorization - parisse - 06-07-2015 06:42 PM

(06-05-2015 08:15 PM)salvomic Wrote:  Given the permutation matrix (by LU), like [1,3,2] is there a way to obtain the actual permutation matrix (like P21 = [[0,1,0], [1,0,0], [0,0,1]] ?
permu2mat in Xcas, not available on the Prime.


RE: About LU factorization - salvomic - 06-07-2015 07:20 PM

(06-07-2015 06:42 PM)parisse Wrote:  permu2mat in Xcas, not available on the Prime.

thank you, Parisse, I hope this command could be included in the Prime in a next firmware also

Salvo


RE: About LU factorization - Claudio L. - 06-08-2015 01:12 PM

(06-05-2015 09:00 PM)salvomic Wrote:  something like this?
Code:

EXPORT permMatrix(lst)
// given a permutation list (like {1,3,2}) and the matrix dimension, returns a permutation matrix
BEGIN
local j, k, mat, dimen;
dimen:= length(lst);
mat:= MAKEMAT(0, dimen, dimen);
FOR j FROM 1 TO dimen DO
mat(j,lst(j)):= 1;
END; // for
RETURN mat;
END;

I don't have a Prime but looks correct to me, you can test easily that permMatrix(P)*A will swap the rows in any matrix A to the order you specified in the vector P.
EDIT: I mean correct in the algorithm, I think your function is missing the size as argument?: permMatrix(P,3)
EDIT AGAIN: Nevermind... I was misled by your comment in the code, but you fot the size automatically.


RE: About LU factorization - salvomic - 06-08-2015 01:15 PM

(06-08-2015 01:12 PM)Claudio L. Wrote:  I don't have a Prime but looks correct to me, you can test easily that permMatrix(P)*A will swap the rows in any matrix A to the order you specified in the vector P.
EDIT: I mean correct in the algorithm, I think your function is missing the size as argument?: permMatrix(P,3)

it seems to be good, almost for the 10-20 matrices I tried Smile
thanks!

Salvo