如何在Xcode中使用dgels

时间:2014-10-02 06:23:08

标签: ios xcode matrix lapack lapacke

我试图用矩形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 count];     int numberOfSignals =(int)[signalMappings count];

// 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);

1 个答案:

答案 0 :(得分:0)

参数编号8对应ldb,应为>= max(1, m, n)。因此,在您的情况下,这应该是mn(以较大者为准)。

我也对此感到厌烦,有些文件对此并不清楚。我将错误追溯到Lapack C来源,这说明了这一点。