//---------------------------------------------------------------- // gaussian.cpp (The Gaussian Elimination Algorithm) // // This interactive program accepts the augmented matrix for // a linear system, and then performs a series of elementary // row-operations which brings the augmented matrix into its // reduced row-echelon form. // // compile using: $ g++ gaussian.cpp -o gaussian // // programmer: ALLAN CRUSE // written on: 18 SEP 1989 -- compiled for MS-DOS Turbo C++ // revised on: 30 NOV 2002 -- modified for Redhat Linux 8.0 //---------------------------------------------------------------- #include "qmatrix.h" int input_matrows( void ) { int m; cout << "\nHow many equations? "; cin >> m; cout << endl; return m; } int input_matcols( void ) { int n; cout << "\nHow many variables? "; cin >> n; cout << endl; return ++n; } void show_matrix( int& tableau, FractionMatrix& a ) { cout << "\nMatrix number " << tableau; cout << " appears below:\n" << a; } int main( void ) { system( "clear" ); cout << "\n\n\n\n"; int m = input_matrows(); int n = input_matcols(); FractionMatrix a(m,n); cin >> a; cout << "\nThe augmented matrix appears below:\n" << a; getchar(); Fraction det = 1; int tableau = 0; while ( !a.row_reduced( det ) ) { getchar(); show_matrix( ++tableau, a ); } cout << "\n\ndeterminant = " << det << endl; }