Community
cancel
Showing results for 
Search instead for 
Did you mean: 
HM_Li
Beginner
89 Views

problem about LAPACKE_dgetrf and LAPACKE_dgetri

Jump to solution

Please see attachment  b.c.

if I comment out from //hmli begin to  //hmli end in the follow code of b.c, it works wrong, but if I do not comment out and use sprintf and atof to convert from double to string, then convert back to double, it work well. 

for (k = 0; k < 64; k++)a +=(double) A1 * A1;
//hmli begin
sprintf(t,"%lf",a);
a=atof(t);
//hmli end
a = (double)a;

Is it just because of the precision?

Can you help me? Thank you very much.

  • b.c: source code
  • body.log : input data file
  • ainv.log: result of matrix inversion.
  • compiling :icc -mkl b.c

 

 

0 Kudos
1 Solution
89 Views

Hello,

The input matrix in the example is very ill-conditioned. This means it hardly could lead to an accurate result, and round-offs cause big fluctuation of the output.

As I see the best option here is to improve the condition number of the input matrix.
However you also could try dgesvxx with FACT=E. This way the function does normalization and equlibration of input data, which could improve accuracy for ill-conditioned matrices. Please provide and identity matrix NxN in B, and on output B will contain inverse of matrix A. Or the function will return a warning in INFO (see documentation) if the matrix is too ill-conditioned.

Best regards,
Alexander

View solution in original post

4 Replies
mecej4
Black Belt
89 Views

You are methodically destroying the precision of the input matrix. Take the (1,1) element of A, for example. It has the value 5.2734375...e-002. After your strange manipulation, the 15+ digit precision of A1,1  has been degraded to just five significant digits, i.e, it is now 5.2734000e-002. What is the purpose of writing a limited number of digits and reading the truncated number back in?

HM_Li
Beginner
89 Views

Thank you.

The reason is: if the double float data not truncated, LAPACKE_dgetrf and LAPACKE_dgetri can't give the right result, so I want to know why and how to use LAPACKE_dgetrf and LAPACKE_dgetri right.

90 Views

Hello,

The input matrix in the example is very ill-conditioned. This means it hardly could lead to an accurate result, and round-offs cause big fluctuation of the output.

As I see the best option here is to improve the condition number of the input matrix.
However you also could try dgesvxx with FACT=E. This way the function does normalization and equlibration of input data, which could improve accuracy for ill-conditioned matrices. Please provide and identity matrix NxN in B, and on output B will contain inverse of matrix A. Or the function will return a warning in INFO (see documentation) if the matrix is too ill-conditioned.

Best regards,
Alexander

View solution in original post

HM_Li
Beginner
89 Views

Thank you very much. I see.

Reply