Skip to content

Instantly share code, notes, and snippets.

@trialsolution
Created August 23, 2013 06:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save trialsolution/6316238 to your computer and use it in GitHub Desktop.
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)
$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