- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I know this is trivial but i cant find the answer anywhere else:
have in C, matrix A[16][16] [A is not symmetric.] that i want to invert. I have this code which is giving incorrect answer:
void inverseRD ( float* I, float* A, int N)
float work [WTDIM][WTDIM];
float *p;
p = &work[0][0];
int ipivot [256];
int lwork = 256;
sgetrf ( &N, &N, A, &N, &ipivot[0], &info);
sgetri ( &N, I, &N, &ipivot[0], p, &lwork, &info);
I assume i have made an error in passing parameters but I cant see it.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I rewrote your code correcting some small errors, and making it a little smaller so that you can test. You might need to remove the underscores because I did not do this with MKL, but just LAPACK. My version destroys the original matrix as the sgetrf and sgetri will anyway, so you should make a copy of the original matrix to work with the routines.
1. info has not been declared as an integer.
2. ipivot can be passed as shown below, though your method is probably OK.
#include
void inverseRD (float *A, int N)
{
float work [2][2];
int ipivot [4];
int lwork = 4;
int info;
sgetrf_( &N, &N, A, &N, ipivot, &info);
sgetri_( &N, A, &N, ipivot, work, &lwork, &info);
}
int main()
{
float A[4]={2,1,1,2}, B[4];
inverseRD(A,2);
printf("%f %f %f %f\n",A[0],A[1],A[2],A[3]);
}
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I rewrote your code correcting some small errors, and making it a little smaller so that you can test. You might need to remove the underscores because I did not do this with MKL, but just LAPACK. My version destroys the original matrix as the sgetrf and sgetri will anyway, so you should make a copy of the original matrix to work with the routines.
1. info has not been declared as an integer.
2. ipivot can be passed as shown below, though your method is probably OK.
#include
void inverseRD (float *A, int N)
{
float work [2][2];
int ipivot [4];
int lwork = 4;
int info;
sgetrf_( &N, &N, A, &N, ipivot, &info);
sgetri_( &N, A, &N, ipivot, work, &lwork, &info);
}
int main()
{
float A[4]={2,1,1,2}, B[4];
inverseRD(A,2);
printf("%f %f %f %f\n",A[0],A[1],A[2],A[3]);
}

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page