我正试图用矩形a矩阵求解Xcode中的Ax=b,其中a和b的大小取决于我存储的不同数组的大小。我试过使用dgels,但由于某种原因,我得到了这个错误
** on entry to DGELS , parameter number 8 had an illegal value dgesv_ fails -8
这对应于工作双矩阵输入,我不明白为什么。
int numberOfPlays=(int)[playArray计数];int numberOfSignals=(int)[signalMappings计数];
// now create A Matrix and b vector
double playElements[numberOfPlays][numberOfSignals];
for (int i = 0; i < numberOfPlays; i = i + 1) {
for (int j = 0; j < numberOfSignals; j = j + 1) {
playElements[i][j] = 0.0;
}
}
double outputElements[numberOfPlays][1];
for (int i = 0; i < numberOfPlays; i = i + 1) {
outputElements[i][0] = 0.0;
}
...update the elements of the matrices
// now solve the matrix
__CLPK_integer m = numberOfPlays;
__CLPK_integer n = numberOfSignals;
__CLPK_integer nrhs = 1;
__CLPK_integer info;
__CLPK_integer lda = n;
__CLPK_integer ldb = 1;
int min = n;
if (m < n) {
min = m;
}
__CLPK_integer workSize = min * 2;
double *work = (double *)malloc(workSize*sizeof(double));
dgels_("N", &m, &n, &nrhs, *playElements, &lda, *outputElements, &ldb, work, &workSize, &info);
参数编号8对应于ldb
,应为>= max(1, m, n)
。因此,在您的情况下,应该是m
或n
(以较大者为准)。
我也被这件事刺痛了,一些文件对此并不清楚。我将错误追溯到Lapack C源代码,这一点很清楚。