我要评分
获取效率
正确性
完整性
易理解

?getrf

Compute the LU factorization of matrix A. This function uses partial pivoting, allowing row interchanges. The operation is defined as A = PLU, where P is a permutation matrix, L is a lower triangular matrix or a lower echelon matrix and the diagonal is 1, and U is an upper triangular matrix or an upper echelon matrix.

Interface Definition

C interface:

void sgetrf_(const int *m, const int *n, float *a, const int *lda, int *ipiv, int *info);

void dgetrf_(const int *m, const int *n, double *a, const int *lda, int *ipiv, int *info);

void cgetrf_(const int *m, const int *n, float _Complex *a, const int *lda, int *ipiv, int *info);

void zgetrf_(const int *m, const int *n, double _Complex *a, const int *lda, int *ipiv, int *info);

Fortran interface:

SGETRF(m, n, a, lda, ipiv, info)

DGETRF(m, n, a, lda, ipiv, info)

CGETRF(m, n, a, lda, ipiv, info)

ZGETRF(m, n, a, lda, ipiv, info)

Parameters

Parameter

Type

Description

Input/Output

m

Integer

Number of rows in matrix A

Input

n

Integer

Number of columns in matrix A

Input

a

  • A single-precision floating-point array in sgetrf
  • A double-precision floating-point array in dgetrf
  • A single-precision complex number array in cgetrf
  • A double-precision complex array in zgetrf
  • Stores matrix A before this function is called.
  • Stores the factorization results L and U after this function is called. The diagonal elements of L (all are 1) are not stored.

Input/Output

lda

Integer

Leading dimension of matrix A. ldamax(1, n).

Input

ipiv

Integer array

An array containing pivot indices obtained from ?getrf. Its length is min(m,n). For 1 ≤ ipiv ≤ min(m,n), row i and row ipiv[i-1] of the matrix are interchanged during factorization.

Output

info

Integer

Execution result:

  • 0: The execution is successful.
  • Smaller than 0: The value of the -info-th parameter is invalid.
  • Greater than 0: The info-th element on the diagonal of matrix U is 0. The matrix factorization is complete, but U is singular. As a result, an error of dividing by zero occurs when a system of linear equations is solved.

Output

Dependencies

#include "klapack.h"

Examples

C interface:

    int m = 4; 
    int n = 4; 
    int lda = 4; 
    int ipiv[4]; 
    int info = 0; 
    /* 
     * A (stored in column-major): 
     *  1.80  2.88    2.05  -0.89 
     *  5.25  -2.95  -0.95  -3.80 
     *  1.58  -2.69  -2.90  -1.04 
     * -1.11  -0.66  -0.59   0.80 
     */ 
    double a[] = {1.80,  5.25,  1.58, -1.11, 
                    2.88, -2.95, -2.69, -0.66, 
                    2.05, -0.95, -2.90, -0.59, 
                    -0.89, -3.80, -1.04,  0.80}; 
    dgetrf_(&m, &n, a, &lda, ipiv, &info); 
    /* 
     * Output: 
     *  5.2500  -2.9500  -0.9500  -3.8000 
     *  0.3429   3.8914   2.3757   0.4129 
     *  0.3010  -0.4631  -1.5139   0.2948 
     * -0.2114  -0.3299   0.0047   0.1314 
     */ 

Fortran interface:

        PARAMETER (m = 4) 
        PARAMETER (n = 4) 
        PARAMETER (lda = 4) 
        INTEGER :: ipiv(4) 
        INTEGER :: info = 0 
*       A (stored in column-major): 
*        1.80  2.88    2.05  -0.89 
*        5.25  -2.95  -0.95  -3.80 
*        1.58  -2.69  -2.90  -1.04 
*       -1.11  -0.66  -0.59   0.80 
        REAL(8) :: a(m, n) 
        DATA a / 1.80,  5.25,  1.58, -1.11, 
     $           2.88, -2.95, -2.69, -0.66, 
     $           2.05, -0.95, -2.90, -0.59, 
     $           -0.89, -3.80, -1.04,  0.80 / 
        EXTERNAL DGETRF 
        CALL DGETRF(m, n, a, lda, ipiv, info); 
*       Output: 
*        5.2500  -2.9500  -0.9500  -3.8000 
*        0.3429   3.8914   2.3757   0.4129 
*        0.3010  -0.4631  -1.5139   0.2948 
*       -0.2114  -0.3299   0.0047   0.1314