I am a new user of lapack, and I tried as a simple first step to invert a matrix. The functions seems to work correctly, but when I check the result with the result that matlab gives me, it doesn't match.
Here is what I tried :
this is my initial matrix (the numbers are floats)
- Code: Select all
mat =
0.1000 2.2000 2.0000 4.2000 1.1000
0.3000 3.1000 0 8.9000 0.2000
7.1000 2.0000 1.0000 8.1000 3.5400
0.5000 4.7000 0.8000 4.1000 1.2000
2.2000 7.1000 6.4000 2.3000 1.3000
then i call the lapack routines :
- Code: Select all
integer N1=5;
integer INFO = 0;
float *A;
integer *IPIV;
float *work;
sgetrf_(&N1,&N1,A,&N1,IPIV,&INFO);
sgetri_(&N1,A,&N1,IPIV,work,&lwork,&INFO);
where A is my previous matrix written as a vector column by column.
Here is the result I get from lapack :
- Code: Select all
inv =
0 -0.0845 -0.0322 -0.0756 0.3057
0 0.6369 -0.0986 -0.1324 -0.1767
0 0.0342 0.1292 0.0192 -0.1093
0 -0.2103 -0.2495 0.3188 0.1274
0 0 0 0 1.3000
And here is the correct answer, given by matlab :
- Code: Select all
ans =
-0.3986 0.1077 0.1124 -0.1158 0.1215
-0.2446 0.0111 -0.0304 0.2592 0.0488
0.2405 0.0085 -0.0206 -0.2919 0.1208
0.0834 0.1159 0.0053 -0.0950 -0.0150
0.6789 -0.4899 0.0679 0.3858 -0.2710
I don't know if this forum is a good place to post my problem, but so far it's the only forum about Lapack that I found.
Could you please help me finding where my error comes from ?
Thank you.

