Hi there, I have a problem using the BLAS routine ztbsv.c in a c-mex file to solve a linear equation system Ax=b, with A being a quadratic, triangular, band matrix stored in a "packed band storage" as follows:
In the real case, the triangular band matrix
1 5 9 0 00 2 6 10 00 0 3 7 110 0 0 4 80 0 0 0 5
Is stored as
0 0 9 10 110 5 6 7 81 2 3 4 5
with the top left 2×2 triangle not being referenced.
The following C-code works perfectly:
void mexFunction( int nlhs, mxArray * plhs[], int nrhs, const mxArray * prhs[] ) { double br[5]={1,2,3,4,5}; double Ar[15]={0,0,1,0,5,2,9,6,3,10,7,4,11,8,5}; char UH = 'U'; char EN = 'N'; ptrdiff_t n = 5; ptrdiff_t k = 2; ptrdiff_t l = k+1; ptrdiff_t one = 1; dtbsv_(&UH,&EN,&EN,&n,&k,Ar,&l,br,&one); return; }
However, the complex case is not working. According to the Matlab documentation, a complex vector of length n is stored as a real vector of length 2n, with real and imaginary part alternating, for example:
1+2i3+4i5+6i
is stored as
{1,2,3,4,5,6}
All complex BLAS routines are working fine this way, except for ztbsv. I tried the same storage scheme as in the real case, with real and imaginary parts alternating. If I solve Ax=b this way, some components of x (the last ones) are correct, but not all.
I haven't found a explanation how to properly store the matrix. The official BLAS documentation describes a different implementation of the complex routines. Here, a structure "doublecomplex", containing the two doubles real and imaginary part, is defined. But the blas.h file in my Matlab directory defines complex arrays as described above: as a double array of two times the length, alternating real and imaginary part. And again: All routines I tried work, except for ztbsv.
Any help is highly appreciated!
Best Answer