home *** CD-ROM | disk | FTP | other *** search
- //-------------------------------------------------------------------//
-
- // Synopsis: Gaussian elimination with complete pivoting.
-
- // Syntax: GECPL = gecp ( A )
-
- // Description:
-
- // Gecp computes the factorization P*A*Q = L*U, where L is unit
- // lower triangular, U is upper triangular, and P and Q are
- // permutation matrices. RHO is the growth factor.
-
- // This file is a translation of gecp.m from version 2.0 of
- // "The Test Matrix Toolbox for Matlab", described in Numerical
- // Analysis Report No. 237, December 1993, by N. J. Higham.
-
- //-------------------------------------------------------------------//
-
- gecp = function ( A )
- {
- local (A)
-
- n = A.nr; n = A.nc;
- pp = 1:n;
- qq = 1:n;
-
- rho = 0;
- maxA = norm(A[:], "i");
-
- for (k in 1:n-1)
- {
- // Find largest element in remaining square submatrix.
- // Note: when tie for max, no guarantee which element is chosen.
-
- colmaxima = max( abs(A[k:n; k:n]) );
- rowindices = maxi( abs(A[k:n; k:n]) );
- biggest = max (colmaxima);
- colindex = maxi (colmaxima);
- row = rowindices[colindex] + k - 1;
- col = colindex + k - 1;
-
- // Permute largest element into pivot position.
-
- A[ [k, row]; ] = A[ [row, k]; ];
- A[; [k, col] ] = A[; [col, k] ];
- pp[ k, row ] = pp[ row, k ];
- qq[ k, col ] = qq[ col, k ];
-
- if (A[k;k] == 0)
- {
- break
- }
-
- A[k+1:n;k] = A[k+1:n;k]/A[k;k]; // Multipliers.
-
- // Elimination
- i = k+1:n;
- A[i;i] = A[i;i] - A[i;k] * A[k;i];
- rho = max( rho, max(max(abs(A[i;i]))));
- }
-
-
- L = tril(A,-1) + eye(n,n);
- U = triu(A);
-
- P = eye(n,n); P = P[pp;];
- Q = eye(n,n); Q = Q[;qq];
- rho = rho/maxA;
-
- return << L=L ; U=U ; P=P ; Q=Q; rho=rho >>;
- };
-