inverse matrix in mexFunction
显示 更早的评论
void inverseMatrix(int dim, double *matrix, double *invMatrix)
{
// matrix and invMatrix are columnwise.
int *IPIV, LWORK, INFO, i;
double *WORK;
mexPrintf("entered inverseMatrix");
IPIV = mxMalloc((dim+1)*sizeof(int));
LWORK = dim*dim;
WORK = mxMalloc(LWORK*sizeof(double));
for (i=0;i<dim*dim;i++){
invMatrix[i] = matrix[i];
}
mexPrintf("before dgetrf");
dgetrf(&dim, &dim, invMatrix, &dim, IPIV, &INFO);
mexPrintf("before dgetri");
dgetri(&dim, invMatrix, &dim, IPIV, WORK, &LWORK, &INFO);
mxFree(IPIV);
mxFree(WORK);
return;
}
I am trying to use dgetrf and dgetri to inverse a matrix in C but Matlab crashes after successfully giving the correct answer 2 times (I did an interation to try the stability of the c code).
采纳的回答
更多回答(3 个)
Titus Edelhofer
2012-4-4
0 个投票
Hi Jane,
the code looks fine to me. Maybe it's the calling mex file causing the problem?
Titus
类别
在 帮助中心 和 File Exchange 中查找有关 Write C Functions Callable from MATLAB (MEX Files) 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!