LDLt decomposition?
06-02-2015, 05:54 PM (This post was last modified: 06-02-2015 07:20 PM by salvomic.)
Post: #6
 salvomic Senior Member Posts: 1,394 Joined: Jan 2015
RE: LDLt decomposition?
SWAPROW runs well in command line but not in a program? or am I missing something?

This code doesn't swap row 2 with 3...

Code:
EXPORT gaussJordan(m) // Gauss-Jordan elimination and pivots // Salvo Micciché 2015 BEGIN local k, gj, r, c, j, piv; r:=rowDim(m); c:=colDim(m); gj:=MAKEMAT(0,r,c); piv:=MAKELIST(0,X,1,r); M1:= m; FOR j FROM 1 TO r DO       M1:=pivot(M1,1,1);       piv(j):=M1(1,1);     IF (piv(j)==0) THEN  PRINT("M1 first " + M1);     M1:=m; PRINT("M1 then " + M1);     SWAPROW(M1, j, (j+1));  PRINT("M1 and after " + M1);     CONTINUE;      END; // if     FOR k FROM 1 TO colDim(M1) DO         gj(j, c-k+1):= M1(1, colDim(M1)-k+1);     END; // inner for     IF (j<r) THEN     M1:= delrows(M1,1);     M1:= delcols(M1,1);     END;     IF piv(j)==0 THEN RETURN "Pivot is 0, division by 0"; END;       M1:= M1/piv(j);   END; // for piv:= list2mat(piv, r); RETURN {gj, piv}; END;

See the prints in Terminal (debug, hi) with this matrix
[[1,2,3],[2,4,3],[3,2,1]]
Normally it would give division by zero, so we must swap the row with its next...
The result should be [[1,2,3],[0,-4,-10],[0,0,-3]] with pivots d={1,-4,-3}

I'm using an "old C style" tip, and it works:
Code:
  // M1:= SWAPROW(M1, numpivot, (numpivot+1));  temp:= M1(numpivot); M1(numpivot):=M1(numpivot+1); M1(numpivot+1):=temp;

∫aL√0mic (IT9CLU) :: HP Prime 50g 41CX 71b 42s 39s 35s 12C 15C - DM42, DM41X - WP34s Prime Soft. Lib
 « Next Oldest | Next Newest »

 Messages In This Thread LDLt decomposition? - salvomic - 01-26-2015, 12:30 PM RE: LDLt decomposition? - salvomic - 06-01-2015, 05:54 PM RE: LDLt decomposition? - salvomic - 06-01-2015, 10:51 PM RE: LDLt decomposition? - DrD - 06-02-2015, 11:26 AM RE: LDLt decomposition? - salvomic - 06-02-2015, 12:10 PM RE: LDLt decomposition? - salvomic - 06-02-2015 05:54 PM RE: LDLt decomposition? - DrD - 06-02-2015, 10:05 PM RE: LDLt decomposition? - salvomic - 06-02-2015, 10:15 PM RE: LDLt decomposition? - Helge Gabert - 06-02-2015, 11:05 PM RE: LDLt decomposition? - DrD - 06-03-2015, 11:59 AM RE: LDLt decomposition? - salvomic - 06-03-2015, 12:19 PM RE: LDLt decomposition? - salvomic - 06-03-2015, 01:22 PM

User(s) browsing this thread: 1 Guest(s)