! Find the largest eigenvalue, D, of a symmetric matrix; 
! Keywords: Positive definite, Eigenvalue, POSD, SDP;
SETS:
  VAR;
  VXV( VAR, VAR): Q, R;
 ENDSETS
DATA: VAR = 1..3; ! The matrix; Q = .01080754 .01240721 .01307513 .01240721 .05839170 .05542639 .01307513 .05542639 .09422681 ; ENDDATA !---------------------------------------------------------------; ! Find the smallest amount, D, such that the matrix D*I-Q is positive definite. D will be the largest eigenvalue of Q; MIN = D; @FREE( D); ! R is the adjusted matrix. Off diagonal elements are left unchanged; @FOR( VXV( i,j) | i #NE# j: R(i,j) = - Q(i,j) ; @FREE( R(i,j)); ); ! Diagonal elements may be decreased; @FOR( VAR(j): R(j,j) = D - Q(j,j); @FREE( R(j,j)); ); ! and we want R = D*I - Q to be positive definite; @POSD( R); DATA: @TEXT() = ' The largest eigenvalue is ', D; @TEXT() = ' '; @TEXT() = ' for the following matrix'; @TEXT() = @TABLE(Q); ENDDATA