Intel® oneAPI Math Kernel Library
Ask questions and share information with other developers who use Intel® Math Kernel Library.
6982 Discussions

LAPACK DSYEV -negative eigenvalue for a positive definite matrix

Pipa
Beginner
1,083 Views
Hi all,

I have a positive definite 6x6 symmetric matrix. When I compute its eigenvalues using DSYEV, I get a negative eigenvalue (which is a small number ~<10^-8). It seems like a machine error. Is there any way to avoid this (without hard-wiring zero for negative eigenvalues with an if-condition)?

I copy-pasted the same matrix into Octave (mathematical tool like MATLAB) and got all positive eigenvalues with similar magnitude as in Fortran. The only difference was the one small eigenvalue which was negative in Fortran and positive in Octave.

p.s. Octave also uses DSYEV

Thanks!!


0 Kudos
5 Replies
Ying_H_Intel
Employee
1,083 Views
Quoting - B
Hi all,

I have a positive definite 6x6 symmetric matrix. When I compute its eigenvalues using DSYEV, I get a negative eigenvalue (which is a small number ~<10^-8). It seems like a machine error. Is there any way to avoid this (without hard-wiring zero for negative eigenvalues with an if-condition)?

I copy-pasted the same matrix into Octave (mathematical tool like MATLAB) and got all positive eigenvalues with similar magnitude as in Fortran. The only difference was the one small eigenvalue which was negative in Fortran and positive in Octave.

p.s. Octave also uses DSYEV

Thanks!!


Hello,

It is interesting probelm. Could you pleaseprovide small test case(include the input matrix)to show the problem?

Thanks
Ying H.
0 Kudos
Pipa
Beginner
1,083 Views
Thanks for your reply.

Here is the 6x6 matrix:
A = [

151120481.428847 151120481.428847 52055036.6724627 53675991.8546206 40296770.0677839 43410356.2551100
;151120481.428847 151120481.428847 52055036.6724627 53675991.8546206 40296770.0677839 43410356.2551100 ;52055036.6724627 52055036.6724627 100305763.160939 60890549.3586360 35311242.4103483 31373570.5088871 ;53675991.8546206 53675991.8546206 60890549.3586360 112533004.382060 33331662.1776238 37220742.9771377 ;40296770.0677839 40296770.0677839 35311242.4103483 33331662.1776238 78740272.8719528 31260906.5611842 ;43410356.2551100 43410356.2551100 31373570.5088871 37220742.9771377 31260906.5611842 86843289.2068501

]

Ocatve gave me the following eigenvalues:
1.1176e-008
4.3032e+007
5.2965e+007
6.7013e+007
1.1757e+008
4.0008e+008

Which are all positive

Fortran gave me the following eigenvalues:

-2.845365061365947D-025
43031590.6018047
52965460.4977217
67012835.5297122
117569027.749215
400084378.101042

The first eigenvalues is negative, which is strange as the symmetric matrix above is a positive definite matrix.

Thanks!!


0 Kudos
Ying_H_Intel
Employee
1,083 Views
Quoting - B
Thanks for your reply.

Here is the 6x6 matrix:
A = [

151120481.428847 151120481.428847 52055036.6724627 53675991.8546206 40296770.0677839 43410356.2551100
;151120481.428847 151120481.428847 52055036.6724627 53675991.8546206 40296770.0677839 43410356.2551100 ;52055036.6724627 52055036.6724627 100305763.160939 60890549.3586360 35311242.4103483 31373570.5088871 ;53675991.8546206 53675991.8546206 60890549.3586360 112533004.382060 33331662.1776238 37220742.9771377 ;40296770.0677839 40296770.0677839 35311242.4103483 33331662.1776238 78740272.8719528 31260906.5611842 ;43410356.2551100 43410356.2551100 31373570.5088871 37220742.9771377 31260906.5611842 86843289.2068501

]

Ocatve gave me the following eigenvalues:
1.1176e-008
4.3032e+007
5.2965e+007
6.7013e+007
1.1757e+008
4.0008e+008

Which are all positive

Fortran gave me the following eigenvalues:

-2.845365061365947D-025
43031590.6018047
52965460.4977217
67012835.5297122
117569027.749215
400084378.101042

The first eigenvalues is negative, which is strange as the symmetric matrix above is a positive definite matrix.

Thanks!!



Hello,

We maysee the problem in two aspects.
First, the A have same row 1 and row2
151120481.428847 151120481.428847 52055036.6724627 53675991.8546206 40296770.0677839 43410356.2551100 ;
151120481.428847 151120481.428847 52055036.6724627 53675991.8546206 40296770.0677839 43410356.2551100
It is not a positive definition matrix and in theory, it has a eigenvalue 0.0.

Secondly, we need consider thecompuation precision on computer, in general, the presion of double type float willabout 15digit . So the valid digit of -2.845365061365947D-025(-0.00000000000000000000000028), it actually equals to 0.0

Regards,
Ying

0 Kudos
Pipa
Beginner
1,083 Views
Thanks a lot for ur reply.

I realized that it is not a positive definite matrix after I did some analysis with the diagonal elements of the matrix to check its positive definitiveness.

I was just wondering if there is a way to know why the results from Octave and Fortran were different although they use same LAPACK routines.

Thanks again for ur time!
0 Kudos
Gennady_F_Intel
Moderator
1,083 Views
Quoting - B
Thanks a lot for ur reply.

I realized that it is not a positive definite matrix after I did some analysis with the diagonal elements of the matrix to check its positive definitiveness.

I was just wondering if there is a way to know why the results from Octave and Fortran were different although they use same LAPACK routines.

Thanks again for ur time!


balwindersingh,
yes the same routines but the different implementations :), different versions and different libraries at all. Fortran (i guess you are talking about Intel Fortran ) uses Intel MKL, but i am not aware about Octave
.
--Gennady
0 Kudos
Reply