home *** CD-ROM | disk | FTP | other *** search
- /* Copyright (C) 1985 Adam Fritz, 133 Main St., Afton, NY 13730 */
-
- SGEFA ( A, lda, n, IPvt, InfoCode )
- float A[][ldx] ;
- int lda, n ;
- int IPvt[] ;
- int *InfoCode ;
-
- /* Program: */
- /* */
- /* SGEFA - Factors Real Single Precision Matrix */
- /* Using Gaussian Elimination. */
- /* */
- /* Version: DATE: */
- /* */
- /* C 02/22/85 */
- /* FORTRAN 08/14/78 */
- /* */
- /* Description: */
- /* */
- /* SGEFA is usually called by SGECO, but can be */
- /* called directly with a saving in time if RCOND */
- /* is not needed. */
- /* */
- /* (time for SGECO) = (1 + 9/n)*(time for SGEFA) */
- /* */
- /* On entry; */
- /* */
- /* A - Matrix to be factored. */
- /* lda - Leading dimension of matrix A. */
- /* n - Order of matrix A. */
- /* */
- /* On exit; */
- /* */
- /* A - Upper triangular matrix and multi- */
- /* pliers used to obtain it. Factoriza- */
- /* tion can be written; */
- /* A = L * U */
- /* where L is a product of permutation */
- /* and unit lower triangular matrices */
- /* and U is upper triangular. */
- /* */
- /* IPvt - Pivot index vector. */
- /* */
- /* InfoCode - */
- /* = 0 Normal value. */
- /* = k If u[k,k] = 0.0. This is not an */
- /* error condition for this procedure, */
- /* but indicates that SGESL or SGEDI */
- /* will divide by zero if called. Use */
- /* RCOND from SGECO for reliable indi- */
- /* cation of singularity. */
- /* */
- /* Subprograms: */
- /* */
- /* SAXPY from BLAS */
- /* SSCAL from BLAS */
- /* ISAMAX from BLAS */
- /* */
- /* Authors: */
- /* */
- /* Cleve Moler */
- /* University of New Mexico */
- /* Argonne National Laboratories */
- /* */
- /* C and Pascal translations; */
- /* */
- /* Adam Fritz */
- /* 133 Main Street */
- /* Afton, New York 13730 */
-
- {
- int ISAMAX() ;
- int j, k, l ;
- int kp1, nm1 ;
- float t ;
- /* Gaussian Elimination with Partial Pivoting */
- *InfoCode = 0 ;
- nm1 = n - 1 ;
- if ( nm1 > 0 )
- {
- for ( k = 0; k < nm1; k++ )
- {
- kp1 = k + 1 ;
- /* Find l = Pivot Index */
- l = ISAMAX(n-k, &A[k][k], lda) + k ;
- IPvt[k] = l ;
- /* Zero Pivot Implies Column Triangularized */
- if ( A[l][k] != 0.0 )
- {
- /* Interchange If Necessary */
- if ( l != k )
- {
- t = A[l][k] ;
- A[l][k] = A[k][k] ;
- A[k][k] = t ;
- }
- /* Compute Multipliers */
- t = -1.0/A[k][k] ;
- SSCAL(n-k-1, t, &A[k+1][k], lda) ;
- /* Row Elimination with Column Indexing */
- for ( j = kp1; j < n; j++ )
- {
- t = A[l][j] ;
- if ( l != k )
- {
- A[l][j] = A[k][j] ;
- A[k][j] = t ;
- }
- SAXPY(n-k-1, t, &A[k+1][k], lda, &A[k+1][j], lda) ;
- }
- }
- else
- *InfoCode = k ;
- }
- }
- IPvt[nm1] = nm1 ;
- if ( A[nm1][nm1] == 0.0 )
- *InfoCode = nm1 ;
- }
-
- /* Copyright (C) 1985 Adam Fritz, 133 Main St., Afton, NY 13730 */