CFD Online Discussion Forums

CFD Online Discussion Forums (http://www.cfd-online.com/Forums/)
-   Main CFD Forum (http://www.cfd-online.com/Forums/main/)
-   -   Testing if matrix is symmetric positive definite (http://www.cfd-online.com/Forums/main/13880-testing-if-matrix-symmetric-positive-definite.html)

Ben July 28, 2007 21:40

Testing if matrix is symmetric positive definite
 
Hi,

May I know if there is a fortran code or algorithm somewhere which test if a matrix is symmetric positive definite (SPD)?

Also is it true if a matrix is SPD, its eigenvectors 'll all be positive?

Thanks

Jonas Holdeman July 29, 2007 07:17

Re: Testing if matrix is symmetric positive defini
 
For the symmetric test, take the difference of the matrix and its transpose. This would be zero for a symmetric matrix and exact arithmetic. Since one would have round-off errors in a real computation, find the maximum element of the difference and see if it is small enough relative to the size of the maximum element of the original matrix. Instead of the maximum elements, you could use some other norm.

For the definite part, you could compute the determinant. For this you might use a routine that reduces the matrix to upper triangular (by elimination), then take the product of the diagonal elements. This must be positive.

Someone else might have a better idea.

NA July 30, 2007 02:19

Re: Testing if matrix is symmetric positive defini
 
I hope you mean positive eigen values ?

For the determinant .. Why even rotate the matrix system from its original coordinate system, just take the determinant , it should be fairly easy if you know the order.

Jonas Holdeman July 30, 2007 07:24

Re: Testing if matrix is symmetric positive defini
 
If NA knows of a faster way to find the determinant of, say, a 1000 X 1000 matrix, I would be interested. The determinant test does not tell you if a matrix is positive definite, but it MIGHT tell you it isn't. If you have an even number of negative eigenvalues it tells you nothing. It will alert you if there are zero eigenvalues or if there are an odd number.

Lionel Larchevêque July 30, 2007 09:28

Re: Testing if matrix is symmetric positive defini
 
Hi,

As far as I remember, there is one indirect method to check wether or not a matrix is symmetric positive definite:

Try to solve the corresponding A*x=B system using the Cholesky method (A=L*L^T decomposition) which require to compute the square root of n quantities for a n*n system. If the method succeed in solving the system (i.e. if all the n quantities are positive), the matrix is indeed positive definite.

See for instance numerical recipes for detail on the Cholesky method.

Hope this helps,

Lionel


All times are GMT -4. The time now is 12:41.