#### Topic: dsygv not working as expected

I am using fortran on windows machine. My program generates two matrices A and B – both square, symmetric and positive definite. These matrices were generated based on a problem input from my side into the fortran program. I tried 6 independent runs with slight variation in inputs – for 5 cases, it ran well, the eigen values were matching my independent calcs using a software and  also with Mathcad. For the 6th case, the dsygv listing gives 2 negative numbers as eigen values which was not expected. I took these matrices in Mathcad, and I got the answers matching software calculations. So this means, the matrices A and B are ok. could you please assist me to find why they are not working with dsygv. While comparing the dsygv listing with Mathcad, I found that eigen value(3) in dsygv was matching eigenval(1) of mathcad, eigenval(4) was matching eigenval(2) of mathcad and so on.. looks like the 2 negative values got inserted in the listing - could some one explain why this is happening. the A and B matrices are generated inside fortran and solved using dsygv. In the 6th case, there is some discrepancy(only while using dsygv, it works as usual while using mathcad/or independent software) - any guidance is appreciated.

#### Re: dsygv not working as expected

When you call DSYGV, are you checking the output of the INFO argument?  Is it returning 0 (successful) in Simply Fortran?

Jeff Armstrong
Approximatrix, LLC

#### Re: dsygv not working as expected

yes, INFO gave zero.

#### Re: dsygv not working as expected

jeff, actually those two matrices were created inside the pgrm, I took them into Mathcad and checked for Eigen values, they were giving me results which I was expecting, but dsygv is giving two negative Eigen values at the beginning. I don't understand why this is happening. I tried with 5 other matrix combinations  - Mathcad and dsygv gave same/similar results.. all matrices here too was generated inside fortran using same code which I used for the error one..

#### Re: dsygv not working as expected

Without seeing the actual matrix you're feeding to DSYGV, I really can't comment any further. Can you post them here?  Are you sure that the matrices being provided to DSYGV are positive-definite to within machine precision?

Jeff Armstrong
Approximatrix, LLC

#### Re: dsygv not working as expected

please see the matrices here. they work perfectly when called in mathcad..

https://www.dropbox.com/s/djji2bq8lzi8h … x.zip?dl=0

thanks Jeff.

#### Re: dsygv not working as expected

When I load your matrices into Octave, it appears that A is not symmetric.  Can you check that in Mathcad?

Jeff Armstrong
Approximatrix, LLC

#### Re: dsygv not working as expected

Hi Jeff, A is symmetric, you can open the excel and have a quick look, please see the screenshot where i did comparison of mathcad with fortran - which means mathcad calculated eigen values for the A,B matrices - inturn means A is symmetric. the screenshot also shows cholesky decomposition of both matrices

https://www.dropbox.com/s/eynvb2clpk46g … n.JPG?dl=0

#### Re: dsygv not working as expected

As an example, Cell L7 has a value of -2.44140625E-04, but Cell G12 is 0.  There are additional examples of this non-symmetry that can be located relatively easily by subtracting the transpose of the lower triangular portion of the matrix from the upper triangular.

Jeff Armstrong
Approximatrix, LLC

#### Re: dsygv not working as expected

thanks Jeff... that should be the issue then,

is there a way to get lower triangular matrix in mathcad ??

so, i think the issue here is with precision - any suggestion on how to tackle this... i am declaring my matrices as doubleprecision in fortran. eg:

doubleprecision,dimension(678,678)::kgap

#### Re: dsygv not working as expected

jeff, i am attaching little more details here.. the original A matrix is made of lot of 12x12 matrices as shown in attachment. in my program, matrices A1, A2 are generated, they are automatically assembled as shown. while this assemblage, there is some discrepancy happening - i found this when i performed the assemblage in excel. i tried to find the difference between the program o/p and my manual calcs - which should have given zeros - it is not happening, and so we have the cell L7 as -2.44140625E-04. i feel this is something due to precision control ?? please see the attached excel... will this mismatch be responsible for the error ? this doesnt appear while using mathcad?

https://www.dropbox.com/s/ze5k298rjqqg2 … .xlsx?dl=0

#### Re: dsygv not working as expected

The condition of your A matrix is 2.2E+13, which does indicate poor conditioning.  The largest value in the A matrix appears to be around 2E+18, and the problematic non-symmetric value is about 2E-04 in magnitude.  This does indicate some numerical instability.

A double precision value can represent about 16 digits of precision.  A problem arises, though, if you perform any arithmetic that won't fall within that precision range.  For example, if you set x=2.2E+13 and you add 2E-04 to x, the value of x will not change at all.

You could, in theory, use a higher precision in Fortran, although LAPACK doesn't provide those routines for higher-precision operations out of the box.  I think it would be more productive to determine why your problem is leading to such a poorly conditioned matrix or to research a more general method of computing eigenvalues using LAPACK that doesn't rely on the A matrix being symmetric.  I would be most concerned, though, with the input matrices' conditioning.

EDIT: Looking at your Excel spreadsheets, it would appear that most of the errors are approaching machine precision errors.  I'm not sure how best to tackle the values not being exact as they should effectively be zero. Again, though, the matrix condition is quite poor.

Jeff Armstrong
Approximatrix, LLC

#### Re: dsygv not working as expected

Is DGGBAL instead of DSYGV a solution for my issue

http://physics.oregonstate.edu/~landaur … ggbal.html