pivot.gms : Simple Gaussian Elimination

Description

Simple Gaussian Elimination steps are performed on a matrix with
identically labeled rows and columns. The implied pivot sequence
is 1.1, 2.2, etc.


Small Model of Type : GAMS


Category : GAMS Model library


Main file : pivot.gms

$title Simple Gaussian Elimination Steps (PIVOT,SEQ=70)

$onText
Simple Gaussian Elimination steps are performed on a matrix with
identically labeled rows and columns. The implied pivot sequence
is 1.1, 2.2, etc.


GAMS Development Corporation, Formulation and Language Example.

Keywords: Gaussian elimination, mathematics
$offText

Set
   i    'matrix labels'  / 1*6 /
   r(i) 'pivot sequence'
   k(i) 'non pivot rows'
   l(i) 'non pivot columns';

Alias (i,j);

Parameter
   a(i,j) 'original matrix'
   b(i,j) 'inverse of a'
   piv
   det;

a(i,j) = uniform(-.3,0);
a(i,i) = 1;
r(i)   = yes;
k(i)   = yes;
l(j)   = yes;
b(i,j) = a(i,j);
det    = 1;

loop(r,
   k(r) = no;
   l(r) = no;

   piv    =  1/b(r,r);
   det    =  det/piv;
   b(r,l) =  b(r,l)*piv;
   b(k,l) =  b(k,l) - b(r,l)*b(k,r);
   b(k,r) = -b(k,r)*piv;
   b(r,r) =  piv;

   k(r) = yes;
   l(r) = yes;
);

display det, a, b;

Parameter check(i,j);
check(i,j) = sum(k, a(i,k)*b(k,j));

display check;