My code crashes when I call solve_chol () using the lapack library
#include "mex.h"
#include <math.h>
#include <string.h>
extern int dpotrs(char *, int *, int *, double *, int *, double *, int *, int *);
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
{
double *C;
int n, m, q;
if (nrhs != 2 || nlhs > 1) /* check the input */
mexErrMsgTxt("Usage: X = solve_chol(R, B)");
n = mxGetN(prhs[0]);
if (n != mxGetM(prhs[0]))
mexErrMsgTxt("Error: First argument matrix must be square");
if (n != mxGetM(prhs[1]))
mexErrMsgTxt("Error: First and second argument matrices must have same number of rows");
m = mxGetN(prhs[1]);
plhs[0] = mxCreateDoubleMatrix(n, m, mxREAL); /* allocate space for output */
C = mxGetPr(plhs[0]);
if (n==0) return; /* if argument was empty matrix, do no more */
memcpy(C,mxGetPr(prhs[1]),n*m*sizeof(double)); /* copy argument matrix */
dpotrs("U", &n, &m, mxGetPr(prhs[0]), &n, C, &n, &q); /* solve system */
if (q > 0)
mexErrMsgTxt("Error: illegal input to solve_chol");
}
Hi guys,
I have a problem with this C code. It is supposed to solve a matrix system (Ax = B)with a Asymmetric, positive definite and already in the upper triangular form?
I created this snippet to improve the performance of Matlab, but unfortunately the failure of Matlab and some debugging showed that the problem was the call dpotrs()at the end of the script. Can you understand what could be the problem?
Information about dpotrs()can be found here: http://physics.oregonstate.edu/~rubin/nacphy/lapack/routines/dpotrs.html
It would be great if you could help