Created
August 23, 2013 06:47
-
-
Save trialsolution/6316238 to your computer and use it in GitHub Desktop.
checks if a symmetric matrix is pos. definite (GAMS code using the default cholesky decomposition utility)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ontext | |
Test the positive definiteness of a symmetric matrix | |
Extension of the 'choleskyexample.gms' example from the McCarl User Guide | |
$offtext | |
Set index /i1*i2/; | |
Table a(index,index) matrix to decompose | |
i1 i2 | |
i1 2 1 | |
i2 1 3; | |
parameter LforA(index,index) L matrix that is a decomposition of A; | |
execute_unload 'gdxforutility.gdx' index,A; | |
execute 'cholesky gdxforutility.gdx index A gdxfromutility.gdx LforA'; | |
execute_load 'gdxfromutility.gdx' , LforA; | |
display a, LforA; | |
* check if all diagonal elements are positive <=> pos. definite (if the matrix is symmetric) | |
loop(index, | |
if (LforA(index,index) < 0, | |
abort "the matrix is not pos.definite"; | |
); | |
); | |
display "the matrix is pos. definite"; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment