?gerqf
计算矩阵的RQ分解,即A = R * Q。
接口定义
C Interface:
void sgerqf_(const int *M, const int *N, float *A, const int *LDA, float *TAU, float *WORK, const int *LWORK, int *INFO);
void dgerqf_(const int *M, const int *N, double *A, const int *LDA, double *TAU, double *WORK, const int *LWORK, int *INFO);
void cgerqf_(const int *M, const int *N, float _Complex *A, const int *LDA, float _Complex *TAU, float _Complex *WORK, const int *LWORK, int *INFO);
void zgerqf_(const int *M, const int *N, double _Complex *A, const int *LDA, double _Complex *TAU, double _Complex *WORK, const int *LWORK, int *INFO);
Fortran Interface:
DGERQF(m, n, a, lda, tau, work, lwork, info);
SGERQF(m, n, a, lda, tau, work, lwork, info);
CGERQF(m, n, a, lda, tau, work, lwork, info);
ZGERQF(m, n, a, lda, tau, work, lwork, info);
参数
参数名 |
类型 |
描述 |
输入/输出 |
---|---|---|---|
m |
整数型 |
矩阵A的行数。 |
输入 |
n |
整数型 |
矩阵A的列数。 |
输入 |
a |
|
|
输入/输出 |
lda |
整数型 |
A的leading dimension大小,要求lda≥max(1, m)。 |
输出 |
tau |
|
初等反射的系数,长度为min(m,n)(参见说明)。 |
输出 |
work |
|
临时存储空间,使用lwork=-1调用后work[0]为最优的lwork值。 |
输出 |
lwork |
整数型 |
work数组的长度。 lwork=-1时查询最优work大小,结果保存在work[0]中,否则要求lwork≥n。 |
输入 |
info |
整数型 |
执行结果:
|
输出 |
分解结果矩阵Q通过一系列初等反射乘积表示:Q=H(1)*H(2)*...*H(k), k=min(m,n)。H(i)=I-tau*v*v'。tau为标量,v为向量且前i-1个元素为0,第i个元素为1,剩余元素保存在a的第i列中(a的下三角部分)。
依赖
#include "klapack.h"
示例
C Interface:
int m = 6; int n = 4; int lda = 6; int info = 0; double tau[4]; double *work = NULL; double qwork; int lwork = -1; /* * A (6x4, stored in column-major): * 2.229 1.273 0.087 0.035 * 8.667 4.317 4.091 3.609 * 0.205 7.810 2.553 6.507 * 2.758 2.911 8.791 5.051 * 8.103 1.396 1.317 4.738 * 8.859 3.161 0.808 5.972 */ double a[] = {2.229, 8.667, 0.205, 2.758, 8.103, 8.859, 1.273, 4.317, 7.810, 2.911, 1.396, 3.161, 0.087, 4.091, 2.553, 8.791, 1.317, 0.808, 0.035, 3.609, 6.507, 5.051, 4.738, 5.972}; /* Query optimal work size */ dgerqf_(&m, &n, a, &lda, tau, &qwork, &lwork, &info); if (info != 0) { return ERROR; } lwork = (int)qwork; work = (double *)malloc(sizeof(double) * lwork); /* Calculate RQ */ dgerqf_(&m, &n, a, &lda, tau, work, &lwork, &info); free(work); /* * Output: * tau * 0.000000 1.683018 1.409717 1.534598 * A output (stored in column-major) * 1.359608 2.967627 -1.011896 -0.433983 * 0.345857 0.516770 0.307017 -2.757397 * -5.500889 -8.779283 -0.546907 0.184390 * 0.141517 -0.775170 6.494784 -1.230625 * -1.582355 0.047133 -2.152892 -10.320058 * -6.035814 -6.347009 -9.449164 -11.171009 */
Fortran Interface:
PARAMETER (m = 6) PARAMETER (n = 4) PARAMETER (lda = 6) INTEGER :: info = 0 REAL(8) :: tau(4) REAL(8) :: qwork(1) INTEGER :: lwork = -1 REAL(8), ALLOCATABLE :: work(:) * * A (6x4, stored in column-major): * 2.229 1.273 0.087 0.035 * 8.667 4.317 4.091 3.609 * 0.205 7.810 2.553 6.507 * 2.758 2.911 8.791 5.051 * 8.103 1.396 1.317 4.738 * 8.859 3.161 0.808 5.972 * REAL(8) :: a(m, n) DATA a / 2.229, 8.667, 0.205, 2.758, 8.103, 8.859, $ 1.273, 4.317, 7.810, 2.911, 1.396, 3.161, $ 0.087, 4.091, 2.553, 8.791, 1.317, 0.808, $ 0.035, 3.609, 6.507, 5.051, 4.738, 5.972 / EXTERNAL DGERQF * Query optimal work size CALL DGERQF(m, n, a, lda, tau, qwork, lwork, info) IF (info.NE.0) THEN CALL EXIT(1) END IF lwork = INT(qwork(1)) ALLOCATE(work(lwork)) * Calculate RQ CALL DGERQF(m, n, a, lda, tau, work, lwork, info) DEALLOCATE(work) * Output: * tau * 0.000000 1.683018 1.409717 1.534598 * A output (stored in column-major) * 1.359608 2.967627 -1.011896 -0.433983 * 0.345857 0.516770 0.307017 -2.757397 * -5.500889 -8.779283 -0.546907 0.184390 * 0.141517 -0.775170 6.494784 -1.230625 * -1.582355 0.047133 -2.152892 -10.320058 * -6.035814 -6.347009 -9.449164 -11.171009