Hello,
In one of my projects at the university, I was searching for a linear algebra library and came across ALGLIB. The packages and subpackages with source code appeared great.
I included all the required files, to do a complex matrix inversion, in my project, and started testing it starting with a 2x2 matrix, but found that I got errors in resulting inverted matrix. Here is the gist of my code, which is just a copy of the examples given in the manual. Funny thing is that in each and every case, half of the elements in the resulting matrix, were right and the other half were wrong.
ae_int_t info; matinvreport rep; complex_2d_array a = "[[1i,-1],[1i,1]]"; // 2x2 complex array complex_2d_array a1 ="[[1i,-1],[1i,1]]"; // copy of the 2x2 complex array to display in the output cmatrixinverse(a1, info, rep);
real_2d_array r = "[[1,2],[3,4]]"; real_2d_array r1 = "[[1,2],[3,4]]"; rmatrixinverse(r1, info, rep);
And for the display, I use a1.tostring(4).c_str() and r1.tostring(4).c_str(). The code is part of a huge project, that has hundreds of source and header files, used to reconstruct data from a medical MRI scanner. And in the tailor made compiler, a few files of relevance are compiled. The above code gets compiled without any error. Display of the original matrices are good and I even tried to copy a large complexd matrix to another and it worked well.
I would have expected the inverted matrices to be [[-0.5i,-0.5i],[-0.5,0.5]] for the complex array and [[-2, 1],[1.5, -0.5]] for the real array, but the results were [[-1i, -0.5i],[0,0.5]] and [[-2,0.33],[1.5,0]].
In the complex case, the 2nd column turned out to be good, and in the real case, the first column turned out to be good.
It will be great to know where I am going wrong. I am sure its a silly error somewhere (as I have read posts in the forum where people have successfully inverted very large matrices), but I have banged my head on the monitor for nearly two hours trying to figure out the mistake..
thanks ERUMAI
|